From e6789f04a75d05e3e3e92f079a1b499d60a0ed37 Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Mon, 20 Jul 2020 16:34:35 +0200 Subject: [PATCH] Fix Copy block button focus loss and try to remove the visually hidden textarea (#24022) --- packages/compose/src/hooks/use-copy-on-click/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/compose/src/hooks/use-copy-on-click/index.js b/packages/compose/src/hooks/use-copy-on-click/index.js index 950006787b3a6..7071ea20bec88 100644 --- a/packages/compose/src/hooks/use-copy-on-click/index.js +++ b/packages/compose/src/hooks/use-copy-on-click/index.js @@ -32,12 +32,17 @@ export default function useCopyOnClick( ref, text, timeout = 4000 ) { container: ref.current, } ); - clipboard.current.on( 'success', ( { clearSelection } ) => { + clipboard.current.on( 'success', ( { clearSelection, trigger } ) => { // Clearing selection will move focus back to the triggering button, // ensuring that it is not reset to the body, and further that it is // kept within the rendered node. clearSelection(); + // Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680 + if ( trigger ) { + trigger.focus(); + } + if ( timeout ) { setHasCopied( true ); clearTimeout( timeoutId );