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

Review the Autocomplete component and implement improvements #5106

Closed
matuzalemsteles opened this issue Sep 22, 2022 · 1 comment · Fixed by #5108
Closed

Review the Autocomplete component and implement improvements #5106

matuzalemsteles opened this issue Sep 22, 2022 · 1 comment · Fixed by #5108
Assignees
Labels
comp: clay-components Issues related to Clay components. (e.g ClayCard, ClayLabel...) type: enhancement Issues that are open to bring improvements or refinement of code

Comments

@matuzalemsteles
Copy link
Member

To go ahead with the #5100 Collection pattern for this component we need to review some implementations to provide the Collection pattern, with data provider integration as well. Some things we need to reconsider and design of this component.

  • Composition is a bit verbose and provides few OOTB features
  • Developer needs to control focus
  • The developer needs to control the visibility of the Menu according to the interaction with the input

Currently an Autocomplete component looks like this:

<ClayAutocomplete>
  <ClayAutocomplete.Input
    aria-label="Numbers: Enter a number from One to Five"
    onChange={(event: any) =>
      setValue(event.target.value)
    }
    value={value}
  />

  <ClayAutocomplete.DropDown active={!!value}>
    <ClayDropDown.ItemList>
      {['one', 'two', 'three', 'four', 'five']
        .filter((item) => item.match(value))
        .map((item) => (
          <ClayAutocomplete.Item
            key={item}
            match={value}
            onClick={() => setValue(item)}
            value={item}
          />
        ))}
    </ClayDropDown.ItemList>
  </ClayAutocomplete.DropDown>
</ClayAutocomplete>

The goal is to redesign the component composition design and resolve the above issues. This way we were able to implement the collection pattern better.

An example of pseudocode:

<Autocomplete
  defaultItems={['one', 'two', 'three']}
>
  {(item) => (
    <Autocomplete.Item>
      {item}
    </Autocomplete.Item>
  )}
</Autocomplete>

This is just an idea of what the component will look like already using the Collection pattern, it will no longer be necessary to declare the Input component it is automatically rendered inside Autocomplete and can be configured by passing properties directly to it.

Observing the usage in DXP, Autocomplete.Input it is more configured to control the focus state and manage the control of the active state, so for this scenario we can still continue providing these callbacks but these functionalities will be controlled by the component itself and reduced implementation on the usage side.

@github-actions
Copy link

This issue has been merged and will be released in DXP at https://issues.liferay.com/browse/LPS-163480

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: clay-components Issues related to Clay components. (e.g ClayCard, ClayLabel...) type: enhancement Issues that are open to bring improvements or refinement of code
Projects
None yet
1 participant