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

[terra-data-grid] Update to automatically focus on single buttons or hyperlinks in cells #2066

Merged
merged 45 commits into from
Mar 14, 2024

Conversation

sdadn
Copy link
Contributor

@sdadn sdadn commented Mar 5, 2024

Summary

This PR updates the focus behavior to negate the need for dive-in mode in cells with only a single button or hyperlink and focus on them directly.

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


Thank you for contributing to Terra.
@cerner/terra

@sdadn sdadn self-assigned this Mar 5, 2024
@github-actions github-actions bot temporarily deployed to preview-pr-2066 March 5, 2024 17:30 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2066 March 5, 2024 19:16 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2066 March 5, 2024 21:13 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2066 March 5, 2024 21:49 Destroyed
@sdadn sdadn marked this pull request as ready for review March 5, 2024 21:50
@github-actions github-actions bot temporarily deployed to preview-pr-2066 March 5, 2024 22:08 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2066 March 5, 2024 22:56 Destroyed
@sdadn sdadn changed the title [wip] Update cell focus to automatically on single buttons or hyperlinks [terra-data-grid] Update cell focus to automatically on single buttons or hyperlinks Mar 5, 2024
// This will be removed is a separate refactor effort.

const getFocusableButtonsOrHyperlinks = (parentElement) => {
const focusableElementSelector = 'a[href]:not([tabindex=\'-1\']), button:not([disabled]):not([tabindex=\'-1\'])';
Copy link
Contributor

@adoroshk adoroshk Mar 6, 2024

Choose a reason for hiding this comment

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

I am wondering if we need to include buttons that are created like <div> tags with a role="button", or that is out of scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe custom elements are out of scope for this feature.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you would actually have to account for this. You might need to exclude certain types rather than being so specific. This selector seems too restrictive.

@sdadn sdadn changed the title [terra-data-grid] Update cell focus to automatically on single buttons or hyperlinks [terra-data-grid] Update to automatically focus on single buttons or hyperlinks in cells Mar 6, 2024
@@ -280,6 +264,26 @@ Terra.describeViewports('DataGrid', ['medium', 'large'], () => {
Terra.validates.element('data-grid-focusable-select-retains-focus', { columnResizeSelector });
expect(browser.$('#specialties').isFocused()).toBe(true);
});

it('focuses on a button if it is the only component in a cell', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have a test with more than one focusable component in a cell?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that should be covered here:

it('validates that a cell with multiple focusable elements traps focus', () => {
browser.keys(['Tab', 'Tab', 'ArrowDown', 'ArrowDown', 'ArrowRight', 'Enter', 'ArrowRight']);
Terra.validates.element('focusable-multiple-element-cell-trap-focus', { columnResizeSelector });
expect(browser.$$('button:focus')).toBeElementsArrayOfSize(1);
});

Comment on lines 230 to 236
const handleFocus = () => {
const element = hasSingleButtonOrHyperlinkElement();

if (element) {
element.focus();
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this correct? We don't want this behavior for the Terra Table. This functionality should only be possible for a DataGrid component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved this to the data grid component.

@@ -213,7 +227,15 @@ function Cell(props) {
}
}, [isGridContext]);

const onMouseDown = (event) => {
const handleFocus = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want to add this logic to the onFocus synthetic event.

…/WorklistDataGrid.1/Examples.3/WorklistDataGridFocusableCell.doc.mdx

Co-authored-by: Nikhita Sharma <[email protected]>
@github-actions github-actions bot temporarily deployed to preview-pr-2066 March 6, 2024 18:03 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2066 March 13, 2024 14:50 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2066 March 13, 2024 15:09 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2066 March 13, 2024 15:55 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2066 March 13, 2024 16:00 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2066 March 14, 2024 07:09 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2066 March 14, 2024 11:11 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2066 March 14, 2024 14:00 Destroyed
@sdadn
Copy link
Contributor Author

sdadn commented Mar 14, 2024

The WDIO failure is caused by an another component. Terra-data-grid tests are all passing:

CleanShot 2024-03-14 at 09 27 36

CleanShot 2024-03-14 at 09 27 00

CleanShot 2024-03-14 at 09 27 14

@github-actions github-actions bot temporarily deployed to preview-pr-2066 March 14, 2024 17:19 Destroyed
@mjpalazzo
Copy link
Contributor

@sdadn - Overall this enhancement is working well. I have a couple of minor findings.

  1. When focus is on the hyperlink, the black solid line focus indicator is cut off on the left side. See attached screen shots. Focus indicator on button and cells look fine. See screenshots for these as well.
  2. This is a nit but the column header text in the example is incorrect. For example the header that has "Column 1" in the header is actually column 2. This causes the screen reader to announce "Column 1" some helper text and then "Column 2"

WDG interactive cell 3 focus issue WDG interactive cell 2 WDG interactive cell 1

@sdadn and I met to discuss visual focus indicator truncation when the interactive element has focus. This issue is in Main and I recall that there may be issues opened by the Clinicals teams that caused us to reduce cell padding. I will follow up on that and open a new Jira to address the issue. I have added the Accessibility Reviewed label.

@sdadn sdadn merged commit 26527ef into main Mar 14, 2024
22 checks passed
@sdadn sdadn deleted the update-cell-focus branch March 14, 2024 18:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants