Commit e184d32a authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[input with autocomplete] fix reactix call for blur

Add Reactix.preventDefault/stopPropagation
parent 279d1985
Pipeline #2299 failed with stage
......@@ -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
......
'use strict';
function addRootElement(rootElem) {
document.body.insertBefore(
rootElem,
document.body.lastElementChild.nextElementSibling
);
document.body.insertBefore(
rootElem,
document.body.lastElementChild.nextElementSibling
);
}
function getSelection(_u) {
return window.getSelection();
return window.getSelection();
}
function stringify(j, indent) {
return JSON.stringify(j, null, indent);
return JSON.stringify(j, null, indent);
}
function postMessage(obj, msg, src) {
......@@ -20,11 +20,23 @@ function postMessage(obj, msg, src) {
}
function setCookie(c) {
document.cookie = c;
document.cookie = c;
}
function domRectFromRect(obj) {
return DOMRectReadOnly.fromRect(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;
......@@ -33,8 +45,11 @@ 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
return e.which || e.keyCode;
// https://www.w3schools.com/jsref/event_key_keycode.asp
return e.which || e.keyCode;
}
......@@ -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