Skip to content

Conversation

aloysb
Copy link
Contributor

@aloysb aloysb commented Jul 12, 2023

Closes #3578

This PR simply add the ability to expose a data-attribute on the <HiddenElement /> of useSelect.

This is useful when using a tool such as AXE or pa11y giving you false positive - the data attribute is a good way to force the tool to ignore the false positive.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

  1. Use the following code (from the useSelect documentation example), ensuring that the props contains {hasA11yIgnoreDataAttr: true}
  2. Ensure that the hidden select element has the data attribute data-rsp-a11y-ignore.
  3. Ensure unit tests are passing (yarn jest)
import {HiddenSelect, useSelect} from '@react-aria/select';
import {Item} from '@react-stately/collections';
import {useSelectState} from '@react-stately/select';

// Reuse the ListBox, Popover, and Button from your component library. See below for details.
import {ListBox, Popover, Button} from 'your-component-library';

function Select(props) {
  // Create state based on the incoming props
  let state = useSelectState(props);

  // Get props for child elements from useSelect
  let ref = React.useRef(null);
  let {
    labelProps,
    triggerProps,
    valueProps,
    menuProps
  } = useSelect(props, state, ref);

  return (
    <div style={{display: 'inline-block'}}>
      <div {...labelProps}>{props.label}</div>
      <HiddenSelect
        isDisabled={props.isDisabled}
        state={state}
        triggerRef={ref}
        label={props.label}
        name={props.name} />
      <Button
        {...triggerProps}
        buttonRef={ref}
        style={{height: 30, fontSize: 14}}>
        <span {...valueProps}>
          {state.selectedItem
            ? state.selectedItem.rendered
            : 'Select an option'
          }
        </span>
        <span
          aria-hidden="true"
          style={{paddingLeft: 5}}></span>
      </Button>
      {state.isOpen &&
        <Popover state={state} triggerRef={ref} placement="bottom start">
          <ListBox
            {...menuProps}
            state={state} />
        </Popover>
      }
    </div>
  );
}

<Select label="Favorite Color">
  <Item>Red</Item>
  <Item>Orange</Item>
  <Item>Yellow</Item>
  <Item>Green</Item>
  <Item>Blue</Item>
  <Item>Purple</Item>
  <Item>Black</Item>
  <Item>White</Item>
  <Item>Lime</Item>
  <Item>Fushsia</Item>
</Select>

🧢 Your Project:

N/A

Aloys Berger added 2 commits July 11, 2023 05:48
This allows to use the data attribute as a reference for other tools to ignore a11y issues.
This solves adobe#3578
Some tools such as AXE or pa11y might give false positive on hidden select.
This add a new prop to expose a data-attribute (dataset) that can be used to ignore these false positives.
@aloysb aloysb closed this Jul 12, 2023
@aloysb aloysb reopened this Jul 12, 2023
Copy link
Member

@reidbarber reidbarber left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!!

There were a few lint issues that you can see when you run yarn lint. Fixing those should fix the build.

Copy link
Member

@reidbarber reidbarber left a comment

Choose a reason for hiding this comment

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

Also, I think we can just always add the new data attribute, no prop needed to enable.

aloysb and others added 2 commits July 14, 2023 17:07
@aloysb
Copy link
Contributor Author

aloysb commented Jul 14, 2023

@reidbarber I've made the data-attribute always available; there is no harm in doing so.
I agree with you, there is no need to hide it behind a flag.

I've also merged in the latest master, but maybe you prefer it rebased?
Let me know.

