-
Notifications
You must be signed in to change notification settings - Fork 156
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
feat: Support for toggle buttons in button group #2909
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2909 +/- ##
==========================================
+ Coverage 96.27% 96.30% +0.02%
==========================================
Files 769 772 +3
Lines 21768 21848 +80
Branches 7039 7477 +438
==========================================
+ Hits 20958 21040 +82
+ Misses 802 755 -47
- Partials 8 53 +45 ☔ View full report in Codecov by Sentry. |
883bd49
to
1fe6263
Compare
16eb96c
to
8f66e2d
Compare
1d96218
to
665ddad
Compare
665ddad
to
20951d4
Compare
20951d4
to
421b593
Compare
2acd039
to
35cf88e
Compare
{ | ||
"name": "id", | ||
"optional": false, | ||
"type": "string", | ||
}, | ||
{ | ||
"name": "pressed", |
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 property is present when the new toggle button is clicked.
@@ -3790,11 +3790,21 @@ exports[`Documenter definition for button-group matches the snapshot: button-gro | |||
"detailInlineType": { | |||
"name": "InternalButtonGroupProps.ItemClickDetails", | |||
"properties": [ | |||
{ | |||
"name": "checked", |
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 property is present when a menu item of type "checkbox" is clicked.
@@ -0,0 +1,140 @@ | |||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
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.
I reworked button group unit tests. Now all tests are split across multiple files focusing on specific categories of tests. The tests ensure full coverage for all button group item types.
In the dev tests we validate dev warnings, fallbacks, and callbacks.
@@ -0,0 +1,66 @@ | |||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
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.
Focus tests validate the focus function works and the focus lands on the menu trigger after the menu is closed. The unit tests do not allow for some more complex checks such as focus delegation after an item is removed or becomes disabled - these transitions are covered with the integ tests.
@@ -0,0 +1,100 @@ | |||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
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 keyboard tests validate navigation and Escape that are handled explicitly. The keyboard tests do not include pressing buttons with Enter because that is the browser behaviour (the buttons do not define any onKeyDown handler, only the onClick). The behaviour is tested with integ tests instead.
@@ -1,274 +0,0 @@ | |||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
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.
All tests from this file are copied or re-implemented, no test scenario was excluded.
|
||
import testUtilStyles from './test-classes/styles.css.js'; | ||
|
||
const IconToggleButtonItem = forwardRef( |
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 component is very similar to the existing IconButtonItem, see: https://github.com/cloudscape-design/components/blob/main/src/button-group/icon-button-item.tsx
@@ -26,7 +26,7 @@ const MenuDropdownItem = React.forwardRef( | |||
) => { | |||
const containerRef = React.useRef<HTMLDivElement>(null); | |||
const onClickHandler = (event: CustomEvent<ButtonDropdownProps.ItemClickDetails>) => { | |||
fireCancelableEvent(onItemClick, { id: event.detail.id }, event); | |||
fireCancelableEvent(onItemClick, { id: event.detail.id, checked: event.detail.checked }, event); |
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.
Adding this to support selectable button dropdown items: https://cloudscape.design/components/button-dropdown?tabId=playground&example=with-selectable-items
@@ -27,7 +27,7 @@ export const InternalToggleButton = React.forwardRef( | |||
onChange, | |||
className, | |||
...rest | |||
}: ToggleButtonProps, | |||
}: ToggleButtonProps & { __title?: string }, |
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 is needed to hide the HTML title of the button when it is used in the button group. That is because the title is not needed when the tooltip is present.
35cf88e
to
4f5350d
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.
Good job! Just left a couple of minor comments on your discretion
expect(wrapper.findToggleButtonById('copy')!.getElement()).toHaveAttribute('aria-disabled', 'true'); | ||
expect(wrapper.findMenuById('menu')!.findTriggerButton()!.getElement()).toHaveAttribute('aria-disabled', 'true'); | ||
|
||
await waitFor(() => expect(document.body).toHaveTextContent('Loading Like')); |
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.
I'm curious why this expectation checks the body content, not live regions' ?
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.
That is because the new live region implementation: https://github.com/cloudscape-design/components/blob/main/src/live-region/controller.ts#L37
trackRef={containerRef} | ||
trackKey={item.id} | ||
value={ | ||
(showFeedback && <InternalLiveRegion tagName="span">{feedbackContent}</InternalLiveRegion>) || |
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.
All other components with a tooltip (but for disabled reason) use aria-describedby
with a hidden element with the description, like in the button component https://github.com/cloudscape-design/components/blob/main/src/button/internal.tsx#L127
Should it be adopted here same way?
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.
Great question!
The popover feedback is supposed to work the same as popover component: https://github.com/cloudscape-design/components/blob/main/src/popover/internal.tsx#L149
Ideally we should use the popover here but that causes a blink when the tooltips gets replaced with a popover.
4f5350d
to
4ffe835
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.
Why we don't have pressedText
for toggle buttons anymore?
Description
The PR adds support for toggle buttons to the button group component.
Depends on:
Rel: [IEbDAJOcw4NY], [a1MAAZpYYH9h]
How has this been tested?
Review checklist
The following items are to be evaluated by the author(s) and the reviewer(s).
Correctness
CONTRIBUTING.md
.CONTRIBUTING.md
.Security
checkSafeUrl
function.Testing
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.