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

Feature request: aria-hidden #72

Closed
tysongach opened this issue Oct 2, 2017 · 9 comments
Closed

Feature request: aria-hidden #72

tysongach opened this issue Oct 2, 2017 · 9 comments

Comments

@tysongach
Copy link

tysongach commented Oct 2, 2017

👋

Huge high-fives all-around for the accessibility features this gem already offers. It’s so handy to be able to pass in titles and descriptions when you call on an SVG. I’d like to discuss furthering the accessibility features by allowing the hiding of SVGs using aria-hidden.

Sometimes SVGs are simply decorative and therefore should be removed from the accessibility tree. Here’s an example:

<p>
  <%= inline_svg "checkmark-icon.svg" %>
  Success!
</p>

You can imagine this as a simple flash message, letting the user know that their action succeeded. We have the word ‘Success’, preceded by a checkmark icon to visually represent the state.

In such a situation, the icon is simply decorative; it’s repeating content already conveyed by the word ‘Success.’ If we apply aria-hidden="true" to the SVG, we can remove it from the accessibility tree and avoid the repetition.

Possible solution?

I’ve not dug into the specifics of how the aria option works, but perhaps passing it a hidden value could work (edit: see comment below):

<%= inline_svg "icon.svg", aria: "hidden" %>
<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg">
  …
</svg>
@tysongach
Copy link
Author

Perhaps this is a good issue for a Hacktoberfest label?

@jamesmartin
Copy link
Owner

@tysongach thanks for taking the time to write up this suggestion. I'm generally 👍 on any feature that improves things from an accessibility perspective.

As for the interface, my preference would be to make this an explicit option, requiring a value. E.g.

<%= inline_svg "icon.svg", aria_hidden: true %>

@seanpdoyle
Copy link
Contributor

@jamesmartin @tysongach is this already supported?

it "applies custm transformations to the output" do
input_svg = <<-SVG
<svg></svg>
SVG
expected_output = <<-SVG
<svg custom="some value"></svg>
SVG
allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
expect(helper.inline_svg('some-file', custom: 'some value')).to eq expected_output
end

Could something like this work?

<%= inline_svg "icon.svg", "aria-hidden" => true %>

@jamesmartin
Copy link
Owner

is this already supported?

@seanpdoyle it's possible to implement via custom transformations, but each user of the gem would have to implement their own version. Is that what you had in mind?

@seanpdoyle
Copy link
Contributor

@jamesmartin for custom attribute support, are there additional steps to take other than "aria-hidden" => true?

<%= inline_svg "icon.svg", "aria-hidden" => true %>

@tysongach
Copy link
Author

tysongach commented Oct 9, 2017

I should’ve been more clear in my original description, but yes, this is possible today via custom transformations:

class AriaHiddenAttribute < InlineSvg::CustomTransformation
  def transform(doc)
    doc = Nokogiri::XML::Document.parse(doc.to_html)
    svg = doc.at_css "svg"
    svg["aria-hidden"] = value
    doc
  end
end


InlineSvg.configure do |config|
  config.add_custom_transformation(
    attribute: :aria_hidden,
    transform: AriaHiddenAttribute,
  )
end

This allows you to pass a aria_hidden: true option when using this inline_svg helper. Although each user can add this custom transformation today, I have found myself adding it to many project and using it quite often, so I thought it would be useful as a core feature.

@jamesmartin
Copy link
Owner

for custom attribute support, are there additional steps to take other than "aria-hidden" => true?

@seanpdoyle yes, see @tysongach's example code.

@jamesmartin jamesmartin self-assigned this Oct 13, 2017
seanpdoyle added a commit to seanpdoyle/inline_svg that referenced this issue Oct 13, 2017
Closes [jamesmartin#72].

Sometimes SVGs are simply decorative and therefore should be removed
from the accessibility tree. Here’s an example:

```erb
<p>
  <%= inline_svg "checkmark-icon.svg" %>
  Success!
</p>
```

You can imagine this as a simple flash message, letting the user know
that their action succeeded. We have the word ‘Success’, preceded by a
checkmark icon to visually represent the state.

In such a situation, the icon is simply decorative; it’s repeating
content already conveyed by the word ‘Success.’ If we apply
`aria-hidden="true"` to the SVG, we can remove it from the accessibility
tree and avoid the repetition.

[jamesmartin#72]: jamesmartin#72
@seanpdoyle
Copy link
Contributor

@tysongach @jamesmartin #79

@jamesmartin
Copy link
Owner

@seanpdoyle thanks for opening the PR for this. Great minds think alike, I think we both just implemented the same thing. See #78 😁

I'll merge yours so you get the contribution credit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants