Commit d3d99c14 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[inputWithText] add onBlur

parent 11855438
......@@ -20,6 +20,7 @@ import Gargantext.Types as GT
import Gargantext.Types (NodeType(..))
import Gargantext.Utils.Reactix as R2
thisModule :: String
thisModule = "Gargantext.Components.Forest.Tree.Node.Action.Add"
----------------------------------------------------------------------
......@@ -83,7 +84,8 @@ addNodeView p@{ dispatch, nodeType, nodeTypes } = R.createElement el p []
defaultNt = (fromMaybe Error $ head nodeTypes)
maybeEdit = [ if edit
then inputWithEnter {
onEnter: \_ -> launchAff_ $ dispatch (AddNode name' nt')
onBlur: \val -> setNodeName $ const val
, onEnter: \_ -> launchAff_ $ dispatch (AddNode name' nt')
, onValueChanged: \val -> setNodeName $ const val
, autoFocus: true
, className: "form-control"
......
......@@ -346,7 +346,8 @@ searchInputCpt = R.hooksComponentWithModule thisModule "searchInput" cpt
valueRef <- R.useRef term
pure $ H.div { className: "" } [
inputWithEnter { onEnter: onEnter valueRef setSearch
inputWithEnter { onBlur: onBlur valueRef setSearch
, onEnter: onEnter valueRef setSearch
, onValueChanged: onValueChanged valueRef
, autoFocus: false
, className: "form-control"
......@@ -364,6 +365,9 @@ searchInputCpt = R.hooksComponentWithModule thisModule "searchInput" cpt
-- , type: "text"
-- }
-- ]
onBlur valueRef setSearch value = do
R.setRef valueRef value
setSearch $ _ { term = value }
onEnter valueRef setSearch _ = do
setSearch $ _ { term = R.readRef valueRef }
......
......@@ -82,7 +82,8 @@ textInputBoxCpt = R.hooksComponentWithModule thisModule "textInputBox" cpt
textInput renameNodeNameRef =
H.div { className: "col-8" }
[ inputWithEnter {
onEnter: submit renameNodeNameRef
onBlur: R.setRef renameNodeNameRef
, onEnter: submit renameNodeNameRef
, onValueChanged: R.setRef renameNodeNameRef
, autoFocus: true
, className: "form-control"
......
......@@ -11,7 +11,8 @@ thisModule :: String
thisModule = "Gargantext.Components.InputWithEnter"
type Props a = (
onEnter :: Unit -> Effect Unit
onBlur :: String -> Effect Unit
, onEnter :: Unit -> Effect Unit
, onValueChanged :: String -> Effect Unit
, autoFocus :: Boolean
......@@ -27,9 +28,10 @@ inputWithEnter props = R.createElement inputWithEnterCpt props []
inputWithEnterCpt :: forall a. R.Component (Props a)
inputWithEnterCpt = R.hooksComponentWithModule thisModule "inputWithEnter" cpt
where
cpt props@{ onEnter, onValueChanged
cpt props@{ onBlur, onEnter, onValueChanged
, autoFocus, className, defaultValue, placeholder } _ = do
pure $ H.input { on: { input: onInput
pure $ H.input { on: { blur: onBlur'
, input: onInput
, keyPress: onKeyPress }
, autoFocus
, className
......@@ -38,6 +40,7 @@ inputWithEnterCpt = R.hooksComponentWithModule thisModule "inputWithEnter" cpt
, type: props.type }
where
onBlur' e = onBlur $ R.unsafeEventValue e
onInput e = onValueChanged $ R.unsafeEventValue e
onKeyPress e = do
......
......@@ -130,6 +130,7 @@ contactInfoItemCpt = R.hooksComponentWithModule thisModule "contactInfoItem" cpt
autoFocus: true
, className: "form-control"
, defaultValue: R.readRef valueRef
, onBlur: R.setRef valueRef
, onEnter: onClick
, onValueChanged: R.setRef valueRef
, placeholder
......
......@@ -130,6 +130,7 @@ contactInfoItemCpt = R.hooksComponentWithModule thisModule "contactInfoItem" cpt
autoFocus: true
, className: "form-control"
, defaultValue: R.readRef valueRef
, onBlur: R.setRef valueRef
, onEnter: onClick
, onValueChanged: R.setRef valueRef
, placeholder
......
......@@ -309,6 +309,7 @@ renameableTextCpt = R.hooksComponentWithModule thisModule "renameableTextCpt" cp
autoFocus: false
, className: "form-control text"
, defaultValue: text
, onBlur: setText <<< const
, onEnter: submit
, onValueChanged: setText <<< const
, placeholder: ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment