-
Notifications
You must be signed in to change notification settings - Fork 26
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(collapsible-panel): Accessible panel Header element #1283
Conversation
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/commercetools/ui-kit/o8j4iipn7 |
@@ -9,12 +9,16 @@ import getNormalizedButtonStyles from './accessible-button.styles'; | |||
|
|||
const propsToOmit = ['onClick']; | |||
|
|||
const getIsEnterOrSpace = e => | |||
e.key === ' ' || e.key === 'Spacebar' || e.which === 13 || e.which === 32; |
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.
What is ' '
? :). Is there maybe like a itty-bity util library we can use for this? Or do you think it's fine inlining it?
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 for the Spacebar.
I just double-checked a bit deeper and simplified this line, according to this spec that React uses for the key
field of their synthetic events: https://www.w3.org/TR/uievents-key/#keys-whitespace
buttonProps = { | ||
type: props.type, | ||
}; | ||
} else if (!props.isDisabled) { |
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.
Nit: do-expression?
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.
It gets a little weird-looking with the object braces for the logic I am trying to achieve, am i doing this right?
const buttonProps =
do {
if (isButton) {
{
type: props.type,
}
}
else if (!props.isDisabled) {
{
role: 'button',
tabIndex: '0',
onKeyPress: event => getIsEnterOrSpace(event) && handleClick(event),
}
}
else {
{ }
}
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.
True that also don't make it much simpler either.
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.
...just tried to avoid the let in a way.
buttonProps = { | ||
type: props.type, | ||
}; | ||
} else if (!props.isDisabled) { |
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.
...just tried to avoid the let in a way.
Summary
This PR addresses this problem: https://github.com/commercetools/merchant-center-frontend/pull/8565#issuecomment-598637568.
It occurs when the
CollapsiblePanel
is passed any child elements for the Header that are buttons, because the Header of the CollapsiblePanel is also abutton
element.Description
AccessibleButton
component to become truly accessible when theas
prop is used:role
andtabIndex
attributes.onKeyPress
event forEnter
andSpace
to trigger theonClick
, for full keyboard navigation support.AccessibleButton
as adiv
for the CollapsiblePanel header, instead of abutton
element but keeping the a11y.