Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

[terra-button-group] Updated tabIndex on button group for single select example #4022

Merged
merged 9 commits into from
Feb 15, 2024

Conversation

KV106606Viswanath
Copy link
Contributor

@KV106606Viswanath KV106606Viswanath commented Feb 6, 2024

Summary

Previously, we are unable to tab (using tab key) between buttons on the button group in single select example. With this fix it has been resolved and we can move focus to the button even it is not selected on single select example.

What was changed:
Updated tabIndex on button group for single select example.

Why it was changed:
User unable to tab between buttons on button group.

Testing

This change was tested using:

  • WDIO
  • Jest
  • Visual testing (please attach a screenshot or recording)
  • Other (please describe below)
  • No tests are needed

Reviews

In addition to engineering reviews, this PR needs:

  • UX review
  • Accessibility review
  • Functional review

Additional Details

This PR resolves:

UXPLATFORM-10171


Thank you for contributing to Terra.
@cerner/terra

@saket2403
Copy link
Contributor

Keyboard navigation for single select buttons should be similar to radio button fields ie: Tab should put focus on the first button and subsequent tabbbing should move the focus out of the group to the next focusable element. Only arrow keys should work inside the group for single select buttons.Removing the entire tabIndex logic means that functioanlity is breaking.

@KV106606Viswanath KV106606Viswanath changed the title [terra-button-group] Removed tabIndex on button group for single select example [terra-button-group] Updated tabIndex on button group for single select example Feb 8, 2024
@KV106606Viswanath
Copy link
Contributor Author

Keyboard navigation for single select buttons should be similar to radio button fields ie: Tab should put focus on the first button and subsequent tabbbing should move the focus out of the group to the next focusable element. Only arrow keys should work inside the group for single select buttons.Removing the entire tabIndex logic means that functioanlity is breaking.

Updated.

@saket2403
Copy link
Contributor

Focus should come onto the selected item (when present) initially but as per these changes, it will always come onto the first button.

@KV106606Viswanath
Copy link
Contributor Author

Focus should come onto the selected item (when present) initially but as per these changes, it will always come onto the first button.

Updated

@@ -170,7 +170,10 @@ class ButtonGroup extends React.Component {

React.Children.forEach(children, (child, index) => {
const isSelected = selectedKeys.indexOf(child.key) > -1;
const tabAttr = (this.props.onChange && !isMultiSelect) ? { tabIndex: (isSelected) ? '0' : '-1' } : null;
// Checking whehter any option is selected or not
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
// Checking whehter any option is selected or not
// Checking whether any option is selected or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@@ -170,7 +170,10 @@ class ButtonGroup extends React.Component {

React.Children.forEach(children, (child, index) => {
const isSelected = selectedKeys.indexOf(child.key) > -1;
const tabAttr = (this.props.onChange && !isMultiSelect) ? { tabIndex: (isSelected) ? '0' : '-1' } : null;
// Checking whehter any option is selected or not
const isAnyOptionSelected = children && Array.isArray(children) ? children.findIndex((e) => this.props.selectedKeys.includes(e?.key)) : -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const isAnyOptionSelected = children && Array.isArray(children) ? children.findIndex((e) => this.props.selectedKeys.includes(e?.key)) : -1;
const isAnyOptionSelected = children && Array.isArray(children) ? children.findIndex((child) => this.props.selectedKeys.includes(child?.key)) : -1;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@saket2403
Copy link
Contributor

Please add a wdio test to verify that focus moves to the first button when no buttons are selected initially in a single select button group.

@KV106606Viswanath
Copy link
Contributor Author

Please add a wdio test to verify that focus moves to the first button when no buttons are selected initially in a single select button group.

Added.

@@ -170,7 +170,11 @@ class ButtonGroup extends React.Component {

React.Children.forEach(children, (child, index) => {
const isSelected = selectedKeys.indexOf(child.key) > -1;
const tabAttr = (this.props.onChange && !isMultiSelect) ? { tabIndex: (isSelected) ? '0' : '-1' } : null;
// Checking whether any option is selected or not
// eslint-disable-next-line no-shadow
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this eslint rule disabled?

@@ -2,6 +2,9 @@

## Unreleased

* Removed
* Removed `tabAttr` variable to fix tabbing issue on the button group.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Removed `tabAttr` variable to fix tabbing issue on the button group.
* Fixed
* Fixed tabbing issue for button-group without initial focus.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@@ -3,6 +3,7 @@
## Unreleased

* Added
* Added a test example to validate focus when none of the buttons are selected.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Added a test example to validate focus when none of the buttons are selected.
* Added a test example for `terra-button-group` to validate focus when none of the buttons are selected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@github-actions github-actions bot temporarily deployed to preview-pr-4022 February 14, 2024 11:00 Destroyed
@rahulkumar8cs
Copy link

+1

@sugan2416 sugan2416 added ⭐ Accessibility Reviewed Accessibility has been reviewed and approved. and removed Accessibility Review Required labels Feb 15, 2024
@sugan2416 sugan2416 merged commit b1209d0 into main Feb 15, 2024
22 checks passed
@sugan2416 sugan2416 deleted the KV106606-terra-button-group-tabbing-issue branch February 15, 2024 06:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📦 terra-button-group ⭐ Accessibility Reviewed Accessibility has been reviewed and approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants