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

fix: Add aria attributes to popover control #796

Merged
merged 7 commits into from
Nov 21, 2019

Conversation

prsdthkr
Copy link
Member

Description

Add following aria attributes to popover control/target.

This allows screen readers and other assistive technologies to understand the popover interactions semantically.

fixes #791

@prsdthkr prsdthkr self-assigned this Nov 20, 2019
@prsdthkr prsdthkr requested a review from a team November 20, 2019 05:41
@netlify
Copy link

netlify bot commented Nov 20, 2019

Deploy preview for fundamental-react ready!

Built with commit 861c4ac

https://deploy-preview-796--fundamental-react.netlify.com

@prsdthkr prsdthkr added A11y Accessiblity bug Something isn't working / Issues in the code fixed A fix for the issue was provided labels Nov 20, 2019
@prsdthkr prsdthkr requested a review from a team November 20, 2019 16:22
Copy link
Contributor

@markpalfreeman markpalfreeman left a comment

Choose a reason for hiding this comment

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

Thanks, Prasad! One primary question around the aria-haspopup.

// eslint-disable-next-line no-undefined
if (newPopperProps.id === undefined || newPopperProps.id === null) {
Object.assign(newPopperProps, { id: this.ariaControls });
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this could be simplified and avoid the safe checking by:

  1. Setting defaultProps for popperProps = {}
  2. Just assigning an id inline?
const id = popperProps.id || this.ariaControls;
...
popperProps={{ ...popperProps, id }}

'aria-haspopup': true,
'aria-controls': newPopperProps.id,
'aria-expanded': this.state.isExpanded,
'aria-haspopup': !!type ? type : true,
Copy link
Contributor

@markpalfreeman markpalfreeman Nov 20, 2019

Choose a reason for hiding this comment

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

Is this right? The positive/first ternary return type seems like it could end up being a string.
I imagine the intention is a boolean, but when should this be false? (there should probably be a test for this)

Aaaaand I stand corrected! Wasn't aware haspopup takes boolean values as well as enum types.


//A generated shortId as fallback, incase props.popperProps.id is unset.
//This ID binds the popover and it's control by 'aria-controls'.
this.ariaControls = shortId.generate();
Copy link
Contributor

Choose a reason for hiding this comment

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

ariaControls is a bit confusing - maybe controlId would be better?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since it is not the control's ID how about popoverId instead? or popoverContainerId?

Copy link
Contributor

@markpalfreeman markpalfreeman Nov 20, 2019

Choose a reason for hiding this comment

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

Yeah, I think popoverId makes sense. It's a bit difficult to distinguish between that and popperProps.id, but I think it's clear enough that one comes from props and the other is defined here as a fallback.

Can you fix a couple small typos while you're here? in case & its

Copy link
Contributor

@meganaconley meganaconley left a comment

Choose a reason for hiding this comment

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

Looks good beside one possible naming suggestion

Copy link
Contributor

@markpalfreeman markpalfreeman left a comment

Choose a reason for hiding this comment

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

LGTM after the small rename 👍

@prsdthkr prsdthkr merged commit 36f1b72 into master Nov 21, 2019
@prsdthkr prsdthkr deleted the fix/issue-791-popover-aria-attributes branch November 21, 2019 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A11y Accessiblity bug Something isn't working / Issues in the code fixed A fix for the issue was provided
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Popover control should have aria attributes for accessibility
3 participants