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