Linting issues should be also resolved. (We'll see once the CI has finished!)

This fixes an issue in the docs where the component was being parsed when it shouldn't have been parsed.
@reidbarber
Copy link
Member

GET_BUILD

@rspbot
Copy link

rspbot commented Jul 14, 2023

Copy link
Member

@reidbarber reidbarber left a comment

Choose a reason for hiding this comment

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

Looks great! Just a small tweak to the docs to reflect the updates and I'm good to approve.

@@ -87,7 +87,8 @@ export function useHiddenSelect<T>(props: AriaHiddenSelectProps, state: SelectSt
name,
size: state.collection.size,
value: state.selectedKey ?? '',
onChange: (e: React.ChangeEvent<HTMLSelectElement>) => state.setSelectedKey(e.target.value)
onChange: (e: React.ChangeEvent<HTMLSelectElement>) => state.setSelectedKey(e.target.value),
['data-rsp-a11y-ignore']: true
Copy link
Member

Choose a reason for hiding this comment

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

Think we can get rid of this one too. I figure people can blanket filter out the container div for aXe and pa11y via data-rsp-a11y-ignore (its the one triggering the "ARIA hidden element must not be focusable or contain focusable elements" false positive) and thus we don't need the attribute on the select props. We could even move this line onto the containerProps so people using the hook instead of HiddenSelect benefit too.

Did you find that you needed the data attribute on the select element?

reidbarber
reidbarber previously approved these changes Jul 14, 2023
reidbarber
reidbarber previously approved these changes Jul 14, 2023
LFDanLu
LFDanLu previously approved these changes Jul 15, 2023
Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! I went in and updated it so the data attribute is just on the container props and verified that we could actually use the attribute to suppress the false positive in our own storybook, hope you don't mind. Apologies about highjacking the PR, we wanted to try and get it merged for our testing session on Monday.

Lemme know if you had any thoughts about my comment here, happy to update in a followup if it turns out we need the attribute on more that just the container

@LFDanLu
Copy link
Member

LFDanLu commented Jul 17, 2023

GET_BUILD

Comment on lines +524 to +527
### False positive on `<HiddenSelect />` in accessibility tools

When using &lt;<TypeLink links={docs.links} type={docs.exports.HiddenSelect} />&gt; some accessibility tools such as AXE or pa11y might give a false positive.
The data attribute `data-rsp-a11y-ignore` is included on the hidden select element and can be used to ignore the false positives in these tools.
Copy link
Member

Choose a reason for hiding this comment

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

For the team, open to opinions on where this information should go. Perhaps we should add a new section in this docs page for accessibility gotchas (or simply accessiblity?)

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with where it is, but not against a dedicated accessibility section either.

Copy link
Member

Choose a reason for hiding this comment

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

+1 to Reid's comment. I think this is fine where it is but a new section for accessibility gotchas would be nice

Copy link
Member

Choose a reason for hiding this comment

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

Alright, I'll approve this PR and make a followup one moving it to a separate accessibility section.

Copy link
Member

Choose a reason for hiding this comment

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

It definitely shouldn't be under "Internationalization" IMO, seems unrelated to that. Also we will need to cover this on all of the other select pages: RAC Select and RSP Picker. If it is going to be a general way for us to indicate false positives, we may also want to document it on a more general page such as the "Accessibility" one.

Copy link
Member

Choose a reason for hiding this comment

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

good point about covering this on the other Select pages. By the "Accessibility" page I assume you are referencing this? If so, I think that is a good idea.

@abitbetterthanyesterday IMO this is creeping in scope a bit, would you like to take this on? I'd be perfectly happy making followup PR for this as well instead.

@rspbot
Copy link

rspbot commented Jul 17, 2023

reidbarber
reidbarber previously approved these changes Jul 17, 2023
LFDanLu
LFDanLu previously approved these changes Jul 17, 2023
Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

LGTM, thanks once again for the contribution!

@LFDanLu LFDanLu requested a review from majornista July 17, 2023 23:56
yihuiliao
yihuiliao previously approved these changes Jul 19, 2023
@@ -71,7 +71,8 @@ export function useHiddenSelect<T>(props: AriaHiddenSelectProps, state: SelectSt
return {
containerProps: {
...visuallyHiddenProps,
'aria-hidden': true
'aria-hidden': true,
['data-rsp-a11y-ignore']: true
Copy link
Member

@devongovett devongovett Jul 19, 2023

Choose a reason for hiding this comment

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

This probably should not have rsp in the name because it's not spectrum specific, this will also affect React Aria. Maybe just data-a11y-ignore?

Comment on lines +524 to +527
### False positive on `<HiddenSelect />` in accessibility tools

When using &lt;<TypeLink links={docs.links} type={docs.exports.HiddenSelect} />&gt; some accessibility tools such as AXE or pa11y might give a false positive.
The data attribute `data-rsp-a11y-ignore` is included on the hidden select element and can be used to ignore the false positives in these tools.
Copy link
Member

Choose a reason for hiding this comment

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

It definitely shouldn't be under "Internationalization" IMO, seems unrelated to that. Also we will need to cover this on all of the other select pages: RAC Select and RSP Picker. If it is going to be a general way for us to indicate false positives, we may also want to document it on a more general page such as the "Accessibility" one.

@aloysb
Copy link
Contributor Author

aloysb commented Jul 20, 2023 via email

@LFDanLu LFDanLu dismissed stale reviews from yihuiliao, reidbarber, and themself via d9ed730 July 21, 2023 21:17
@aloysb
Copy link
Contributor Author

aloysb commented Jul 26, 2023

Is there anything left I can do to get this in?
Sorry it has grown out of scope a bit so fell off the wagon 🙂

@LFDanLu
Copy link
Member

LFDanLu commented Jul 26, 2023

I'm hoping to get this reviewed by the team and merged in as is by early next week, then will open a followup PR shortly after addressing the rest of the comments.

Copy link
Member

@reidbarber reidbarber left a comment

Choose a reason for hiding this comment

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

LGTM

### False positive on `<HiddenSelect />` in accessibility tools

When using &lt;<TypeLink links={docs.links} type={docs.exports.HiddenSelect} />&gt; some accessibility tools such as AXE or pa11y might give a false positive.
The data attribute `data-rsp-a11y-ignore` is included on the hidden select element and can be used to ignore the false positives in these tools.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The data attribute `data-rsp-a11y-ignore` is included on the hidden select element and can be used to ignore the false positives in these tools.
The data attribute `data-a11y-ignore` is included on the hidden select element and can be used to ignore the false positives in these tools.

It got renamed right?

Copy link
Member

Choose a reason for hiding this comment

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

I'll update in a followup

@ktabors
Copy link
Member

ktabors commented Aug 1, 2023

GET_BUILD

@rspbot
Copy link

rspbot commented Aug 1, 2023

@rspbot
Copy link

rspbot commented Aug 1, 2023

## API Changes

unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }

Copy link
Member

@devongovett devongovett left a comment

Choose a reason for hiding this comment

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

thanks for the contribution!

@LFDanLu LFDanLu merged commit 3aa6dbe into adobe:main Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow hidden select to take a className prop
8 participants