You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Create a use_linked_inputs widget instead of Input #475
The current Input widget is clunky to use and was created primarily for the purpose of making it easier to construct a set of linked inputs. The current Input util also doesn't work when the IDOM_FEATURE_INDEX_AS_DEFAULT_KEY=1 feature flag is set.
New Behavior
To resolve this we should create a use_linked_inputs widget utility that can achieve this use case with a better interface and also work with the IDOM_FEATURE_INDEX_AS_DEFAULT_KEY=1 feature flag set.
Implementation Details
_CastInput=TypeVar("_CastInput")
defuse_linked_inputs(
attributes: Iterable[Dict[str, Any]],
on_change: Callable[[_CastInput], None] =lambdavalue: None,
cast: Callable[[str], _CastInput] =lambdavalue: value,
initial_value: str="",
ignore_empty: bool=True,
) ->List[VdomDict]:
"""Return a list of linked inputs equal to the number of given attributes"""value, set_value=idom.hooks.use_state(initial_value)
defsync_inputs(event: Dict[str, Any]) ->None:
new_value=event["value"]
set_value(new_value)
ifnotnew_valueandignore_empty:
returnNoneon_change(cast(new_value))
return [
idom.html.input({**attrs, "onChange": sync_inputs, "value": value})
forattrsinattributes
]
Activity
rmorshea commentedon Jan 14, 2022
Since index is now the default this needs to be fixed before the next release