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

UI: Add a 'main' role to the Main component for a11y #13827

Merged
merged 1 commit into from
Feb 11, 2021

Conversation

adagar
Copy link
Contributor

@adagar adagar commented Feb 5, 2021

Issue: #13794

What I did

Added a role="main" to the Main functional component

How to test

Install and run the axe plug-in in Chrome. Observe that the error regarding a main landmark is resolved after this PR is added.

@shilman
Copy link
Member

shilman commented Feb 6, 2021

Thank you @adagar! @tooppaaa @jsomsanith can you please review?

@shilman shilman added this to the 6.2 core milestone Feb 6, 2021
@shilman shilman changed the title fix(a11y): Adds a 'main' role to the Main component UI: Adds a 'main' role to the Main component for a11y Feb 6, 2021
@@ -120,7 +120,7 @@ export const Main: FunctionComponent<{ isFullscreen: boolean; position: CSSPrope
position = undefined,
...props
}) => (
<Pane style={position} top {...props}>
<Pane style={position} top {...props} role="main">
Copy link
Contributor

@jsomsanith jsomsanith Feb 6, 2021

Choose a reason for hiding this comment

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

This is totally correct so I approved. But as a suggestion, a better way would be to render a ˋmain` element

Via styled component « as »

Suggested change
<Pane style={position} top {...props} role="main">
<Pane style={position} top {...props} as="main">

The same can be applied to the sidebar to render a nav element

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestions! I'm hoping to use this one as an example, but then I'd like this approach to be spread so that most if not all major UI elements have landmarks set like this. I'll make the as update after testing to confirm axe picks it up correctly.

Copy link
Member

Choose a reason for hiding this comment

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

@jsomsanith we're using emotion not styled components ... not sure that makes a difference? 🤷‍♂️

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the precision. Emotion has the « as » props as well 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This took me a bit longer to get back to than expected, but from what I can tell, as can't be used for this type of element:

Type '{ children: Element; as: string; style: CSSProperties; top: true; }' is not assignable to type 'IntrinsicAttributes & ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & Pick<...> & { ...; } & { ...; }'.
  Property 'as' does not exist on type 'IntrinsicAttributes & ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & Pick<...> & { ...; } & { ...; }'.ts(2322)

@shilman shilman changed the title UI: Adds a 'main' role to the Main component for a11y UI: Add a 'main' role to the Main component for a11y Feb 11, 2021
@shilman shilman merged commit 1e97c26 into storybookjs:next Feb 11, 2021
@cdedreuille cdedreuille mentioned this pull request Oct 9, 2023
8 tasks
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.

4 participants