Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a use_linked_inputs widget instead of Input #475

Closed
rmorshea opened this issue Aug 22, 2021 · 1 comment · Fixed by #593
Closed

Create a use_linked_inputs widget instead of Input #475

rmorshea opened this issue Aug 22, 2021 · 1 comment · Fixed by #593
Labels
priority-1-high Should be resolved ASAP. type-revision About a change in functionality or behavior
Milestone

Comments

@rmorshea
Copy link
Collaborator

rmorshea commented Aug 22, 2021

Old Behavior

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")


def use_linked_inputs(
    attributes: Iterable[Dict[str, Any]],
    on_change: Callable[[_CastInput], None] = lambda value: None,
    cast: Callable[[str], _CastInput] = lambda value: 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)

    def sync_inputs(event: Dict[str, Any]) -> None:
        new_value = event["value"]
        set_value(new_value)
        if not new_value and ignore_empty:
            return None
        on_change(cast(new_value))

    return [
        idom.html.input({**attrs, "onChange": sync_inputs, "value": value})
        for attrs in attributes
    ]
@rmorshea rmorshea added flag-triage Not prioritized. low priority and removed flag-triage Not prioritized. low priority labels Aug 22, 2021
@rmorshea rmorshea added the type-feature About new capabilities label Jan 11, 2022
@rmorshea rmorshea added this to the 1.0 milestone Jan 11, 2022
@rmorshea rmorshea added priority-2-moderate Should be resolved on a reasonable timeline. type-revision About a change in functionality or behavior priority-1-high Should be resolved ASAP. and removed type-feature About new capabilities priority-2-moderate Should be resolved on a reasonable timeline. labels Jan 13, 2022
@rmorshea
Copy link
Collaborator Author

Since index is now the default this needs to be fixed before the next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-1-high Should be resolved ASAP. type-revision About a change in functionality or behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant