Skip to content
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

Merged
merged 2 commits into from
Nov 12, 2024

Conversation

pan-kot
Copy link
Member

@pan-kot pan-kot commented Oct 21, 2024

Description

The PR adds support for toggle buttons to the button group component.

Depends on:

Rel: [IEbDAJOcw4NY], [a1MAAZpYYH9h]

How has this been tested?

  • New unit tests
  • New permutations and screenshot tests
Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link

codecov bot commented Oct 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.30%. Comparing base (672e7f8) to head (7d26fd4).
Report is 8 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

{
"name": "id",
"optional": false,
"type": "string",
},
{
"name": "pressed",
Copy link
Member Author

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",
Copy link
Member Author

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.
Copy link
Member Author

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.
Copy link
Member Author

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.
Copy link
Member Author

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.
Copy link
Member Author

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(
Copy link
Member Author

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);
Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -27,7 +27,7 @@ export const InternalToggleButton = React.forwardRef(
onChange,
className,
...rest
}: ToggleButtonProps,
}: ToggleButtonProps & { __title?: string },
Copy link
Member Author

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.

@pan-kot pan-kot marked this pull request as ready for review November 1, 2024 13:46
@pan-kot pan-kot requested a review from a team as a code owner November 1, 2024 13:46
georgylobko
georgylobko previously approved these changes Nov 1, 2024
Copy link
Contributor

@georgylobko georgylobko left a 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'));
Copy link
Contributor

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' ?

Copy link
Member Author

Choose a reason for hiding this comment

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

trackRef={containerRef}
trackKey={item.id}
value={
(showFeedback && <InternalLiveRegion tagName="span">{feedbackContent}</InternalLiveRegion>) ||
Copy link
Contributor

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?

Copy link
Member Author

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.

georgylobko
georgylobko previously approved these changes Nov 8, 2024
Copy link
Contributor

@georgylobko georgylobko left a 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?

@pan-kot pan-kot added this pull request to the merge queue Nov 12, 2024
Merged via the queue into main with commit 0763b43 Nov 12, 2024
38 checks passed
@pan-kot pan-kot deleted the feat-button-group-toggle-buttons branch November 12, 2024 19:44
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.

2 participants