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

[terra-table] Added navigation via Home and End Keys #1887

Merged
merged 9 commits into from
Nov 15, 2023
Merged

Conversation

cm9361
Copy link
Contributor

@cm9361 cm9361 commented Nov 13, 2023

Summary

What was changed:
The Terra Table was updated to allow users to navigate to the first or last focusable element in the table via the home and end keys, respectively.

Why it was changed:
The change was made to improve accessibility as well as the user experience for keyboard users. If a table contained a large set of focusable elements, users previously had to tab through each individual element.

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

N/A

This PR resolves:

UXPLATFORM-9784


Thank you for contributing to Terra.
@cerner/terra

@cm9361 cm9361 marked this pull request as ready for review November 13, 2023 18:01
Copy link
Contributor

@kenk2 kenk2 left a comment

Choose a reason for hiding this comment

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

Mostly nits and some questions, otherwise LGTM.

Comment on lines +503 to +504
if (event.keyCode !== KeyCode.KEY_TAB
&& (isTextInput(targetElement)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: In other places where we do onKeyDown we use switch statements. I think doing that here would make it clear that we're watching for keycode events and doing an action accordingly.

Also it seems that we're doing something pretty similar to what's being done in focusManagement.js. Maybe we can put this query search in that file too and then us that as a util here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have very similar code in the data-grid package. I think it is ok to keep this pattern.

@@ -8,6 +8,29 @@ import GridContext, { GridConstants } from '../../src/utils/GridContext';
import Cell from '../../src/subcomponents/Cell';
import ColumnContext from '../../src/utils/ColumnContext';

const originalOffsetHeight = Object.getOwnPropertyDescriptor(
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question: What is the purpose of doing this bit from 11 to 33? What's being changed or needed to change here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is required so that the elements will have an offsetWidth and offsetHeight in Jest. Without this logic, the values will be 0 and the tests will fail.

* @param {HTMLElement} element - The element to check if it is a text input
* @returns True if the element is a text input. Otherwise, false.
*/
const isTextInput = (element) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Since we now have focusManagement.js that's doing queries similar to this, should we move this function in that file as well?

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 just didn't move it because it is currently only used in this one location. We can always move it if the function needs to be shared by multiple files.

Copy link
Contributor

@adoroshk adoroshk left a comment

Choose a reason for hiding this comment

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

Tested locally, works as expected.
Screenshot 2023-11-13 at 5 44 15 PM
Screenshot 2023-11-13 at 5 44 23 PM

@eawww
Copy link
Contributor

eawww commented Nov 14, 2023

Needs to be mentioned in the docs somewhere. Possibly under "Component Features". @sdadn @sycombs @chrismichalewicz thoughts?

@github-actions github-actions bot temporarily deployed to preview-pr-1887 November 15, 2023 14:13 Destroyed
@eawww eawww added ⭐ UX Reviewed UX Reviewed and approved. and removed UX Review Required labels Nov 15, 2023
@cm9361 cm9361 merged commit 464dfb3 into main Nov 15, 2023
21 checks passed
@cm9361 cm9361 deleted the table-home-end branch November 15, 2023 15:58
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