Skip to content

Select overrides selected prop on children items #44951

@MonstraG

Description

@MonstraG

Steps to reproduce

Steps:

  1. Open this link to live example: https://stackblitz.com/edit/react-mpdrbwbo?file=Demo.tsx, look at BasicSelect
  2. open select

Current behavior

Select passes selected based on value and ignores existing value of selected of MenuItem.

Expected behavior

Select passes selected based on value, but only if it's undefined.

Context

This might be sort of X-Y problem.

The stackblitz link contains another element - ComplicatedSelect. This more closely resembles select from my app.

I'm trying to implement Select all option, and the only thing that is blocking me is selected not working.

With selected={selectAllValue !== 'none'} I expect it to be hightlighted, whenever at least one element is selected, but it is never selected, because it's not in value prop.

I can put the value of the Select all checkbox in the value array on the fly, but that would also require adding magical -1 in renderValue which feels brittle, but most imporantly, it results in onChange breaking becase it will not be in event.target.value after click.

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: select selected MenuItem overrides undefined

Metadata

Metadata

Assignees

Labels

accessibilitya11yscope: selectChanges related to the select.type: expected behaviorThe current behavior is already the one expected.type: new featureExpand the scope of the product to solve a new problem.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions