Calling e.clearSelection()
on success doesn't move focus back to the trigger
#680
Labels
e.clearSelection()
on success doesn't move focus back to the trigger
#680
Minimal example
See https://jsfiddle.net/fsvqda6j/1/
Expected behaviour
Focus to be moved back to the trigger.
Actual behaviour
Focus stays on the input / textarea
Browsers affected
N/A
Additional context
Following the example from https://clipboardjs.com/#events seems to me
clearSelection()
is meant to be used on success. At that point, the text is copied and there's no need to keep the selection for further action with Ctrl / Cmd + C.Looking at
clipboard.js/src/clipboard-action.js
Lines 133 to 142 in 26a8d63
seems to me blurring the active element should happen first. This was added in 83824fa. At that point, the active element is actually the trigger button (if any) so what happens is:
document.activeElement
For better accessibility, there should always be a focused element otherwise a focus loss happens. Focus losses are one of the most frustrating experiences for keyboard users and assistive technology users.
To my understanding, to make sure there's always a focused element, the call to
blur()
should be moved within the check forthis.trigger
and beforethis.trigger.focus();
.For what is worth, I'm a regular contributor (and core committer) in the WordPress.org project where we try to make things as accessible as possible. We do use ClipboardJS and we'd like to use it in more places 🙂
The text was updated successfully, but these errors were encountered: