Commit e184d32a authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[input with autocomplete] fix reactix call for blur

Add Reactix.preventDefault/stopPropagation
parent 279d1985
......@@ -4,7 +4,6 @@ module Gargantext.Components.GraphExplorer.Search
import Prelude
import Data.Sequence as Seq
import Data.Set as Set
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect (Effect)
import Reactix as R
......
......@@ -79,6 +79,8 @@ inputWithAutocompleteCpt = here.component "inputWithAutocomplete" cpt
onInputKeyUp :: R.Ref (Nullable DOM.Element) -> DE.KeyboardEvent -> Effect Boolean
onInputKeyUp inputRef e = do
if DE.key e == "Enter" then do
R2.preventDefault e
R2.stopPropagation e
let val = R.unsafeEventValue e
let mInput = toMaybe $ R.readRef inputRef
T.write_ val state
......
......@@ -27,12 +27,27 @@ function domRectFromRect(obj) {
return DOMRectReadOnly.fromRect(obj)
}
function preventDefault(e) {
return e.preventDefault();
}
function stopPropagation(e) {
return e.stopPropagation();
}
function blur(el) {
return el.blur();
}
exports._addRootElement = addRootElement;
exports._getSelection = getSelection;
exports._stringify = stringify;
exports._postMessage = postMessage;
exports._setCookie = setCookie;
exports._domRectFromRect = domRectFromRect;
exports._preventDefault = preventDefault;
exports._stopPropagation = stopPropagation;
exports._blur = blur;
exports._keyCode = function(e) {
// https://www.w3schools.com/jsref/event_key_keycode.asp
......
......@@ -335,14 +335,23 @@ inputFileNameWithBlob n e = case ff of
where
ff = inputFile n e
foreign import _preventDefault :: forall e. EffectFn1 e Unit
preventDefault :: forall e. DE.IsEvent e => e -> Effect Unit
preventDefault = runEffectFn1 _preventDefault
foreign import _stopPropagation :: forall e. EffectFn1 e Unit
stopPropagation :: forall e. DE.IsEvent e => e -> Effect Unit
stopPropagation = runEffectFn1 _stopPropagation
-- | Get blob from a drop event
--dataTransferFileBlob :: forall e. DE.IsEvent e => RE.SyntheticEvent e -> Effect Blob
dataTransferFileBlob e = unsafePartial $ do
let ff = fromJust $ item 0 $ ((e .. "dataTransfer" .. "files") :: FileList)
pure $ WF.toBlob ff
foreign import _blur :: EffectFn1 DOM.Element Unit
blur :: DOM.Element -> Effect Unit
blur el = el ... "blur" $ []
blur = runEffectFn1 _blur
row :: Array R.Element -> R.Element
row children = H.div { className: "row" } children
......
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