-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add keyboard support and accessibility polyfill for IE11 & Edge #5
Conversation
- Add enter/space trigger - Add tabindex, aria-expanded, and role to summary
This all looks excellent and matches with the linked spec 👌 💯 |
else | ||
document.addEventListener "DOMNodeInserted", (event) -> | ||
if event.target.tagName is "SUMMARY" | ||
addAttributesForSummary event.target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, we'd only create a single MutationObserver
(or DOMNodeInserted
listener). Think this could be combined with the one in polyfillToggleEvent
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
polyfillToggleEvent
only get called when support.element and not support.toggleEvent
while polyfillFocusAndARIA
only get called when not support.element
, so only one MutationObserver
will ever get created. Do you think it's worth combining them still? The conditions make it a bit awkward when I tried. 🤔
addAttributesForSummary event.target | ||
|
||
addAttributesForSummary = (summary) -> | ||
details = findClosestElementWithTagName(summary, "DETAILS") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This closest
trip up the DOM could be avoided if the details
element was (optionally) passed too. You already have a reference to it in the mutation observer callback.
@@ -56,11 +56,37 @@ polyfillProperties = -> | |||
removeAttribute.call(this, name) | |||
|
|||
polyfillToggle = -> | |||
onTogglingClick (element) -> | |||
onTogglingTrigger (element) -> | |||
summary = element.querySelector "summary" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer using parens for function calls in CoffeeScript even though they're optional. Mind updating to follow that style throughout?
event.metaKey or | ||
event.shiftKey or | ||
event.target.isContentEditable | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is so similar to clickEventIsSignificant
, maybe there should be a single eventIsSignificant
function with the common parts. And the event handlers can check the unique parts, e.g.:
addEventListener "keydown", (event) ->
if eventIsSignificant(event)
if event.keyCode in [13, 32]
...
Thank you! And sorry for the delay in reviewing. These are welcomed improvements.
What did you try? Dispatching an event with the right properties (like |
Do you think it's appropriate for a polyfill to manage |
details = findClosestElementWithTagName(summary, "DETAILS") | ||
summary.setAttribute "tabindex", "0" | ||
summary.setAttribute "aria-expanded", details.hasAttribute("open") | ||
summary.setAttribute "role", "button" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably avoid overwriting these attributes if they're present initially:
summary.setAttribute("tabindex", "0") unless summary.hasAttribute("tabindex")
...
Something like this: http://jsbin.com/yatubamege/1/edit?js,console,output If it works,
I think this might be the cause. I tested in Safari & Firefox, the events don't work either, but I couldn't find any reference other than this one for Chrome.
I think it is. The attributes aren't present, but the characteristics they simulate are there, and these attributes were designed to add support for these characteristics. Thanks for the review ⭐ I made all the other changes. |
Thank you! I just released v2.0.0 with these changes. |
👋🏻 This follows the definitions in https://www.w3.org/TR/html-aam-1.0/#summary-and-details-elements:
And adds
aria-expanded
on<summary>
tabindex
androle
to<summary>
enter
andspace
trigger for<summary>
<summary>
being focusableIt'd be nice to test
addAttributesForSummary
whendetails
isn't supported. Is checking fornavigator.userAgent
intest.coffee
the only way?I also tried adding a test for
enter
/space
trigger, but the keydown event simulation doesn't seem to trigger the default action when I tested in Chrome 🤔.cc @josh @dgraham @keithamus