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 and ellatrix committed Jul 20, 2020
1 parent 66d1d2d commit e6789f0
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 e6789f0

Please sign in to comment.