Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[On-hold] RSP-1396 [Accessibility] Asterisk has ariaLabel and role presentation #85

Closed
wants to merge 2 commits into from

Conversation

majornista
Copy link
Collaborator

@majornista majornista commented Dec 6, 2019

Closes RSP-1396 and RSP-1360

NOTE: this PR includes a commit to address the related issue for labelling and setting the role on Icon and UIIcon components RSP-1360

✅ Pull Request Checklist:

  • Included link to corresponding RSP-1396 and RSP-1360.
  • 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 exist for this component).
  • Looked at the Accessibility Standard and/or talked to @mijordan about Accessibility for this feature.

📝 Test Instructions:

  1. Open http://localhost:9003/?path=/story/fieldlabel--required-styles
  2. Verify spacing on FieldLabel with necessityLabel and Required Asterix icon
  3. Using web inspector, verify that for the field labelled "Required label (required)", the neccessityLabel span has aria-hidden="true" and the related textfield input has aria-required="true"
  4. Using web inspector, verify that for the field labelled "Optional label (options)", the neccessityLabel span does not have aria-hidden="true" and the related textfield input does not have aria-required="true"
  5. Using web inspector, verify that for the field labelled "React *", the icon svg does not have an aria-label and has aria-hidden="true" and the related textfield input has aria-required="true"
  6. Using web inspector, verify that for the field labelled "isRequired on child", the icon svg is rendered, does not have an aria-label and has aria-hidden="true" and the related textfield input has aria-required="true". This is the case where a single child with isRequired forces isRequired on the parent label.

🧢 Your Team:

Accessibility

@adobe-bot
Copy link

Build successful! View the storybook

packages/@react-spectrum/form/intl/ja-JP.json Outdated Show resolved Hide resolved
packages/@react-aria/label/src/useLabel.ts Outdated Show resolved Hide resolved
packages/@react-spectrum/form/src/LabelBase.tsx Outdated Show resolved Hide resolved
{necessityIndicator && ' '}
{necessityIndicator === 'label' && <span>{necessityLabel}</span>}
{necessityIndicator ? `${label} ` : label}
{necessityIndicator === 'label' && <span className={classNames(styles, 'react-spectrum-FieldLabel-necessityLabel')} aria-hidden={isRequired && childArray.length === 1}>{necessityLabel}</span>}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this extra span? Looks like spectrum-css doesn't have it. https://opensource.adobe.com/spectrum-css/components/fieldlabel/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The span allows me to hide the necessityIndicator from AT when the component isRequired, in order to prevent double voicing of 'required' on the input that has aria-required.

role: 'presentation',
'aria-label': ariaLabel || alt,
'aria-hidden': (ariaLabel || alt ? ariaHidden : true),
role: 'img',
Copy link
Member

Choose a reason for hiding this comment

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

Are we sure we want UIIcon to have role=img? That has effects across many components. Seems more likely that most UIIcons should be aria-hidden by default.

Copy link
Collaborator Author

@majornista majornista Dec 6, 2019

Choose a reason for hiding this comment

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

Always having a role is useful for the unit tests, and @jnurthen asked that we avoid role="presentation" with aria-hidden="true". Either way, it's something of a moot point when the UIIcon has no aria-label or alt text. With aria-label or alt text, the role should be img unless explicitly hidden with aria-hidden.

isRequired?: boolean
}

