Skip to content

[Autocomplete] Add ability to render custom single value #45387

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

Conversation

ZeeshanTamboli
Copy link
Member

@ZeeshanTamboli ZeeshanTamboli commented Feb 24, 2025

Closes #26440

Based on the upvotes and requests in #26440, this PR introduces a new renderSingleValue prop to customize the display of the selected value. This is separate from renderTags for clarity. I avoided naming it renderTag to prevent potential confusion and typos.

Edit: Decided to go with renderValue as the prop name based on the discussion below. Also deprecated renderTags prop.

Preview: https://deploy-preview-45387--material-ui.netlify.app/material-ui/react-autocomplete/#custom-single-value-rendering

@ZeeshanTamboli ZeeshanTamboli added the component: autocomplete This is the name of the generic UI component, not the React module! label Feb 24, 2025
@mui-bot
Copy link

mui-bot commented Feb 24, 2025

Netlify deploy preview

@material-ui/core: parsed: +0.08% , gzip: +0.10%
Autocomplete: parsed: +0.29% , gzip: +0.27%
useAutocomplete: parsed: +3.24% , gzip: +2.72%
@material-ui/lab: parsed: +0.25% , gzip: +0.26%

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against cc4d7e9

@zannager zannager requested a review from DiegoAndai February 24, 2025 14:47
@ZeeshanTamboli ZeeshanTamboli removed the request for review from DiegoAndai February 24, 2025 14:53
@ZeeshanTamboli ZeeshanTamboli marked this pull request as draft February 24, 2025 14:54
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 25, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 25, 2025
@ZeeshanTamboli ZeeshanTamboli added the package: material-ui Specific to @mui/material label Feb 26, 2025
@ZeeshanTamboli
Copy link
Member Author

@aarongarciah @DiegoAndai @michaldudak I’ve made the discussed changes:

  • Deprecated renderTags and renamed the new prop to renderValue.
  • The value parameter now adapts based on the multiple prop in TypeScript.

Ready for further review.

@ZeeshanTamboli
Copy link
Member Author

Just a heads-up, this is ready for further review.

@DiegoAndai
Copy link
Member

DiegoAndai commented Apr 1, 2025

The preview looks good @ZeeshanTamboli 🙌🏼

Internally, some methods and variables still use "tag" since the deprecated renderTags depends on them. Renaming them would mean duplicating methods with the same logic for renderValue.

A question about this, could we modify render tags to use the renamed methods and variables? Or could that introduce breaking changes? What about the data-tag-index attribute?

@ZeeshanTamboli
Copy link
Member Author

ZeeshanTamboli commented Apr 2, 2025

@DiegoAndai

A question about this, could we modify render tags to use the renamed methods and variables? Or could that introduce breaking changes?

Yes, we can. Done! 👍 Please review carefully. There should be no breaking changes.

Since renderTags is deprecated, I’ve also deprecated getTagProps and focusedTag returned from useAutocomplete.

Regarding the tag, tagSizeSmall, and tagSizeMedium classes—should we deprecate them? tagSizeSmall and tagSizeMedium are specifically for Chips. What should we do?

What about the data-tag-index attribute?

To maintain backward compatibility with renderTags, the data-tag-index and data-item-index attributes are now added conditionally based on the renderValue prop. If renderValue prop is used, then data-item-index, else data-tag-index.

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.

LGTM in general.

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] 'renderTags' ignored when 'multiple' is false
5 participants