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

[base-ui][useSelect] Support browser autofill #39595

Merged
merged 9 commits into from
Oct 26, 2023

Conversation

DiegoAndai
Copy link
Member

@DiegoAndai DiegoAndai commented Oct 24, 2023

Closes #37646

Support browser autofill in the useSelect hook and Select component.

Changes:

  • Add onChange handler to getHiddenInputProps which
    • dispatches a (new) browser autofill action if the value is found in the options
    • dispatches a (new) clear selection action if the value is an empty string
  • Add autoComplete prop to Select component and forward to the hidden input
  • Added tests for all the changes.

Manual testing

I tested with

  • 1Password on Chrome
  • Chrome native autofill (including clear autofill, avoiding #31426 by clearing when the onChange handler is called with an empty string as value)
  • Safari native autofill

I couldn't get Firefox autofill to work on my computer, so I didn't test with that one. Apparently, the feature is blocked by region.

Demo

Before changes: https://codesandbox.io/s/base-ui-select-autofill-demo-benchmark-rz7qff?file=/src/Demo.tsx
After changes: https://codesandbox.io/s/base-ui-select-autofill-demo-nj6ylw?file=/src/Demo.tsx

Screen.Recording.2023-10-24.at.16.38.06.mov

@DiegoAndai DiegoAndai added new feature New feature or request component: select This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base labels Oct 24, 2023
@DiegoAndai DiegoAndai self-assigned this Oct 24, 2023
@mui-bot
Copy link

mui-bot commented Oct 24, 2023

Netlify deploy preview

https://deploy-preview-39595--material-ui.netlify.app/

@material-ui/unstyled: parsed: +0.38% , gzip: +0.25%
@mui/joy: parsed: +0.12% , gzip: +0.11%

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against ab94a1d

@DiegoAndai
Copy link
Member Author

DiegoAndai commented Oct 24, 2023

@michaldudak I'm thinking about the following refactor:

  • Remove the autoComplete prop from the Select component
  • Add support for slotProps.input (or slotProps.hiddenInput) so users can provide the autoComplete value that way

What do you think? What would you name the input's slot if we go that route?

@michaldudak
Copy link
Member

I'd keep it on the Select. It'll be more in-line with the native HTML select.

Copy link
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks and works great! Good job!

@DiegoAndai DiegoAndai merged commit 4b35e64 into mui:master Oct 26, 2023
22 checks passed
@DiegoAndai DiegoAndai deleted the use-select-autofill branch October 26, 2023 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: select This is the name of the generic UI component, not the React module! new feature New feature or request package: base-ui Specific to @mui/base
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Select][base-ui] Support the autoComplete prop
3 participants