export function useLabel(labelProps: LabelProps & DOMProps = {}, labelledComponentProps: LabelComponentAriaProps = {}) {
Copy link
Member

Choose a reason for hiding this comment

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

why is labelledComponentProps on both the input and output of this function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The descendant component may already have some relevant aria-label or aria-labelledby props, that when wrapped in a LabelBase may need to be updated.

packages/@react-aria/label/src/useLabel.ts Outdated Show resolved Hide resolved
@@ -35,16 +35,31 @@ describe('ActionButton', function () {
expect(button).toHaveAttribute('aria-hidden', 'true');
});

// TODO: update v2 to use `role="img" aria-hidden="true"` for hold affordance icon, and then recombine following two tests.
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have a todo about v2? I know this is a note about improving the tests but it seems like the v2 story should have a note about updating v3 tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That makes sense. We don't have a v2 story for this issue yet, but I'll create one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

PR against v2: #716

packages/@react-spectrum/button/test/ActionButton.test.js Outdated Show resolved Hide resolved
packages/@react-spectrum/icon/test/Icon.test.js Outdated Show resolved Hide resolved
packages/@react-spectrum/icon/test/UIIcon.test.js Outdated Show resolved Hide resolved
@adobe-bot
Copy link

Build successful! View the storybook

@adobe-bot
Copy link

Build successful! View the storybook

@adobe-bot
Copy link

Build successful! View the storybook

2 similar comments
@adobe-bot
Copy link

Build successful! View the storybook

@adobe-bot
Copy link

Build successful! View the storybook

@adobe-bot
Copy link

Build successful! View the storybook

<Asterisk
className={classNames(styles, 'spectrum-FieldLabel-requiredIcon')}
size="S"
alt={childArray.length === 1 ? undefined : formatMessage('(required)').replace(/[(((](.+?)[)))]/g, '$1')} />
Copy link
Member

Choose a reason for hiding this comment

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

Should we remove this alt completely and set aria-hidden to true on the icon instead (second option in ticket)? Seems like it would be simpler, and avoid duplicating required text in label and aria-required on input. I forget why the second option was discarded.

Copy link
Member

Choose a reason for hiding this comment

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

Also noticed below that when necessity indicator is a label and not an icon, it is aria-hidden, but not when it's an icon?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We want the icon to have alt text when the childArray.length > 1. Icons are hidden by default when alt is undefined.

Copy link
Member

Choose a reason for hiding this comment

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

Why though? The input would have aria-required on it so would be announced as required already. Wouldn't the extra alt text on the icon just be redundant? I'm not sure about this case with > 1 child. Wouldn't all the inputs have aria-required on them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don’t think that a fieldset of checkboxes requiring one or more selections would have aria-required on each checkbox, but the fieldset should read as required.

Copy link
Member

Choose a reason for hiding this comment

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

Ah. Wondering if there should be a separate component for groups of fields as opposed to a single one. The logic in here is getting really complicated and hard to follow. Not sure we nailed the API on this one yet.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could have a Fieldset component, but I'm not sure that that prevents users from using FieldLabel in this way. Would always adding the alt attribute and only explicitly setting aria-hidden="true" when childArray.length === 1 make this more clear?

@adobe-bot
Copy link

Build successful! View the storybook

@majornista majornista force-pushed the RSP-1396 branch 3 times, most recently from 469d34e to 47f5e3e Compare December 12, 2019 22:55
@adobe-bot
Copy link

Build successful! View the storybook

@adobe-bot
Copy link

Build successful! View the storybook

@adobe-bot
Copy link

Build successful! View the storybook

@dannify dannify changed the title RSP-1396 [Accessibility] Asterisk has ariaLabel and role presentation [On-hold] RSP-1396 [Accessibility] Asterisk has ariaLabel and role presentation Dec 14, 2019
@adobe-bot
Copy link

Build successful! View the storybook

RSP-1360 Use `toBeTruthy` rather than `not.toBeNull`
- Fix gap between icon or necessityLabel

With one child, and isRequired on the LabelBase:

- remove the alt text from the required icon or set aria-hidden={true} to the necessityLabel span element.
- ensure that the child also receives isRequired={true} so that it will communicate required state by adding aria-required="true" to the input.

Otherwise, include alt text on the required icon or don't hide the necessityLabel with aria-hidden.

If the LabelBase does not have isRequired, but isRequired is true for the child component, set isRequired on the LabelBase, and also set necessityIndicator = 'icon' if necessityIndicator is undefined on the LabelBase.

RSP-1396 Use zero-width space to force whitespace before necessity label

RSP-1396 Improve comments regarding aria-hidden on required label or icon

Improve aria-required propagation to using Provider.
@adobe-bot
Copy link

Build successful! View the storybook

@majornista majornista closed this Dec 19, 2019
@snowystinger snowystinger deleted the RSP-1396 branch January 8, 2020 23:28
devongovett added a commit that referenced this pull request Jul 25, 2024
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.

5 participants