[reactix] better focus function, more triggers removal

parent e52647f9
Pipeline #7030 passed with stages
in 15 minutes and 27 seconds
...@@ -54,6 +54,14 @@ export function _keyCode(e) { ...@@ -54,6 +54,14 @@ export function _keyCode(e) {
return e.which || e.keyCode; return e.which || e.keyCode;
} }
export function _implFocus(nel) {
if (nel === null) {
return;
} else {
nel.focus();
}
}
export function _scrollIntoView(el) { export function _scrollIntoView(el) {
return el.scrollIntoView({ return el.scrollIntoView({
behavior: 'smooth', behavior: 'smooth',
......
...@@ -494,10 +494,12 @@ foreign import _setCookie :: EffectFn1 String Unit ...@@ -494,10 +494,12 @@ foreign import _setCookie :: EffectFn1 String Unit
setCookie :: String -> Effect Unit setCookie :: String -> Effect Unit
setCookie = runEffectFn1 _setCookie setCookie = runEffectFn1 _setCookie
foreign import _implFocus :: EffectFn1 (Nullable R.Element) Unit
focus :: Nullable R.Element -> Effect Unit focus :: Nullable R.Element -> Effect Unit
focus nEl = case toMaybe nEl of focus nel = runEffectFn1 _implFocus nel
Nothing -> pure unit
Just el -> el ... "focus" $ []
foreign import _scrollIntoView :: EffectFn1 DOM.Element Unit foreign import _scrollIntoView :: EffectFn1 DOM.Element Unit
...@@ -509,24 +511,6 @@ setIndeterminateCheckbox :: R.Element -> Boolean -> Effect R.Element ...@@ -509,24 +511,6 @@ setIndeterminateCheckbox :: R.Element -> Boolean -> Effect R.Element
setIndeterminateCheckbox el val = pure $ (el .= "indeterminate") val setIndeterminateCheckbox el val = pure $ (el .= "indeterminate") val
-- A "trigger" is a ref to a function which is used to make changes without
-- modifying too much DOM.
-- This is to escape passing explicit state to nested child components.
type Trigger a = R.Ref (Maybe (a -> Effect Unit))
callTrigger :: forall a. Trigger a -> a -> Effect Unit
callTrigger tRef arg = case R.readRef tRef of
Nothing -> do
log2 "[callTrigger] trigger is empty" tRef
pure unit
Just t -> t arg
setTrigger :: forall a. Trigger a -> (a -> Effect Unit) -> Effect Unit
setTrigger tRef fun = R.setRef tRef $ Just fun
clearTrigger :: forall a. Trigger a -> Effect Unit
clearTrigger tRef = R.setRef tRef Nothing
type Rect = type Rect =
( x :: Number ( x :: Number
, y :: Number , y :: Number
......
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