-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix Copy block button focus loss and try to remove the visually hidden textarea #24022
Conversation
Fixes #23994 |
Size Change: +12 B (0%) Total Size: 1.15 MB
ℹ️ View Unchanged
|
To clarify: I did try to call |
Question: Now that the implementation is based on Pinging @ellatrix and @gziolo as I saw you worked on this bit of code. |
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 fix is looking good for me. I don't know about the other suggestion. Hopefully, someone will chime in.
@afercia Could you open a separate issue with the remaining problems? The clipboard is removed after unmount, yes. |
I can open a separate issue, but that requires time. My time is very, very, limited. I'd appreciate if next time an issue gets closed when all the problems reported are actually fixed... |
@afercia So is everyone's... |
I just wanted to note that closing issues and merging PRs that don't fully solve the reported bugs don't help in spending our time in the best way. |
closes #23994
Description
This PR seeks to solve two issues with the Clipboard.js-powered "Copy" block button.
For more details, please see the related issue #23994
Notes
These behaviors are Clipboard.js bugs (or "features") that produce a sub-optimal experience for keyboard users and assistive technology users.
While working on recent changes in WordPress core I stumbled upon the same issues. See:
https://core.trac.wordpress.org/changeset/48233
https://core.trac.wordpress.org/changeset/48232
I also reported these two issues upstream:
zenorocha/clipboard.js#680
zenorocha/clipboard.js#684
In the meantime, I guess they can be fixed in our implementation.
1
The focus loss is fixed by explicitly setting the focus back on the button. See also similar fixes used in the core changesets linked above.
2
I'd greatly appreciate some help to fix the second issue.
Ideally, the visually hidden textarea should be removed on the copy action
success
. This is why I fixed it in core. Worth noting Clipboard.js re-adds the textarea at any click so removing it on success looks safe.However, I couldn't find a nice way to use the fix used in core also in
useCopyOnClick
.As far as I see,
clipboard.current.destroy();
is used in theuseEffect
cleanup but that's not enough.It should be called on success. I couldn't find a way to make it work other than adding one more timeout which I guess isn't ideal. Any help would be greatly appreciated.