-
Notifications
You must be signed in to change notification settings - Fork 27
Add option groups to Select component #431
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
Add option groups to Select component #431
Conversation
* Adds more tests for the existing behaviors of Select, plus tests for OptionMenuList - this is to facilitate future changes to Select. * Fixes a bug in Select where a disabled option could still be selected via the keyboard.
3c21d84
to
5668742
Compare
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.
} from '../../source/react/constants'; | ||
|
||
// Example with option groups | ||
const options = [ |
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.
nittiest of nits: call this optionsWithGroups
?
return eventObj; | ||
}; | ||
|
||
const MANY_TIMES = 8; // (more times than the number of focusable items in these examples) |
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.
this made me laugh, i'm not sure why.
* OptionMenuListItem has a new prop, `type`, which can be set to either `option` (the default) or `heading` (an option group heading). The usual OptionMenuListItem event handlers and icons are ignored for option group headings. * OptionMenuList now accepts arrays of child options as option values; these values will be rendered as an option group. The parent item's label will be used as the option group heading. If the parent item is disabled, all children will also be disabled.
5668742
to
ff1b7ae
Compare
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.
Looks like a good approach to me!
Adds a small border between groups to help the user distinguish between them.
Made a tiny tweak to add in some borders. LGTM! |
Thanks @Sigler I'll fix up these linting errors and add a changelog entry before I merge! |
Also fixes a linting error
This PR implements option groups for the Select component (and by extension, the OptionMenuList component) - I've been working off of this design for the forge.
In short, this makes it so that for Select components, if you specify an array of options as an option value, the array items will be the child options, and the parent's label will be the option group title. I have not enabled focus or click/select events for group titles (but happy to do so if wanted).
This was a pretty large change, but I added several new tests for OptionMenuList and Select to try to ensure all existing behavior stayed the same. This also fixes a small bug in Select where disabled items could be selected via keyboard.