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

[RFC] Better consistency between Autocomplete and Select #43979

Open
joshkel opened this issue Oct 3, 2024 · 1 comment
Open

[RFC] Better consistency between Autocomplete and Select #43979

joshkel opened this issue Oct 3, 2024 · 1 comment
Assignees
Labels
component: autocomplete This is the name of the generic UI component, not the React module! RFC Request For Comments status: waiting for maintainer These issues haven't been looked at yet by a maintainer

Comments

@joshkel
Copy link
Contributor

joshkel commented Oct 3, 2024

What's the problem?

I'm exploring replacing some of our Select components with Autocomplete components (using the default combo box mode). My assumption was that these would look and act more or less the same as Select components, with the added ability to filter the list by typing on the keyboard. However, the components have several differences in appearance and behavior:

  1. Autocomplete's popup list is non-modal (the screen can still scroll). Select's is modal.
  2. Autocomplete closes its list if the user switches to another tab or window. Select's list stays open.
  3. Popup positioning differs: Select's tries to center around the Select component but constrains to the boundaries of Select's container, while Autocomplete's is more flexible. (See the demo - the Select component's popup is left-aligned with the Select component, due to the contraints of the surrounding Box, while the Autocomplete's is not.)
  4. In dark mode, Autocomplete's list's background is a darker color than Select's (because Select's Popover uses an elevation of 8, while Autocomplete gives its Paper an elevation of 2).
  5. Autocomplete's list is always the width of the autocomplete element. Select's list uses the Select element as a minimum width but can auto-size based on the menu contents.
  6. Select's list uses a transition. Autocomplete's list appears immediately.
  7. Autocomplete's list uses word wrapping. Select's list cuts off long items.
  8. Select's list takes up to the full height of the screen. Autocomplete's is constrained to above or below the autocomplete element and is limited in height (beyond what's required by fitting above or below the autocomplete element).

What are the requirements?

Greater consistency and compatibility - avoid noticeable UX differences, unless there are clear reasons for them

What are our options?

Issues 1-3 (differences in modal, focus handling, and positioning) are likely the result of Select's use of Menu and Popover versus Autocomplete's use of Popper. This may be related to #38756.

Items 4-5 and (to some extent) 6 can be handled by changes to props and components, although I personally would appreciate not needing to apply these customizations myself.

Item 8 seems like a desirable difference: the autocomplete element needs to stay visible so the user can see what they're typing, and limiting the height seems perfectly reasonable.

(There may be UX issues I haven't considered that argue against changing any or all of these.)

Proposed solution

Some simple starting changes would include changing Autocomplete's Paper's elevation to 8 to match Popover and changing it to pass minWidth instead of width to the Popper's style.

Resources and benchmarks

https://stackblitz.com/edit/react-3apdzs?file=Demo.tsx has a side-by-side comparison of Select and Autocomplete, including a demonstration of some props and component changes to make Autocomplete more like Select.

Customizing Autocomplete width has come up before: #19376

Search keywords:

@joshkel joshkel added RFC Request For Comments status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 3, 2024
@oliviertassinari oliviertassinari added the component: autocomplete This is the name of the generic UI component, not the React module! label Oct 3, 2024
@ijxy
Copy link
Contributor

ijxy commented Oct 6, 2024

Autocomplete, whilst convenient sometimes, does not work properly with hydration (it flickers, maybe the internal state management is relying on useEffect, which would explain it, but I haven't checked).

See for example with query strings. If you refresh the page, Select and TextField (select mode) hydrate immediately, whereas Autocomplete shows the empty state then hydrates with the value.

https://codesandbox.io/p/devbox/5swdg3

That is to say that any solution that makes Select/TextField similarly badly behaved during hydration should be avoided, IMO.

That said, if Autocomplete hydrated properly on initial render then I'd use it almost every time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module! RFC Request For Comments status: waiting for maintainer These issues haven't been looked at yet by a maintainer
Projects
None yet
Development

No branches or pull requests

4 participants