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

[terra-folder-tree] Add isSelectable prop #2021

Merged
merged 33 commits into from
Feb 22, 2024
Merged

Conversation

sycombs
Copy link
Contributor

@sycombs sycombs commented Feb 7, 2024

Summary

This PR adds an isSelectable prop to FolderTreeItem so that consumers can define whether or not an item can be selected.

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


Thank you for contributing to Terra.
@cerner/terra

/**
* Indicates whether the item is selected. Because this component has the appearance of a radio button group, only one item should be selected at a time.
*/
isSelected: PropTypes.bool,
/**
* The callback function for a click event.
*/
onClick: PropTypes.func,
onSelect: PropTypes.func,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed this prop from onClick to onSelect to better reflect its actual intended usage. If there are concerns about passivity this can be reverted.

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 passivity concern would be if MPages is already using this callback. If they have coded to use onClick, this minor version update would break them, correct?

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, this will break consumers who are already using onClick.

Copy link
Contributor

Choose a reason for hiding this comment

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

The component is still in alpha, so I think we can get away with making a non-passive change. The prop rename makes sense to me. I would just add a "breaking change" entry in the CHANGELOG.

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 point, added the breaking change entry here: 7555293

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

{/* eslint-disable-next-line react/forbid-dom-props */}
<span style={{ paddingLeft: `${level}rem` }}>
<span style={{ paddingLeft: `${level * 14}px` }}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we multiplying the level by 14? Also, is there a reason to remove rem? If you are trying to convert rem to px, this is not the correct way to convert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

14px is the correct value as specified by UX, the original value was incorrect.

className={cx('radio')}
/>
) : (
<div className={cx('radio-container')} />
Copy link
Contributor

Choose a reason for hiding this comment

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

A div is a block element. Do you want an actual div? Can we not just add the necessary padding or margin to the sibling element?

Comment on lines 48 to 52
.radio-container {
height: 14px;
margin: 17px;
width: 14px;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you created a new class that duplicates the styles of the radio class. Maybe you could give a meaningful name so that you can have a single class.

@@ -169,23 +196,16 @@ const FolderTreeItem = ({
className={itemClassNames}
role="treeitem"
aria-expanded={isFolder ? isExpanded : null}
aria-selected={isSelected}
onClick={isFolder ? handleToggle : onClick}
aria-selected={isSelectable ? isSelected : null}
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to just use the isSelected value, right?

Copy link
Contributor Author

@sycombs sycombs Feb 7, 2024

Choose a reason for hiding this comment

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

According to the mdn docs, the states for aria-selected are true (the element is selectable and selected), false (the element is selectable and unselected), and undefined (the element is not selectable). I'd like to avoid setting aria-selected={false} on elements that are not selectable (although it does seem to behave correctly in Voiceover at least) since it implies that the element is selectable.

@sycombs sycombs marked this pull request as ready for review February 8, 2024 14:45
@sycombs sycombs self-assigned this Feb 8, 2024
@github-actions github-actions bot temporarily deployed to preview-pr-2021 February 21, 2024 22:49 Destroyed
@chrismichalewicz
Copy link

@sycombs I have reviewed for a11y and it sounds good, great work! I have updated the a11y label.

Tested on a PC with Microsoft Edge Version 121.0.2277.128, JAWS 2022 version 2022.2202.38

  • JAWS communicated if an item is selectable and instructions for how to select it (Enter)
  • Pressing Enter selects an item
  • All other keyboard navigation continued to work as expected.

@sycombs sycombs merged commit 90c66d6 into main Feb 22, 2024
22 checks passed
@sycombs sycombs deleted the folder-tree_selectable branch February 22, 2024 19:01
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