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

Cell auto focus property #2123

Merged
merged 4 commits into from
Apr 8, 2024
Merged

Cell auto focus property #2123

merged 4 commits into from
Apr 8, 2024

Conversation

cm9361
Copy link
Contributor

@cm9361 cm9361 commented Apr 4, 2024

Summary

What was changed:
The isAutoFocusEnabled property was introduced to control whether cell with a single focusable element that is a button or hyperlink gets focus automatically during cell navigation.

Why it was changed:

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


Thank you for contributing to Terra.
@cerner/terra

Copy link
Contributor

@sdadn sdadn left a comment

Choose a reason for hiding this comment

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

We may need to update these wdio tests to account for the new prop.

it('clicks the button instead of diving in if it is the only component in the cell', () => {
const modal = browser.$('[aria-modal="true"]');
expect(modal.isDisplayed()).toBe(false);
browser.keys(['Tab', 'Tab', 'ArrowDown', 'ArrowRight', 'Enter']);
expect(modal.isDisplayed()).toBe(true);
expect(browser.$('/html/body/div[2]/div[2]/div/div/div/div[4]/div/button').isFocused()).toBe(true);
});
it('focuses on a hyperlink if it is the only component in a cell', () => {
browser.keys(['Tab', 'Tab', 'ArrowDown', 'ArrowRight', 'ArrowRight', 'ArrowRight']);
expect(browser.$('//*[@id="default-terra-data-grid-focusable-cell-table"]/tbody[2]/tr[1]/td[3]/div/a').isFocused()).toBe(true);
});

/**
* Determines if focus is moved to the interactive element of a cell when a single button or hyperlink element is the only interactive element.
*/
isAutoFocusEnabled: PropTypes.bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

would enableAutofocus make sense as a simpler name?

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 tried to follow the naming pattern of some of the other props. However, I can make this change if it is the desired update.

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 the is___ pattern is preferred. Would a name like isAutofocusable or similar work? (Not sure if that's sufficiently descriptive of the prop's usage though)

Copy link
Contributor

Choose a reason for hiding this comment

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

If we're keeping to the is__ pattern, then I think both these names are similar enough that either works.

@@ -282,7 +289,7 @@ const DataGrid = forwardRef((props, ref) => {

// Set focus to a single header button or hyperlink if they are the only content in cell
const cellButtonOrHyperlink = focusedCell.querySelector('a, button');
if ((isHeaderRow && !focusedCell.hasAttribute('tabindex')) || cellButtonOrHyperlink) {
if ((isHeaderRow && !focusedCell.hasAttribute('tabindex')) || (isAutoFocusEnabled && cellButtonOrHyperlink)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

will action buttons on header cells still be autofocused, regardless of the prop?

Copy link
Contributor Author

@cm9361 cm9361 Apr 5, 2024

Choose a reason for hiding this comment

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

The first half of the condition is for the header row and all unit tests pass. I will manually confirm though.

Yes, the button in the row header is still being selected.

@cm9361
Copy link
Contributor Author

cm9361 commented Apr 5, 2024

We may need to update these wdio tests to account for the new prop.

it('clicks the button instead of diving in if it is the only component in the cell', () => {
const modal = browser.$('[aria-modal="true"]');
expect(modal.isDisplayed()).toBe(false);
browser.keys(['Tab', 'Tab', 'ArrowDown', 'ArrowRight', 'Enter']);
expect(modal.isDisplayed()).toBe(true);
expect(browser.$('/html/body/div[2]/div[2]/div/div/div/div[4]/div/button').isFocused()).toBe(true);
});
it('focuses on a hyperlink if it is the only component in a cell', () => {
browser.keys(['Tab', 'Tab', 'ArrowDown', 'ArrowRight', 'ArrowRight', 'ArrowRight']);
expect(browser.$('//*[@id="default-terra-data-grid-focusable-cell-table"]/tbody[2]/tr[1]/td[3]/div/a').isFocused()).toBe(true);
});

I already made this update in the test file to account for the new prop.

rowHeaderIndex={rowHeaderIndex}
rowHeight="50px"
ariaLabel="Worklist Data Grid"
/>
Copy link
Contributor

@adoroshk adoroshk Apr 5, 2024

Choose a reason for hiding this comment

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

It looks like this example is missing isAutoFocusEnabled prop

@adoroshk
Copy link
Contributor

adoroshk commented Apr 5, 2024

Is there an example where the action button autofocus can be tested with isAutoFocusEnabled prop set to false? I am not sure where to test this combination.

UPD: I locally updated an example with actions with isAutoFocusEnabled={false} and verified that it worked, so the functionality is good. However, it would be nice to have a test to ensure that autofocus on action works in both cases - with isAutoFocusEnabled true and false.

@github-actions github-actions bot temporarily deployed to preview-pr-2123 April 5, 2024 20:12 Destroyed
@mjpalazzo
Copy link
Contributor

@cm9361 - I tested 2 examples Worklist Data Grid Autofocusable Cell and Worklist Data Grid Focusable Cell. Keyboard navigation is working as required in both. JAWS announcements are working as required in both.

@cm9361 cm9361 merged commit b7d65f7 into main Apr 8, 2024
22 checks passed
@cm9361 cm9361 deleted the cell-auto-focus branch April 8, 2024 12:51
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.

5 participants