svelte: Plugin svelte: A11y: on:blur must be used instead of on:change, unless absolutely necessary and it causes no negative consequences for keyboard only or screen reader users.
I recently updated Svelte to latest version and this warning started to show up.
So I decided to try that out, change the on:change on some selects to on:blur, but they stopped working. It’s only after I click away from the select that the event gets triggered, simply selecting the option doesn’t do it.
I know I can simply ignore these, but I wanted to see if I can actually go ahead with this recommendation, maybe I’m doing something wrong. Thanks!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 14
- Comments: 16 (7 by maintainers)
Commits related to this issue
- svelte: ignore a11y-no-onchange warnings as there is a growing consensus that this rule should be removed see https://github.com/sveltejs/svelte/issues/4946#issuecomment-754750711 — committed to inventaire/inventaire-client by maxlath 3 years ago
- svelte: ignore a11y-no-onchange warnings as there is a growing consensus that this rule should be removed see https://github.com/sveltejs/svelte/issues/4946#issuecomment-754750711 — committed to inventaire/inventaire-client by maxlath 3 years ago
I disabled it by putting a comment one line above the warning:
Edit: added select to example
Imo, this rule should be removed.
The original reasoning behind this rule seemed to be that IE fired the change event when navigating between options with the arrow keys. From the linked article in the jsx-a11y docs:
This was from 2004 and seems to be out of date now. I wrote a quick CodePen to see when the change event is fired for a
<select>and tested in IE11, Chrome, and Firefox. In all browsers tested, tabbing to the select, opening the menu with Space, and using the arrow keys to navigate between different items did not fire a change event. A change event was only fired when an item was selected with Enter or if the arrow keys were used to select an option without opening the menu.While older versions of IE may have made this necessary, I don’t think it’s reasonable to enforce a warning for all developers that only applies to a very small subset of people supporting IE < 11.
tl;dr the jsx-a11y this was based on is now deprecated. The rationale is many years old now and not applicable to most use cases when using a modern browser or IE11.
Something I just realized while interacting with this warning — wouldn’t this imply that
bind:valueis also inadvertently breaking thea11yrule? I was helping someone “fix” this warning and our answer was to swap to usingbind:valueinstead (which was the better choice anyway/more Svelte-y). But it did get me thinking about what it was doing behind the scenes and sure enough — it’s achangelistener!There’s a webaim.org mailing thread that discusses this issue: https://webaim.org/discussion/mail_thread?thread=8036
Quoting the reply:
Thanks, this warning is way over the top. It’s absolutely untrue that it doesn’t change anything for desktop.
How do I disable this warning… on:blur does not work for my use case. It is annoying to see on Visual Studio Code.
Edit your
rollup.config.jslike this. This will give you the opportunity to add more warnings later on.Ah, I see. Here’s the official (as far as I’ve been able to find) rule that the Svelte one was adapted from: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-onchange.md.
Really, I think there’s frustratingly little guidance on this rule. It’s a big change from what most web developers currently do and the description of the rule is extremely vague on when it’s ok to use onchange or not if you aren’t already an accessibility expert. The link I posted above has two article links, one of which is dead and the other which is 15 years old: http://www.themaninblue.com/writing/perspective/2004/10/19/
That article is basically is making the case against doing what I mentioned in the last paragraph of my previous comment. This was common back in 2004 when select menus were often used as a kind of simple dropdown navigation, and selecting an option would trigger a page change. But I think that kind of behavior is pretty rare today though.
So I would just sum this one up as “make sure your select’s on:change handler is friendly to keyboard users” and keep on using on:change. I think that’s what I’m going to do.
How would you ignore this warning if you are running Webpack?
My understanding is that’s the behavior change you described is actually the entire point of using
on:bluras opposed toon:change.If the user is accessing the select control with a keyboard, then as they go through the options in the select menu,
on:changewill be fired for each one. But if you useblur, then you only look at the value of the select once it has closed, so you aren’t taking action against intermediate values that the user didn’t want to select.I’m not an a11y expert, but I think so long as you don’t do anything unreasonable in your
changehandler, like making large alterations to the page layout, triggering a bunch of network queries, or anything that might cause the select menu to close, then you’re just fine continuing to useon:change.