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

[terra-form-select] Fixed focus issue in MultiSelect #4089

Merged
merged 13 commits into from
Apr 29, 2024

Conversation

adavijit
Copy link
Collaborator

@adavijit adavijit commented Apr 17, 2024

Summary

What was changed:

  • Added aria-label attribute in Tag component
  • Modified role attribute logic depending on the isInputFocused prop.
  • Consumed inputRef as callback in MultiSelect component and passed down to Tag component.
  • Consumed disabled and isInputFocused props in Tag component
  • Added test for testing disabled MultiSelect component
  • Updated wdio tests
  • Updated translations files

Why it was changed:
Keyboard TAB focus also not moving to the added list of options. The User is not able to access the previous selected options that appears above the multi-select field.

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-10191


Thank you for contributing to Terra.
@cerner/terra

@SwethaM03
Copy link

+1
Keyboard focus behaviour of multi-select is working as expected. However there are some screen reader issues still existing.

event.stopPropagation();
onDeselect(value);
const previousLi = tagRef.current.previousElementSibling;
const selectInput = tagRef.current.closest('ul').parentElement.parentElement.children[1].children[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

This way of accessing input control might result in unexpected failure when dom changes are made to component. I would suggest you to create a callback ref for input to set focus.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have now used inputRef from a callback to set focus on the input element.

const previousLi = tagRef.current.previousElementSibling;
const selectInput = tagRef.current.closest('ul').parentElement.parentElement.children[1].children[0];
if (previousLi) {
const deselectElement = previousLi.children[1];
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 the index being hard-coded to 1 here ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have removed the hard coded index. focused input element using inputRef.

@@ -2376,6 +2376,17 @@ Terra.describeViewports('Select', ['tiny'], () => {
it('should display selected option', () => {
Terra.validates.element('tag controlled selected option');
});

it('should focus on pressing tab key', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this test validates disabled tag navigations as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@supreethmr I have added tests to validate disabled tag navigations

@@ -65,7 +65,7 @@ Terra.describeViewports('Alert', ['tiny', 'large'], () => {
it('alert content is focused when rendered with an action element', () => {
browser.url('/raw/tests/cerner-terra-core-docs/alert/custom-prop-alert');

browser.keys(['Tab', 'Tab', 'Tab', 'Tab', 'Enter']);
browser.keys(['Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Enter']);
Copy link
Contributor

Choose a reason for hiding this comment

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

why are the additional tab key is required to bring focus to alert content..?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@supreethmr Earlier pressing tab key was not focusing inside the input field, that is the deselect option. Now since there are two options in the list, to get out side of the input box we need to press tab two more times

@github-actions github-actions bot temporarily deployed to preview-pr-4089 April 23, 2024 06:20 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-4089 April 23, 2024 06:24 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-4089 April 23, 2024 06:30 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-4089 April 24, 2024 11:20 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-4089 April 24, 2024 11:25 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-4089 April 24, 2024 11:58 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-4089 April 24, 2024 13:12 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-4089 April 24, 2024 13:31 Destroyed
@adavijit
Copy link
Collaborator Author

+1 Keyboard focus behaviour of multi-select is working as expected. However there are some screen reader issues still existing.

@SwethaM03 , Screen Reader issue is now fixed with this PR

@adavijit adavijit requested a review from supreethmr April 24, 2024 13:48
@github-actions github-actions bot temporarily deployed to preview-pr-4089 April 24, 2024 14:08 Destroyed
@adavijit adavijit requested a review from supreethmr April 24, 2024 14:14
@github-actions github-actions bot temporarily deployed to preview-pr-4089 April 24, 2024 20:23 Destroyed
@supreethmr
Copy link
Contributor

There is a Axe Violation on disabled multi-select I think this will be same for other variants of select also.
disabled frame does not get any value for role attribute :

return disabled ? undefined : 'application';

Hence it's resulting in below axe voilation. It would be better to remove the aria-expanded attribute for the disabled frame since it has no role. OR we can add role back but it looks like `role='application' is not consistent with screen readers for disabled elements.

Screenshot 2024-04-25 at 3 39 40 PM

Copy link
Contributor

@supreethmr supreethmr left a comment

Choose a reason for hiding this comment

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

+1 with axe error fix

@adavijit
Copy link
Collaborator Author

There is a Axe Violation on disabled multi-select I think this will be same for other variants of select also. disabled frame does not get any value for role attribute :

return disabled ? undefined : 'application';

Hence it's resulting in below axe voilation. It would be better to remove the aria-expanded attribute for the disabled frame since it has no role. OR we can add role back but it looks like `role='application' is not consistent with screen readers for disabled elements.

@supreethmr Since this is not related to this PR, logged a new JIRA here.
UXPLATFORM-10391

@rbsree
Copy link

rbsree commented Apr 25, 2024

+1, both keyboard and screen reader focus is managed as expected. And the focus is also managed when options are deselected.

@sugan2416 sugan2416 force-pushed the UXPLATFORM-10191_multiselect branch from f53740a to a551809 Compare April 29, 2024 05:17
@github-actions github-actions bot temporarily deployed to preview-pr-4089 April 29, 2024 05:17 Destroyed
@sugan2416 sugan2416 added ⭐ Accessibility Reviewed Accessibility has been reviewed and approved. and removed Accessibility Review Required labels Apr 29, 2024
@sugan2416 sugan2416 merged commit 5d2f4a7 into main Apr 29, 2024
22 checks passed
@sugan2416 sugan2416 deleted the UXPLATFORM-10191_multiselect branch April 29, 2024 07:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📦 terra-form-select ⭐ Accessibility Reviewed Accessibility has been reviewed and approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants