mui / mui/material-ui

[Select] Pass rendered content of MenuItem to renderValue function

Open
#19,585 3 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ready to take scope: select type: new feature
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 💡

In the current situation it's possible to customize the rendered content of a Select component using the renderValue prop. This works really well I just have one gripe. I would like the rendered content of the selected MenuItem to be passed as an argument as well.

As a solution that wont break existing implementations I propose it would be passed as a second function argument, e.g.:

function(value: any, content: ReactNode) => ReactNode

When using the multiple prop the content argument would be an array of ReactNodes.

Motivation 🔦

Often I'm using customized content inside the MenuItems in my Select, like icons and avatars. When not using the renderValue prop this content is automatically rendered inside the Select when a selecting a value. However when using the renderValue prop you only get passed the value as function parameter, you would have to generate the content again inside the renderValue function.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the Select renderValue implementation and how selected MenuItem content is rendered. Confirm the existing renderValue(value) behavior, then verify that rendered content is available as a second argument and as an array for multiple selections without breaking existing usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.