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

[terra-folder-tree] Update cursor style for interactable regions #1937

Merged
merged 4 commits into from
Dec 7, 2023

Conversation

sycombs
Copy link
Contributor

@sycombs sycombs commented Dec 7, 2023

Summary

This change updates the cursor style for folder tree rows to be a pointer so that there is a visual cue that the regions are clickable. This also updates the selection behavior so that folder rows can only be selected by the radio button and clicking anywhere else on the row will toggle expand/collapse, and non-folder rows can be selected by clicking anywhere in the row.

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


Thank you for contributing to Terra.
@cerner/terra

@sycombs sycombs requested a review from a team December 7, 2023 17:12
@sycombs sycombs self-assigned this Dec 7, 2023
// Stop click propagation to prevent triggering expand/collapse when selecting folders
event.stopPropagation();

onClick();
Copy link
Contributor

Choose a reason for hiding this comment

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

Since onClick is not required, we either need to check here or when the event handler is defined to prevent an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, deebcdc

onClick={onToggle}
onKeyDown={onToggle}
onClick={isFolder ? onToggle : onClick}
onKeyDown={isFolder ? onToggle : onClick}
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't there a specific key or keys that should trigger this action? I would not expect this to happen for any key pressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I took a look at the keyboard Jira (UXPLATFORM-9776) and expand/collapse should be triggered by the right and left arrows and selection should be triggered via the enter key. I went ahead and removed the onKeyDown handler and disabled the eslint error for now, these should be re-enabled as part of the keyboard interaction story.
ccdc63e

Comment on lines 125 to 126
onChange={onClick}
onClick={handleRadioButtonClick}
Copy link
Contributor

Choose a reason for hiding this comment

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

What would be the difference between onChange and onClick? Do we need both event handlers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The onChange handler was originally used instead of onClick to resolve this React failed proptype warning. Unfortunately, stopPropagation will not prevent the row click event if the radio button uses onChange since they are different event types, so I had to use an onClick instead.

An alternative to addressing the React warning would be to set readOnly on the radio, but that seems incorrect to me as well since it's not really a readonly element, so I've left it as onChange for now, but I'm open to other solutions if we don't want to have an extra event handler here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am assuming the row click is getting the event due to bubbling. If that is the case, can't you just check if the event target is the radio button in the handler. If so, you could return instead of executing the logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, and that's much nicer, updated: 460c1f2

Copy link
Contributor

@eawww eawww left a comment

Choose a reason for hiding this comment

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

Just to document but out of scope for this story:
There's one example where we get the pointer cursor on an item that can't be selected or expanded, but this is an issue with the example. When consumed properly, all items would be interactable so pointer cursor everywhere is fine.

@github-actions github-actions bot temporarily deployed to preview-pr-1937 December 7, 2023 21:34 Destroyed
@sycombs sycombs merged commit 1d4b87c into main Dec 7, 2023
22 checks passed
@sycombs sycombs deleted the folder-tree_fix-cursor-style branch December 7, 2023 22:18
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.

4 participants