Skip to content

[textfield] Use non-native label for <TextField select/>#47958

Open
mj12albert wants to merge 2 commits intomui:masterfrom
mj12albert:fix/textfield-select-label
Open

[textfield] Use non-native label for <TextField select/>#47958
mj12albert wants to merge 2 commits intomui:masterfrom
mj12albert:fix/textfield-select-label

Conversation

@mj12albert
Copy link
Member

@mj12albert mj12albert commented Mar 12, 2026

Breaking: The visible text label uses a div instead of a label element for <TextField select/>

Part of #47489

Preview: https://deploy-preview-47958--material-ui.netlify.app/material-ui/react-text-field/#select

Avoids devtool errors about incorrect use of the label element; it's not strictly needed as the component is named with aria-labelledby already.

@mj12albert mj12albert added type: bug It doesn't behave as expected. scope: text field Changes related to the text field. labels Mar 12, 2026
@mj12albert mj12albert changed the title Use non-native label for TextField.select [textfield] Use non-native label for <TextField select/> Mar 12, 2026
@mui-bot
Copy link

mui-bot commented Mar 12, 2026

Netlify deploy preview

https://deploy-preview-47958--material-ui.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/material 🔺+108B(+0.02%) 🔺+28B(+0.02%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against 70c9981

@mj12albert mj12albert added breaking change Introduces changes that are not backward compatible. and removed type: bug It doesn't behave as expected. labels Mar 12, 2026
@mj12albert mj12albert force-pushed the fix/textfield-select-label branch from b7a4fad to dd591cf Compare March 12, 2026 15:13
@mj12albert mj12albert marked this pull request as ready for review March 12, 2026 15:14
props: ({ ownerState }) => ownerState.formControl,
style: {
'label + &': {
[`.${inputLabelClasses.root} + &`]: {
Copy link
Member

Choose a reason for hiding this comment

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

Note that this increases specificity from (0,1,0) to (0,2,0) might break some customization.

Copy link
Member

Choose a reason for hiding this comment

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

can you try:

Suggested change
[`.${inputLabelClasses.root} + &`]: {
[`label + &, div:where(.${inputLabelClasses.root}) + &`]: {

Copy link
Member Author

@mj12albert mj12albert Mar 13, 2026

Choose a reason for hiding this comment

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

Updated to: [`label + &, :where(.${inputLabelClasses.root}) + &`] without the div (in case it's a span or sth)

With :where, the new selector is even less specific than the original one, so it could be ok to drop the label + & one as this PR is marked breaking anyway 🤔

Copy link
Member Author

@mj12albert mj12albert Mar 13, 2026

Choose a reason for hiding this comment

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

(the preview works, dunno why Argos is getting an error or stuck on an old snapshot)

@mj12albert mj12albert force-pushed the fix/textfield-select-label branch from 155b34f to afffdab Compare March 13, 2026 05:45
@mj12albert mj12albert requested a review from siriwatknp March 13, 2026 05:54
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 13, 2026
@mj12albert mj12albert force-pushed the fix/textfield-select-label branch from 35af8d8 to 4028882 Compare March 13, 2026 11:44
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 13, 2026
@mj12albert mj12albert force-pushed the fix/textfield-select-label branch 3 times, most recently from 49b1c2c to 96c18cc Compare March 13, 2026 13:22
@mj12albert mj12albert force-pushed the fix/textfield-select-label branch from 96c18cc to 70c9981 Compare March 13, 2026 14:38
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.

In the description it is mentioned:

Part of #47489

From the changes done, I see it completely fixes #47489, doesn't it?

'label + &': {
marginTop: 16,
},
[`label + &, :where(.${inputLabelClasses.root}) + &, div:where(.${inputLabelClasses.root}) + &`]:
Copy link
Member

Choose a reason for hiding this comment

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

I see label is needed when native select with TextField is used. But why div is also needed? Couldn't it be simplified to:

Suggested change
[`label + &, :where(.${inputLabelClasses.root}) + &, div:where(.${inputLabelClasses.root}) + &`]:
[`label + &, :where(.${inputLabelClasses.root}) + &`]:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Introduces changes that are not backward compatible. scope: text field Changes related to the text field.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants