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(collapsible-panel): Accessible panel Header element #1283

Merged
merged 4 commits into from
Mar 16, 2020

Conversation

jonnybel
Copy link
Contributor

@jonnybel jonnybel commented Mar 16, 2020

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 a button element.

Description

  • Fix the AccessibleButton component to become truly accessible when the as prop is used:
    • Add role and tabIndex attributes.
    • Add onKeyPress event for Enter and Space to trigger the onClick, for full keyboard navigation support.
  • Use this adjusted AccessibleButton as a div for the CollapsiblePanel header, instead of a button element but keeping the a11y.

@vercel
Copy link

vercel bot commented Mar 16, 2020

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/commercetools/ui-kit/o8j4iipn7
✅ Preview: https://ui-kit-git-fix-accessible-panel-header.commercetools.now.sh

@jonnybel jonnybel added the 🐛 Type: Bug Something isn't working label Mar 16, 2020
@jonnybel jonnybel self-assigned this Mar 16, 2020
@jonnybel jonnybel requested a review from tdeekens March 16, 2020 09:02
@@ -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;
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: do-expression?

Copy link
Contributor Author

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 {
  { }
 }

Copy link
Contributor

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.

Copy link
Contributor

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) {
Copy link
Contributor

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.

@kodiakhq kodiakhq bot merged commit d921662 into master Mar 16, 2020
@kodiakhq kodiakhq bot deleted the fix-accessible-panel-header branch March 16, 2020 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants