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] Add support for "{label: string}" data type as a default for "options" #21992

Conversation

DanailH
Copy link
Member

@DanailH DanailH commented Jul 29, 2020

This PR aims to add support for {label: string} data type for options in the Autocomplete UI component, as it was discussed in #21693

I've also updated one of the examples (the ComboBox one to have the new options type). I can revert that if it is not needed.

Fixes #21693

@mui-pr-bot
Copy link

mui-pr-bot commented Jul 29, 2020

Details of bundle changes

Generated by 🚫 dangerJS against 9dfab0d

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

I have added some documentation, let me know what you think about it

@oliviertassinari oliviertassinari added component: autocomplete This is the name of the generic UI component, not the React module! new feature New feature or request labels Jul 30, 2020
@@ -270,7 +270,7 @@ const Autocomplete = React.forwardRef(function Autocomplete(props, ref) {
fullWidth = false,
getLimitTagsText = (more) => `+${more}`,
getOptionDisabled,
getOptionLabel = (x) => x,
getOptionLabel = (x) => x.label ?? x,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
getOptionLabel = (x) => x.label ?? x,
getOptionLabel = (option) => option.label ?? x,

to use a descriptive name similar to useAutocomplete.

@DanailH DanailH force-pushed the feature/21693-autocomplete-default-options-type branch from f27c25c to 9dfab0d Compare August 2, 2020 15:13
@DanailH
Copy link
Member Author

DanailH commented Aug 2, 2020

Since this got quite messy I've cleaned up the commits to have only one containing all the changes plus everyone's feedback

@oliviertassinari
Copy link
Member

Since this got quite messy I've cleaned up the commits to have only one containing all the changes plus everyone's feedback

@DanailH It depends, on what you want to optimize for. If you need to rebase, definitely help. Otherwise, I think that keeping the commit history is better, they get squashed anyway once merged.

eps1lon
eps1lon previously requested changes Aug 2, 2020
Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

One question though: It seems like this doesn't add a default options type but changes it from string to { label: string }, no? This should be reflected in the PR title, description and label to create a proper changelog.

@DanailH DanailH changed the title [Autocomplete] Add support for default options type [Autocomplete] Add support for {label: string} data type for options Aug 2, 2020
@DanailH DanailH changed the title [Autocomplete] Add support for {label: string} data type for options [Autocomplete] Add support for "{label: string}" data type for "options" Aug 2, 2020
@DanailH DanailH changed the title [Autocomplete] Add support for "{label: string}" data type for "options" [Autocomplete] Add OOTB support for "{label: string}" data type for "options" Aug 2, 2020
@DanailH
Copy link
Member Author

DanailH commented Aug 2, 2020

One question though: It seems like this doesn't add a default options type but changes it from string to { label: string }, no? This should be reflected in the PR title, description and label to create a proper changelog.

I've updated the title and the description. Just to be clear, the default options type doesn't change from string to { label: string } but rather the component now supports { label: string } OOTB. Basically, if you pass string[] it will work and it will also work with { label: string }[] without the need of using the getOptionLabel. As far as I understood that was the outcome of the corresponding ticket.

@eps1lon
Copy link
Member

eps1lon commented Aug 2, 2020

Just to be clear, the default options type doesn't change from string to { label: string } but rather the component now supports { label: string } OOTB

The previous label getters were option => option indicating that they did support string by default. Every pre-existing test was using string options. I don't understand what you mean by implying that we didn't support a default data type.

@eps1lon eps1lon changed the title [Autocomplete] Add OOTB support for "{label: string}" data type for "options" [Autocomplete] Add support for "{label: string}" data type as a default for "options" Aug 2, 2020
@oliviertassinari oliviertassinari merged commit a93ed58 into mui:next Aug 4, 2020
@oliviertassinari
Copy link
Member

@DanailH Well done :)

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Autocomplete] Standard for Select options with different values
6 participants