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

ToggleButton: indicate toggle button state on underlying button elements #438

Merged
merged 3 commits into from
Nov 2, 2022

Conversation

daneah
Copy link
Member

@daneah daneah commented Nov 2, 2022

This change: (check at least one)

  • Adds a new feature
  • Fixes a bug
  • Improves maintainability
  • Improves documentation
  • Is a release activity

Is this a breaking change? (check one)

  • Yes
  • No

Is the: (complete all)

  • Title of this pull request clear, concise, and indicative of the issue number it addresses, if any?
  • Test suite(s) passing?
  • Code coverage maximal?
  • Changeset added?
  • Component status page up to date?

What does this change address?

Resolves #430

Because the accessibility object model (AOM) is still in active development and doesn't enjoy wide browser vendor adoption at present, we need to maintain the accessibility for assistive technologies in the underlying native elements rather than the custom element host containers.

How does this change work?

For things like buttons, this often means adding a property that gets rendered onto the underlying native element as an aria- attribute. Here, I add a pressed property to Button so that the ToggleButton can set it appropriately, which gets rendered as aria-pressed on the underlying <button> element. I also add a group-label prop to ToggleButton that renders the aria-label for the full button group, useful for consumers to add the most contextualized description they can for each usage.

Additional context

The approach here is a generally desired one for optimal accessibility, and not unique to this particular component. Some of these may prove more difficult to manage, such as getting the right aria-describedby value down into the native element for any and every component that might need a tooltip. One approach could be for the tooltip to attach itself to the outermost shadow DOM element, but we'll need to take stock to see how future-proof that'd be.

… elements

Because the accessibility object model (AOM) is still in active
development and doesn't enjoy wide browser vendor adoption at present,
we need to maintain the accessibility for assistive technologies in the
underlying native elements rather than the custom element host
containers. For things like buttons, this often means adding a property
that gets rendered onto the underlying native element as an `aria-`
attribute.
@daneah daneah requested a review from a team as a code owner November 2, 2022 00:05
@daneah daneah requested review from chrisjbrown, SMQuazi and jialin-he and removed request for a team November 2, 2022 00:05
@changeset-bot
Copy link

changeset-bot bot commented Nov 2, 2022

🦋 Changeset detected

Latest commit: e1df0a8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@ithaka/pharos Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Nov 2, 2022

size-limit report 📦

Path Size
packages/pharos/lib/index.js 46.47 KB (+0.2% 🔺)

@@ -17,6 +17,8 @@ export type ButtonType = 'button' | 'submit' | 'reset';

export type ButtonVariant = 'primary' | 'secondary' | 'subtle' | 'overlay';

export type PressedState = 'false' | 'true' | 'mixed' | 'undefined';
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious what state is a "mixed" state?

Copy link
Member Author

Choose a reason for hiding this comment

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

Have a read of the docs for aria-pressed

* @attr value
*/
@property({ type: String, reflect: true })
public pressed: PressedState = 'undefined';
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be set to the string undefined?

Copy link
Member Author

@daneah daneah Nov 2, 2022

Choose a reason for hiding this comment

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

Yes, it's one of the PressedStates. Have a read of the docs for aria-pressed; this value means "I'm not a toggle button" by default.

Copy link
Contributor

@sirrah-tam sirrah-tam left a comment

Choose a reason for hiding this comment

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

I was able to validate this update and confirm the expected behavior with VoiceOver on MacOS in Firefox and Safari and on Windows with NVDA and Chrome/Firefox/Edge.

However, this appears to have introduced a bug in Chrome (Version 97.0.4692.71) with VO where none of the toggle buttons have a calculated name and are just announced as "Toggle button" along with current state.

@daneah
Copy link
Member Author

daneah commented Nov 2, 2022

@sirrah-tam Thanks for looking! Interestingly, I observed Chrome working with VO on my end 🤔

@sirrah-tam
Copy link
Contributor

Hmm, it appears that my installation of Chrome on my work laptop has been kept back by some org settings. Tested this on my personal laptop and can confirm its working as expected. Tested on Chrome v 107.0.5304.87.

Copy link
Contributor

@sirrah-tam sirrah-tam left a comment

Choose a reason for hiding this comment

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

Validated and working as expected. Screen reader users will perceive the group name upon entering the toggle button grouping and each control is announced as a toggle button and includes its current state as pressed/not pressed.

@daneah daneah requested a review from jialin-he November 2, 2022 18:21
@daneah daneah merged commit 4f56c1b into develop Nov 2, 2022
@daneah daneah deleted the fix/toggle-button-a11y branch November 2, 2022 20:28
daneah added a commit that referenced this pull request Nov 3, 2022
* develop:
  ToggleButton: indicate toggle button state on underlying button elements (#438)
  Tooltip, DropdownMenu: replace popperjs with floating-ui (#434)
daneah added a commit that referenced this pull request Nov 10, 2022
* develop:
  Tabs: fix initial tab selection in more cases (#449)
  Storybook: add eslint-plugin-storybook and fix issues (#446)
  feat(storybook): install Measure and Outline addons (#445)
  Docs: update copy for Button's on-background usage (#444)
  Storybook: Convert stories to CSF 3 (#435)
  feat(tabs): fire event when tab selected programmatically (#442)
  ToggleButton: indicate toggle button state on underlying button elements (#438)
  Tooltip, DropdownMenu: replace popperjs with floating-ui (#434)
  Site: improve imports (#433)
@github-actions github-actions bot mentioned this pull request Nov 10, 2022
@sirrah-tam
Copy link
Contributor

sirrah-tam commented Apr 7, 2023

@daneah - One side effect of the change we made to this is that all Pharos buttons now have the aria-pressed="undefined" attribute added by default. While this isn't necessarily problematic at first, it has shown a bit of inconsistency across some browser & AT combinations. While testing with VoiceOver on Safari, the presence of that attribute makes the button be parsed as a "toggle button" and is announced as such even though I don't believe that's the intention. Users will expect certain behavior if its announced as that type of button control, and could become confused if it does something different.

@daneah
Copy link
Member Author

daneah commented Apr 7, 2023

@sirrah-tam can you please open a new issue?

sirrah-tam pushed a commit to sirrah-tam/pharos that referenced this pull request Dec 1, 2023
…nts (ithaka#438)

* fix(toggle-button): indicate toggle button state on underlying button elements

Because the accessibility object model (AOM) is still in active
development and doesn't enjoy wide browser vendor adoption at present,
we need to maintain the accessibility for assistive technologies in the
underlying native elements rather than the custom element host
containers. For things like buttons, this often means adding a property
that gets rendered onto the underlying native element as an `aria-`
attribute.

* fix(toggle-button): address type imports and add unit tests

* chore: add changeset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Toggle button group not conveying state
4 participants