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

Components: Adds AccessibleSVG component and use consistently for block icons #9565

Merged
merged 6 commits into from
Sep 4, 2018

Conversation

youknowriad
Copy link
Contributor

closes #9372

  • This PR adds an AccessibleSVG component
  • Use this component in BlockIcon

Test that the svg icons contain the required A11y props.

@youknowriad youknowriad added [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Components /packages/components labels Sep 3, 2018
@youknowriad youknowriad self-assigned this Sep 3, 2018
@jasmussen
Copy link
Contributor

This is impressive. From my quick testing, it seems like all the block icons had the proper attributes as they need. Fine work! I can't really speak too much for the code — it looks good to me. But from everything else, 👍 👍

Thanks for working on this.

Copy link
Member

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

I think some documentation around what happens here would be useful as right now this is elegant, but a bit Magic™.

Overall a cool solution though, and definitely one that prevents third-party developers from making mistakes.

I trust you to add some kind of documentation or something, so 👍 with docs. Feel free to ping for further review if needed 😄

@@ -18,6 +18,8 @@ function renderIcon( icon ) {
}

return icon();
} else if ( icon && icon.type === 'svg' ) {
Copy link
Member

Choose a reason for hiding this comment

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

That is, I suppose, a better solution that prevents developers who don't bother to use our components from causing an error. It's definitely less explicit though and I don't see any documentation around it: either that using AccessibleSVG directly is preferred or even that if the icon prop is an SVG that we'll add properties to it. We should probably at least document this, as it might be quite jarring to a block developer to see their icon markup change unexpectedly like this with no documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I personally don't think it's important enough for people to know precisely that we're adding some props to their SVGs to make them accessible. I guess it doesn't harm to add a mention in the documention but if we do so, we should avoid using AccessibleSVG directly in the components because the behavior is documented in that case.

Copy link
Member

Choose a reason for hiding this comment

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

That's fair. I think I'd prefer the documentation because it teaches people about an accessibility issue and it means our code can be: 1. a bit leaner (no imports) 2. more idiomatic (regular SVGs)

So maybe just a note of "we add accessibility properties to SVGs" in the block property documentation with a link to the original issue for context or something.

@@ -18,7 +18,7 @@ export const settings = {

description: __( 'This block is deprecated. Please use the Paragraph block instead.' ),

icon: <svg role="img" aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7.1 6l-.5 3h4.5L9.4 19h3l1.8-10h4.5l.5-3H7.1z" /></svg>,
icon: <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7.1 6l-.5 3h4.5L9.4 19h3l1.8-10h4.5l.5-3H7.1z" /></svg>,
Copy link
Member

Choose a reason for hiding this comment

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

I get that we don't have to use our component directly, but I wonder why we wouldn't. This is less explicit and we're already changing all of the lines 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't mind, I was hesitant as well.

Copy link
Member

Choose a reason for hiding this comment

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

As mentioned though, feel free to leave them SVG if you add docs. I think that's probably the better approach, upon reflection.

@tofumatt tofumatt added this to the 3.8 milestone Sep 3, 2018
@youknowriad
Copy link
Contributor Author

@tofumatt I added a note to the docs, feel free to tweak it (I'm not great at documentation :P)

Copy link
Member

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

Docs look good; I made a few tweaks (mainly changing a11y to accessibility).

:shipit:

@youknowriad youknowriad merged commit 3b6c167 into master Sep 4, 2018
@youknowriad youknowriad deleted the add/accessible-svg branch September 4, 2018 10:27
@afercia
Copy link
Contributor

afercia commented Sep 4, 2018

Test that the svg icons contain the required A11y props.

❤️

@caxco93
Copy link
Contributor

caxco93 commented Sep 6, 2018

I think we should extract the SVG icons to another package, maybe @wordpress/icons. This will increase their reusability and maintainability. Right now I was looking at #9642 and it would require to declare the same SVG again for the MediaPlaceholder icon.

Here's the PR where I extract the SVG icons to a new package

Then we could simply do it like this
image

@youknowriad @tofumatt

@jasmussen
Copy link
Contributor

@mtias
Copy link
Member

mtias commented Sep 6, 2018

@youknowriad coming a bit late to this, but I feel this should be just called Svg (with capital) as being accessible should be core to all the components we offer.

@tofumatt
Copy link
Member

tofumatt commented Sep 6, 2018

That's kinda confusing if you quickly scan it 🤷‍♂️ (<Svg /> vs <svg />), but also the point is the stock SVGs aren't always accessible and the aim of the wrapper is to make them so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Components /packages/components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide (and require) block icon component to ensure accessibility attributes are present
6 participants