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

[Autocomplete] Enable global customization of different options #36971

Merged
merged 26 commits into from
Jul 10, 2023

Conversation

nicolas-ot
Copy link
Contributor

@nicolas-ot nicolas-ot commented Apr 23, 2023

Closes #33423.

getOptionLabel can now be extracted through ownerState as fourth parameter to renderOption

This PR also add a test to check that getOptionLabel can be called through ownerState and that the function works properly.

New feature in action: codesandbox

@mui-bot
Copy link

mui-bot commented Apr 23, 2023

@oliviertassinari oliviertassinari added the component: autocomplete This is the name of the generic UI component, not the React module! label May 18, 2023
@nicolas-ot nicolas-ot marked this pull request as ready for review May 24, 2023 17:59
@nicolas-ot nicolas-ot changed the title [Autocomplete] Pass getOptionLabel as a parameter to renderOption [Autocomplete] Add ownerState as fourth parameter to renderOption May 24, 2023
@nicolas-ot
Copy link
Contributor Author

@ZeeshanTamboli please review

@zannager zannager requested a review from mnajdova May 25, 2023 06:56
@ZeeshanTamboli ZeeshanTamboli added the new feature New feature or request label May 26, 2023
Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

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

We should add the same in Joy UI's Autocomplete. Also adding demos demonstrating the use-case shown in #33423 (comment) would be great.

@nicolas-ot
Copy link
Contributor Author

nicolas-ot commented May 29, 2023

@ZeeshanTamboli i will now also add the same for Autocomplete in JoyUI. I've made the demo for material UI. Should I add a similar demo too for Joy UI?

You can check the demo here : demo

edit: renderOption of Autocomplete of JoyUI actually already has ownerState in the parameter. So I think I've done all of your review. Please re-review :)

Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

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

@nicolas-ot The Autocomplete in the demo is not visible in light mode because the demo's ThemeProvider overrides the docs' internal ThemeProvider. To determine the color mode of the docs, useTheme would need to be used, but this may not be a good demonstration for developers who would question the need for useTheme. Therefore, in my opinion, the best solution currently is to not showcase a demo and let developers rely on the API docs instead. What are your thoughts?

@nicolas-ot
Copy link
Contributor Author

@ZeeshanTamboli that is unfortunate, I didn't realize that. Personally I believe this demo is useful to show how you can easily customize the component for the whole app. I think it's important because one of the main reason people might be reluctant to use Material UI is that they might not really be too fond of Material Design and they don't know that Material UI is easily customizable like that.

It also showcases how to utilise ownerState. It's true that the API docs also explains it, but a quick glance on the demo with all the same styling might push user to find other alternative before finding the API.

As for using useTheme, I think a simple comment above it such as "to determine dark/light mode" should suffice. It might not be ideal, but the advantage far outweights the disadvantage.

@ZeeshanTamboli
Copy link
Member

ZeeshanTamboli commented Jun 1, 2023

@nicolas-ot I'm discussing it with the team and will inform you about the next steps.

If you want to research till then, this is how I did it recently in #36805.

@nicolas-ot
Copy link
Contributor Author

@ZeeshanTamboli any update?

@ZeeshanTamboli
Copy link
Member

@ZeeshanTamboli any update?

@nicolas-ot We haven't found a solution yet because the demo creates a new theme. Let's go ahead by using the useTheme hook and adding a comment explaining its purpose in determining light/dark mode. Afterward, we can seek someone else's opinion on it.

@nicolas-ot
Copy link
Contributor Author

I would do that, but would it be possible to seek someone's else opinion first before I actually implemented it? @ZeeshanTamboli

@michaldudak
Copy link
Member

I'm OK with useTheme, but let's also add a comment explaining why it's needed.

@nicolas-ot
Copy link
Contributor Author

@ZeeshanTamboli I've changed it as discussed. Please review.

@nicolas-ot
Copy link
Contributor Author

@ZeeshanTamboli I'm done updating. Please review again

Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

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

Looks generally good! Just two more comments.

@nicolas-ot
Copy link
Contributor Author

please review @ZeeshanTamboli

Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

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

@nicolas-ot It looks good to me. Nice work.

@ZeeshanTamboli ZeeshanTamboli added the package: material-ui Specific to @mui/material label Jul 10, 2023
@ZeeshanTamboli ZeeshanTamboli changed the title [Autocomplete] Add ownerState as fourth parameter to renderOption [Autocomplete] Make getOptionLabel available through renderOption Jul 10, 2023
@ZeeshanTamboli ZeeshanTamboli changed the title [Autocomplete] Make getOptionLabel available through renderOption [Autocomplete] Enable global customization of options Jul 10, 2023
@ZeeshanTamboli ZeeshanTamboli changed the title [Autocomplete] Enable global customization of options [Autocomplete] Enable global customization of different options Jul 10, 2023
@ZeeshanTamboli ZeeshanTamboli merged commit e0e5d28 into mui:master Jul 10, 2023
9 checks passed
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! new feature New feature or request package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Autocomplete] Pass getOptionLabel as a parameter to renderOption
5 participants