Skip to content

Commit

Permalink
Fix Copy block button focus loss and try to remove the visually hidde…
Browse files Browse the repository at this point in the history
…n textarea (#24022)
  • Loading branch information
afercia authored Jul 20, 2020
1 parent ed31451 commit f1915cb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/compose/src/hooks/use-copy-on-click/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit f1915cb

Please sign in to comment.