-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[Select]Bug when the first child is a ListSubheader #27299
Changes from 2 commits
8f97e85
247e7fe
3e2d580
5a970c5
52130ee
d028882
5f197e1
f966267
408d3a0
9a45a10
26a47e9
efffa1f
36402c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,7 +328,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) { | |
} | ||
} | ||
|
||
const items = childrenArray.map((child) => { | ||
const items = childrenArray.map((child, index, arr) => { | ||
if (!React.isValidElement(child)) { | ||
return null; | ||
} | ||
|
@@ -369,6 +369,20 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) { | |
foundMatch = true; | ||
} | ||
|
||
const hasOptionSelected = () => { | ||
if (arr.find((item) => areEqualValues(value, item.props.value))) { | ||
return selected; | ||
} | ||
return true; | ||
}; | ||
|
||
if (child.props.value === undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This returns a different object when the option is a ListSubheader. The role option is because the role listbox of the Menu needs that the children have the role option, but when the option is not a selectable option the aria-selected should be omitted. |
||
return React.cloneElement(child, { | ||
'aria-readonly': true, | ||
role: 'option', | ||
}); | ||
} | ||
|
||
return React.cloneElement(child, { | ||
'aria-selected': selected ? 'true' : undefined, | ||
onClick: handleItemClick(child), | ||
|
@@ -385,7 +399,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) { | |
} | ||
}, | ||
role: 'option', | ||
selected, | ||
selected: index === 1 && arr[0].props.value === undefined ? hasOptionSelected() : selected, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here when the first child is a ListSubheader it sets the selected true to the second option, to gains the focus when the list of options is open, with the tabindex = 0, to the arrow down works. |
||
value: undefined, // The value is most likely not a valid HTML attribute. | ||
'data-value': child.props.value, // Instead, we provide it as a data attribute. | ||
}); | ||
|
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.
And here, when you select an option don't need more to set the second option as selected true to gain the focus.