#50322 closed defect (bug) (fixed)
Site Health "copy info" button: fix focus loss and other improvements
Reported by: | afercia | Owned by: | afercia |
---|---|---|---|
Milestone: | 5.5 | Priority: | normal |
Severity: | normal | Version: | 5.2 |
Component: | Site Health | Keywords: | has-patch commit has-screenshots |
Focuses: | accessibility | Cc: |
Description
While reviewing #48463 I looked into this implementation of ClipboardJS
and noticed a few things to fix or improve:
- go to the Site Health > Info page
- use the Tab key and navigate to the "Copy site info to clipboard" button
- press Enter
- observe focus isn't on the button any longer
- actually, focus moved to the visually hidden textarea used by
ClipboardJS
ClipboardJS
provides events to implement custom behaviors, see https://clipboardjs.com/#events for an example- the built-in
clearSelection()
function is meant to clear the selection and move focus back to the button that triggered the copy action - this method should have been used since the beginning...
- ...if it only worked... actually it's buggy and I created a new issue upstream, see https://github.com/zenorocha/clipboard.js/issues/680
- for now, the buggy behavior can be remediated by moving focus back in the site health implementation
Additionally:
- the "Copied!" text used for visual feedback stays there indefinitely
- if users click a second or third time or more, actually there's no _new_ feedback because the previous text is still there
- I'd like to propose to make this text disappear atter a few seconds since last successful copy action
- the CSS could be slightly simplified
I'd like to propose to fix this for 5.5 so that there's a good implementation example that can be used in other places in core. For now, there will be 2 maybe 3 cases where a "Copy" button is going to be used so I don't think it's really necessary to abstract this into some reusable code. If more use cases will arise in the future, some abstraction would be welcome.
Attachments (5)
Change History (21)
#5
@
5 years ago
One more problem with ClipboardJS
is that is that the visually hidden textarea used to actually select and copy the text stays there in the DOM right before the closing </body>
tag.
This way it's still focusable, can be navigated to via keyboard, and it's perceived and announced by screen readers when arrowing or when using other shortcuts to jump to form elements. See screenshot below.
To reproduce using the keyboard:
- press the Tab key to go to the "Copy site info..." button
- press Enter
- focus is moved to the visually hidden textarea
- press Shift + Tab to navigate back to the "stay updated" link in the admin footer
- press Tab: you just navigated to the visually hidden textarea
- press Tab again: keyboard navigation start from scratch (browser chrome then the document)
#6
@
5 years ago
50322.2.diff uses internal ClipboardJS
methods to remove the visually hidden textarea after 3 seconds since the last successful copy action.
ClipboardJS
takes care to re-add the textarea back each time the Copy button is clicked to the functionality works as expected.
Ideally, this should be reported upstream. Will do as soon as I have some time.
#8
@
4 years ago
For the records: I created this upstream issue: https://github.com/zenorocha/clipboard.js/issues/684 to propose to remove the visually hidden textarea that lingers in the DOM after a successful copy action.
50322.diff:
clearSelection()
function fromClipboardJS
setTimeout
/clearTimeout
to hide the "Copied!" visual feedback after 3 seconds since last successful copy actionTo Test: