Skip to content

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

Merged
merged 4 commits into from
Jun 1, 2021

Conversation

caseywilliams
Copy link
Contributor

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.

@caseywilliams caseywilliams requested a review from a team as a code owner May 24, 2021 17:00
* 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.
@caseywilliams caseywilliams force-pushed the select-option-groups branch from 3c21d84 to 5668742 Compare May 24, 2021 17:15
Copy link
Contributor

@eputnam eputnam left a comment

Choose a reason for hiding this comment

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

ilikewhatyouvedonehere

not sure i should be the last person to review this but it LGTM. I'm an especially big fan of all those tests. woot.

} from '../../source/react/constants';

// Example with option groups
const options = [
Copy link
Contributor

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)
Copy link
Contributor

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.
@caseywilliams caseywilliams force-pushed the select-option-groups branch from 5668742 to ff1b7ae Compare May 27, 2021 18:57
Copy link
Contributor

@scotje scotje left a 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.
@CLAassistant
Copy link

CLAassistant commented Jun 1, 2021

CLA assistant check
All committers have signed the CLA.

@Sigler
Copy link
Contributor

Sigler commented Jun 1, 2021

Made a tiny tweak to add in some borders. LGTM!

@caseywilliams
Copy link
Contributor Author

Thanks @Sigler I'll fix up these linting errors and add a changelog entry before I merge!

Also fixes a linting error
@caseywilliams caseywilliams merged commit 679f3c0 into puppetlabs:main Jun 1, 2021
@caseywilliams caseywilliams deleted the select-option-groups branch June 1, 2021 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants