Skip to content

Fix cart image link accessibility pattern#623

Merged
tauthomas01 merged 3 commits intomainfrom
fix-cart-image-link
Sep 16, 2021
Merged

Fix cart image link accessibility pattern#623
tauthomas01 merged 3 commits intomainfrom
fix-cart-image-link

Conversation

@tauthomas01
Copy link
Contributor

Why are these changes introduced?

Related PR: #605
The goal of this PR is the same as #605 , except that we want users to be able to right click to open a new tab. Currently, we use JS to trigger the link so it's not possible

What approach did you take?

Followed Scott's approach:

  • Add an <a> tag, and use position absolute to take full space
  • Add aria-hidden and tabindex=-1 so assistive technology can't detect the link, but only the image.

Demo links

Checklist

@tauthomas01 tauthomas01 requested a review from svinkle September 13, 2021 20:43
svinkle
svinkle previously approved these changes Sep 14, 2021
@sofiamatulis sofiamatulis self-assigned this Sep 14, 2021
sofiamatulis
sofiamatulis previously approved these changes Sep 14, 2021
Copy link
Contributor

@sofiamatulis sofiamatulis left a comment

Choose a reason for hiding this comment

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

Nice! 🎉

<tr class="cart-item" id="CartItem-{{ item.index | plus: 1 }}">
<td class="cart-item__media">
{% if item.image %}
<a href="{{ item.url }}" class="cart-item__link" aria-hidden="true" tabindex="-1"> </a>
Copy link
Contributor

Choose a reason for hiding this comment

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

Since <a> is empty can we just do this instead?

Suggested change
<a href="{{ item.url }}" class="cart-item__link" aria-hidden="true" tabindex="-1"> </a>
<a href="{{ item.url }}" class="cart-item__link" aria-hidden="true" tabindex="-1">

Copy link
Member

Choose a reason for hiding this comment

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

This results in invalid HTML. Any element with an opening tag must be accompanied by a closing tag (with the exception of elements which do not feature a text node such as input, img, br, etc.

Copy link
Contributor

@sofiamatulis sofiamatulis Sep 14, 2021

Choose a reason for hiding this comment

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

You are right, thank you. I knew with HTML5 more tags could be self-closing and assumed this was the case for a too. I confused it with how now you can do <br> instead of <br/>

Can we remove the extra space?

Suggested change
<a href="{{ item.url }}" class="cart-item__link" aria-hidden="true" tabindex="-1"> </a>
<a href="{{ item.url }}" class="cart-item__link" aria-hidden="true" tabindex="-1"></a>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally, I removed the extra space, but due to the a:empty display: none rule, it gets overwritten.

If I remove the empty space, most likely I will have to write a more specific CSS rules.
What are your thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh you are right! Then I think we can leave it as is since that makes sense 👍

And the decision/reason for it is documented here in case we need to come back to it

@tauthomas01 tauthomas01 merged commit 051dd5c into main Sep 16, 2021
@tauthomas01 tauthomas01 deleted the fix-cart-image-link branch September 16, 2021 20:08
phapsidesGT pushed a commit to Gravytrain-UK/gt-shopify-dawn-theme that referenced this pull request Sep 3, 2024
* Add space to avoid the CSS :empty display none rule

* move link inside the condition only if media exist

* Add comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments