-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Improve click event handler accessibility warning #8001
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
Comments
This is not the only a11y warning where the text itself ironically is anything but accessible. This sounds almost like legal speak. They are using words such as "must be" or "cannot", but technically that's not true at all. Of course I can have a positive tabIndex (#7953), but it makes it less accessible. And I surely don't need to add any Even just rewording the current text without adding any new information makes it so much more accessible and friendly:
Now this is still confusing as hell (see #7958), so let's add some more context:
Much better. But even this leaves question marks even in my own face. Is |
Actually, |
As well as key handlers and tabindex you also need to add an appropriate All operable elements must have machine-readable accessible names, semantic roles and (if applicable) state values to conform with WCAG SC 4.1.2 Name, Role, Value. |
Something I also discovered here, leaving in case useful for others. If you change eg a |
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-type
|
Good catch @archiewood . So, a warning about the submit functionality would only be appropriate if the button is a descendant of a form, right? BTW. The default behavior when pressing SPACE is to scroll the document unless an operable element (such as a button) is in focus, in which case, a click event should be sent to the element. This is handled automatically by user agents, without extra code if you use Ideally, any warning should "nudge" developers towards best practices: i.e. the first choice should be to use an element that is operable and focusable by default, namely BTW: The reason |
It seems that there is a lot of knowledge required to be able to fix this error. Unfortunately that is something most developers will not have and even those who would love to comply will struggle, and the results may actually be worse than ignoring it. The more I have searched for help the harder it seems to be to fix this. The fundamental problem seems to be that html was invented as a publishing/reading medium and it is now being used as an interactive UI. To only have two clickable elements "A" and "BUTTON" seems a bit lacking. DIV is a block element that comes with no styling unlike P. We need a DIV equivalent for BUTTON, ie something recognised as clickable but without the styling of buttons and then readers could handle it intelligently. That is something for HTML standards to sort out. But in the meantime, it would be nice if Svelte could offer something like <svlelte:interactive class="listitem" on:click={openitem}>Item text</svlelte:interactive> The element would handle the boilerplate things that need to be done for an clickable element and ask the developer to provide attribute values if these are needed (things like alt text or role whatever cannot be determined generically). This would be a win win win as it is good for accessibility, developers and svelte. |
I don't really see the problem. You can style buttons however you want, including the removal of all styling, and they can contain just about any content, including divs. |
That is how I have approached it; just use buttons and remove styling. We could also get rid of DIVs out HTML and just use P and remove the styling too. It's just a question of semantics and convenience. |
You cannot get rid of divs precisely because of the semantics. (Sorry for being a bit off-topic here.) |
The non-semantics of div (and span) are a feature not a bug. They allow content to be structured and ordered (important for meeting WCAG's "Meaningful Sequence" criterion ) without cluttering the accessibility tree, and of course they provide valuable hooks for visual presentation (especially for CSS selectors). Using Various articles and stack overflow posts cover the topic of overriding user agent style for Using div or span as operable elements without providing cues (i.e. role, tabindex and event handlers) for assistive tech users is simply a developer mistake (or -dare I say- just developer ignorance). The error text should briefly capture the essence of this guidance. |
I tracked down the location of the message:
|
@benmccann Is that a subtle suggestion that someone should just go ahead and change it already? 😅 |
too late: #9358 |
My IDE complains
This is exactly how I feel right now! |
You can put the button in the heading instead. Information on what elements can contain can be found on MDN or in the specification.
For headings it's also phrasing content. List of elements from MDN
A few other elements belong to this category, but only if a specific condition is fulfilled:
If you combine elements the wrong way, your page will sometimes just break. |
Describe the problem
There is a this warning when adding a
click
event handler to non-interactive elements:For users that do not know what this is really about, the only clear instruction here is: Add more event handlers.
Which is backwards and will not even work half of the time because the element would also have to be focusable and semantics will still be missing for screen readers.
Describe the proposed solution
Start the warning with a suggestion to use the appropriate elements:
Use a
button
element for actions, use ana
element for navigation.A note on
button
behavior in forms may be helpful. I.e. the defaulttype
of buttons issubmit
and that one might want to addtype="button"
to change this.(The documentation for the warning should also include this as the primary suggestion.)
Alternatives considered
N/A
Importance
nice to have
The text was updated successfully, but these errors were encountered: