-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[Joy] Add Autocomplete
component
#34315
Conversation
7516373
to
9c3daa6
Compare
@michaldudak I did what you suggested about the input slot and the result is amazing. Even though it is a bit more code to add but the abstraction is a lot better. Now the customization experience is similar to the We can completely think of autocomplete as an enhanced version of the |
Added TypeScript demos. |
By getting rid of |
@flaviendelangle took the same direction in mui/mui-x#5504 by not exposing the TextField as a React.createElement. For the history of the date picker, v3 didn't have
@dmtrKovalenko do you remember was were the main struggles of the date picker in v3 without It will be interesting to see the new class of issues that developers raise without |
Yes I think I remember that was about reducing amount of spreaded props. So for customising input we don't need to pass 17 props to the root component and make root components props to be spread into the modal |
Preview
🖥 https://deploy-preview-34315--material-ui.netlify.app/joy-ui/react-autocomplete/
Internal changes
There are some logics in
useAutocomplete
that tie to Material UI autocomplete structure, so I added internal options for using with Joy UI.Some CSS variables in Joy UI components, e.g. Input, Chip, are updated to work seamlessly with the Autocomplete when size prop changes.
Components
Autocomplete
: usesuseAutocomplete
from MUI BaseAutocompleteListbox
: reuses the same styles asList
which lets developers build a custom list box if needed.AutocompleteOption
: reuses the same styles asListItemButton
which lets developers build a custom option if needed.Differences compared to Material UI
1. Autocomplete does not expose
renderInput
. It is an input in itself which lets developers control the global variants, colors, and sizes as if they are using theInput
component.Joy UI:
Material UI:
2. Tag composition
Joy UI Chip does not support
onDelete
so developers have to compose by themselves:Joy UI:
Material UI:
This approach is easier to customize if developers don't want to show the delete button.
3.
AutocompleteListbox
A new component used by default in
Autocomplete
and can be used for complex customization. Material UI uses plainul
+ styled-component for customization.Joy UI:
Material UI:
4.
AutocompleteOption
Similar to the list box customization, it is used by default in
Autocomplete
component. Developers can use it to customize the option appearance.Joy UI:
Material UI:
Test
👍 The test suite is the same as Material UI Autocomplete tests.
Comparison
Lines of code: This can be comparable because both Material UI and Joy UI are using the same
useAutocomplete
from MUI Base.Joy UI reduces styles by ~50% compared to Material UI which still produces a similar appearance.