-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
[base-ui][Select] Fix display of selected Options with rich content #40689
Conversation
Netlify deploy previewhttps://deploy-preview-40689--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
@@ -43,7 +43,7 @@ const InnerOption = React.memo( | |||
// If `label` is not explicitly provided, the `children` are used for convenience. | |||
// This is used to populate the select's trigger with the selected option's label. | |||
const computedLabel = | |||
label ?? (typeof children === 'string' ? children : optionRef.current?.innerText); | |||
label ?? (typeof children === 'string' ? children : optionRef.current?.textContent?.trim()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this affect/fix the demo? Testing it out and getting the same value for both innerText
and textContent
:
Screen.Recording.2024-01-19.at.10.52.58.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the "before" demo, the Select is initially "collapsed" (too short).
The difference between innerText
and textContent
(that I learned today) is that innerText
takes display properties into consideration. So if an option is hidden (as it initially is), innerText
will return ''. textContent
, on the other hand always returns what's defined in the DOM node, regardless of visibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aah, right, it's collapsed, so it's hidden, and innerText
doesn't return it, gotcha!
When Select's Options had rich content (= more than a plain string), such as an icon or an image, selecting such an option did not display properly. The effect was as if nothing was selected.
See the "Select a component" Select:
before: https://deploy-preview-40683--material-ui.netlify.app/base-ui/
after: https://deploy-preview-40689--material-ui.netlify.app/base-ui/