-
Notifications
You must be signed in to change notification settings - Fork 72
[terra-data-grid] Update to automatically focus on single buttons or hyperlinks in cells #2066
Conversation
// 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\'])'; |
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 am wondering if we need to include buttons that are created like <div>
tags with a role="button"
, or that is out of scope?
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 believe custom elements are out of scope for this feature.
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 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.
...a-dev-site/doc/data-grid/WorklistDataGrid.1/Examples.3/WorklistDataGridFocusableCell.doc.mdx
Outdated
Show resolved
Hide resolved
@@ -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', () => { |
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.
Should we have a test with more than one focusable component in a cell?
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 think that should be covered here:
terra-framework/packages/terra-data-grid/tests/wdio/data-grid-spec.js
Lines 234 to 239 in b4b9f88
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); | |
}); |
const handleFocus = () => { | ||
const element = hasSingleButtonOrHyperlinkElement(); | ||
|
||
if (element) { | ||
element.focus(); | ||
} | ||
}; |
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.
Is this correct? We don't want this behavior for the Terra Table. This functionality should only be possible for a DataGrid component.
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.
Moved this to the data grid component.
@@ -213,7 +227,15 @@ function Cell(props) { | |||
} | |||
}, [isGridContext]); | |||
|
|||
const onMouseDown = (event) => { | |||
const handleFocus = () => { |
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 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]>
… into update-cell-focus
@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. |
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:
Reviews
In addition to engineering reviews, this PR needs:
Additional Details
This PR resolves:
UXPLATFORM-10225
Thank you for contributing to Terra.
@cerner/terra