Skip to content

Commit

Permalink
Cleaned up comments and function name.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeryj committed Jan 21, 2020
1 parent c9a2185 commit cc5cd14
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,18 @@ function NavigationLinkEdit( {
// close the link
setIsLinkOpen( false );
// focus the label
focusLabel();
selectLabelText();
}
}, [ url ] );

/**
* Focus the navigation link label text.
* Focus the navigation link label text and select it.
*/
function focusLabel( ) {
// select all the text and place cursor at the end (although you can't see it).
function selectLabelText( ) {
ref.current.focus();

const selection = window.getSelection();
const range = document.createRange();

// Get the range of the current ref contents so we can add this range to the selection.
range.selectNodeContents( ref.current );
selection.removeAllRanges();
selection.addRange( range );
Expand Down

0 comments on commit cc5cd14

Please sign in to comment.