-
Notifications
You must be signed in to change notification settings - Fork 77
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
Conversation
* update tests and snapshots
Deploy preview for fundamental-react ready! Built with commit 861c4ac |
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.
Thanks, Prasad! One primary question around the aria-haspopup
.
src/Popover/Popover.js
Outdated
// eslint-disable-next-line no-undefined | ||
if (newPopperProps.id === undefined || newPopperProps.id === null) { | ||
Object.assign(newPopperProps, { id: this.ariaControls }); | ||
} |
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 wonder if this could be simplified and avoid the safe checking by:
- Setting
defaultProps
forpopperProps = {}
- 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, |
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.
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.
src/Popover/Popover.js
Outdated
|
||
//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(); |
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.
ariaControls
is a bit confusing - maybe controlId
would be better?
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.
Since it is not the control's ID how about popoverId
instead? or popoverContainerId
?
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.
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
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.
Looks good beside one possible naming suggestion
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.
LGTM after the small rename 👍
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