惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
S
Schneier on Security
The Hacker News
The Hacker News
P
Proofpoint News Feed
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
I
Intezer
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Schneier on Security
Schneier on Security
Security Latest
Security Latest
AWS News Blog
AWS News Blog
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
有赞技术团队
有赞技术团队
博客园 - 叶小钗
The Last Watchdog
The Last Watchdog
O
OpenAI News
月光博客
月光博客
Hacker News: Ask HN
Hacker News: Ask HN
阮一峰的网络日志
阮一峰的网络日志
S
Security @ Cisco Blogs
Google Online Security Blog
Google Online Security Blog
云风的 BLOG
云风的 BLOG
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Latest news
Latest news
P
Palo Alto Networks Blog
Last Week in AI
Last Week in AI
M
MIT News - Artificial intelligence
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
Apple Machine Learning Research
Apple Machine Learning Research
U
Unit 42
PCI Perspectives
PCI Perspectives
博客园 - 聂微东
SecWiki News
SecWiki News
宝玉的分享
宝玉的分享
Forbes - Security
Forbes - Security
H
Heimdal Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Troy Hunt's Blog
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
罗磊的独立博客
WordPress大学
WordPress大学
D
Darknet – Hacking Tools, Hacker News & Cyber Security

User Agent Man

Introducing Enable: Accessible Web Components You Can Learn From R.I.P. Internet Explorer: A Hate Filled Love Letter How to Fix Seizure Inducing Sequences In Videos How To Style Resized Text and Quickly Fix WCAG 1.4.4 Issues Creating Accessible HTML5 Modal Dialogs For Desktop and Mobile Using PEAT To Create Seizureless Web Animations Implementing An Accessible Skip Navigation Link Requires More Thought Than You’d Think Making Framework Agnostic Isomorphic Web Applications with Query Strings and HTML5 pushState How To Fix Transformed Text in HTML5 Canvas In Firefox For Windows
Fixing Firefox’s Keyboard Accessibility Bug With Flex Layout
zoltan · 2017-01-29 · via User Agent Man

While fixing accessibility issues on a project, I noticed a huge problem with a page that relied on CSS Flex Layout, specifically with the order property. If you are not familiar with CSS order, it allows developers to make the visual order of elements on the page different than their DOM order. For example, you can have this code:

<div class="flex-example shuffled">
  <button class="btn">
    <strong>1</strong>
    <br> This appears first in source order.
  </button>
  <button class="btn">
    <strong>2</strong>
    <br> This appears second in source order.
  </button>
  <button class="btn">
    <strong>3</strong>
    <br> This appears third in source order.
  </button>
  <button class="btn">
    <strong>4</strong>
    <br> This appears fourth in source order.
  </button>
</div>

with CSS like this:

.flex-example {
  display: inline-flex;
  justify-content: space-around;
  width: 100%;
}

.example-main > div .btn {
  width: 23%;
}

div.shuffled .btn:nth-child(1) {
  order: 2;
}

div.shuffled .btn:nth-child(2) {
  order: 4;
}

div.shuffled .btn:nth-child(3) {
  order: 1;
}

div.shuffled .btn:nth-child(4) {
  order: 3;
}

look like this:

Note that the order property changes the how the order of the elements appear visually in the design. Neat, huh?

Among it’s other use-cases, I have found the order property is extremely useful when the order of elements change from breakpoint to breakpoint. However, it opens up a huge accessibility issue in the desktop version of Firefox. When a user employs a keyboard to navigate the page, all other browsers have the tabbing order to be the same as the DOM order, as shown in this animation:

Animation showing tabbing order of previous example in Chrome.  Note the tabbing order is the DOM order, not visual order.

Animated GIF showing the tabbing order of elements with flex-layout’s order CSS property (bottom) and without (top). Note the tabbing order is the DOM order, not visual order.

Unfortunately, the desktop version of Firefox is different — it makes the tabbing order the same as the visual order, as seen here:

Animation showing tabbing order of the same example in Firefox. Note the tabbing order is the visual order, not the DOM order.

Animation showing tabbing order of the same example in Firefox. Note the tabbing order is the visual order, not the DOM order.

These examples were originally made for the excellent article HTML Source Order vs CSS Display Order by Adrian Roselli. In it, he mentions that this will likely be fixed due to this bug report asking to fix the issue. It is unclear, however, if/when it will be fixed (the bug was reported in 2012!), so I implemented a fix using JavaScript to fix this issue. Note that this bug only appears in the desktop version of Firefox, the Android version of Firefox 50 doesn’t have this bug when using Talkback gestures.

Load the above example with the Firefox Flex Layout Keyboard Navigation Fix.

How Does This Fix Work?

This fix uses event delegation to listen to all focus and blur events on the page. When a tabbable element gains focus, we set the tabindex property of it and the tabbable DOM elements before and after it so that tabbing order repects DOM order. The tabindex values used are the highest three that the can be used, in order to ensure we are not interfering with the tabindex of any other element. When a tabbable element is blurred (and on keypress when the TAB key is pressed), the tabindex of these three elements are set back to what they were before they the focus event.

This fix will only be executed in Firefox, since it is the only browser that has this issue (at the moment).

How Can I Implement This Fix Myself?

  1. Have your application load the fixFirefoxFlexbox.js script (it’s from my a11y-examples GitHub repo, which is where I am putting examples for all my accessibility fixes going forward).
  2. Add the a11y-fix-firefox-flexbox class to the <body> of your document.
  3. That’s it.

But Doesn’t Visual Order Would Make More Sense Than DOM Order?

There is quite a bit of debate on this right now. If you look at the comments on the Firefox bug on the issue, quite a few people understandably think visual order makes sense. However, this is contrary to what the official Flexbox spec says (which states “The order property does not affect ordering in non-visual media (such as speech). Likewise, order does not affect the default traversal order of sequential navigation modes (such as cycling through links, see e.g. tabindex [HTML5]).

Regardless of your stance on which is right, I am frustrated with Mozilla’s decision on keeping this bug active for such a long time — in the Canadian Province of Ontario, web accessibility is a legal requirement and companies and other organizations of a certain size must implement accessible websites that follow WCAG level A. Making web sites accessible is also a legal requirement is other parts of the world as well. While probably having good intentions, Mozilla has made it impossible for developers to create designs using the CSS order property that are truly accessible across all browsers without JavaScript. As a developer who cares about accessibility (as well as the legal well-being of his clients) I hope someone from Mozilla reads this article and helps developers out by fixing this bug.

I am not saying visual order should or shouldn’t affect tabbing order — I have seen some great arguments for the “Tabbing order should be the same as visual order” argument. I just think that Mozilla should try to change the standard instead of making a decision that breaks cross-browser accessibility.

Acknowledgments