-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
ToggleGroupControl: Add de-selectable variant #45123
Conversation
Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
34f56c4
to
12fd768
Compare
Size Change: +219 B (0%) Total Size: 1.28 MB
ℹ️ View Unchanged
|
} = { | ||
...toggleGroupControlContext, | ||
...buttonProps, | ||
}; |
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.
Instead we're going to destructure our props from toggleGroupControlContext
and buttonProps
separately so we have better control over where they are forwarded.
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.
Definitely more clear 🌞
className, | ||
isActive && styles.buttonActive | ||
styles.buttonView( { isDeselectable, isIcon, isPressed, size } ), | ||
className | ||
); |
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.
The "icon" and "active" styles were moved to be handled in the buttonView
function, because we can't control the cascade order in cx()
itself.
export const separatorActive = css` | ||
background: transparent; | ||
`; |
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 wasn't being used anywhere 🧹
|
||
const noop = () => {}; | ||
|
||
function UnconnectedToggleGroupControl( | ||
props: WordPressComponentProps< ToggleGroupControlProps, 'input', false >, | ||
props: WordPressComponentProps< ToggleGroupControlProps, 'div', false >, |
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.
Apparently this was wrong. Rest props were being forwarded to a div, not an input
.
return ( | ||
<LabelView className={ labelViewClasses } data-active={ isActive }> |
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.
Removed the data-active
because apparently this was only being used as a selector in an e2e test.
@@ -233,7 +233,7 @@ describe( 'Font Size Picker', () => { | |||
await page.keyboard.type( 'Paragraph to be made "large"' ); | |||
|
|||
await clickFontSizeButtonByLabel( 'Large' ); | |||
const buttonSelector = `${ FONT_SIZE_TOGGLE_GROUP_SELECTOR }//div[@data-active='true']//button`; | |||
const buttonSelector = `${ FONT_SIZE_TOGGLE_GROUP_SELECTOR }//button[@aria-checked='true']`; |
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.
Changed to a more standard selector.
0338cae
to
6f4b7a6
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.
Thank you for splitting these changes in smaller PRs! It really improves the review process
I took a look at the new Storybook examples and things are looking pretty good!
Kapture.2022-10-21.at.13.36.33.mp4
Should we also remove the __experimentalIsBorderless
prop from the Justification ToggleGroupControl
?
} = { | ||
...toggleGroupControlContext, | ||
...buttonProps, | ||
}; |
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.
Definitely more clear 🌞
packages/components/src/toggle-group-control/toggle-group-control-option-base/component.tsx
Outdated
Show resolved
Hide resolved
packages/components/src/toggle-group-control/toggle-group-control-option-base/component.tsx
Outdated
Show resolved
Hide resolved
packages/components/src/toggle-group-control/toggle-group-control-option-base/component.tsx
Outdated
Show resolved
Hide resolved
packages/components/src/toggle-group-control/toggle-group-control-option-base/styles.ts
Outdated
Show resolved
Hide resolved
packages/components/src/toggle-group-control/toggle-group-control/styles.ts
Show resolved
Hide resolved
packages/components/src/toggle-group-control/toggle-group-control/as-button-group.tsx
Show resolved
Hide resolved
- otherProps are forwarded to div, not `input` - ToggleGroupControl should not accept a `disabled` prop, but it was included via the FormElementProps type
- Removed unused `separatorActive` - Don't lighten button when deselectable
Co-authored-by: Marco Ciampini <[email protected]>
9588263
to
5591154
Compare
That was some great feedback, thanks! Everything should be addressed now.
Good catch, done 👍 |
* | ||
* @default false | ||
*/ | ||
__experimentalIsBorderless?: boolean; |
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.
Given the recent conversations around deprecating and removing props, are we able to simply delete this prop, even if it's experimental?
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.
Until any new rules are codified, I'd say yes. It also helps that this is a cosmetic difference that doesn't break layout.
packages/components/src/toggle-group-control/toggle-group-control/as-button-group.tsx
Show resolved
Hide resolved
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.
🚀
Extracted from #44168 (where a high-level review was completed first)
What?
Add an
isDeselectable
prop to allow ToggleGroupControl to be deselectable.Why?
See #44168
How?
isDeselectable
prop is enabled, we use the button group implementation.__experimentalIsBorderless
prop is removed, since the border will be dictated by whether or not the control is deselectable.Testing Instructions
npm run storybook:dev
and see the ToggleGroupControl stories.Screenshots or screencast