-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
Build successful! View the storybook |
{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>} |
There was a problem hiding this comment.
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/
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = {}) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@@ -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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR against v2: #716
Build successful! View the storybook |
Build successful! View the storybook |
packages/@adobe/spectrum-css-temp/components/fieldlabel/index.css
Outdated
Show resolved
Hide resolved
Build successful! View the storybook |
Build successful! View the storybook |
<Asterisk | ||
className={classNames(styles, 'spectrum-FieldLabel-requiredIcon')} | ||
size="S" | ||
alt={childArray.length === 1 ? undefined : formatMessage('(required)').replace(/[(((](.+?)[)))]/g, '$1')} /> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
Build successful! View the storybook |
469d34e
to
47f5e3e
Compare
Build successful! View the storybook |
Build successful! View the storybook |
Build successful! View the storybook |
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.
Build successful! View the storybook |
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:
📝 Test Instructions:
🧢 Your Team:
Accessibility