Skip to content

Commit

Permalink
Code Quality: Improve URLInput onFocus method implementation (#20220)
Browse files Browse the repository at this point in the history
* Previously, onFocus got the input value from the focus event, when it should be the same as the this.props.value. I removed the event argument and am getting the input value from this.props.value
* onFocus allowed an onFocus method to be passed in. This isn't necessary, so it has been removed.
* Removed use of onFocus from LinkControl search-input
* Check for isUpdatingSuggestions in onFocus
  • Loading branch information
jeryj authored Feb 14, 2020
1 parent 8e7f7b1 commit e6603a6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ const LinkControlSearchInput = ( {
className="block-editor-link-control__search-input"
value={ value }
onChange={ selectItemHandler }
onFocus={ selectItemHandler }
onKeyDown={ ( event ) => {
if ( event.keyCode === ENTER ) {
return;
Expand Down
13 changes: 5 additions & 8 deletions packages/block-editor/src/components/url-input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,20 @@ class URLInput extends Component {
}
}

onFocus( event ) {
onFocus() {
const { suggestions } = this.state;
const { disableSuggestions, onFocus } = this.props;

const inputValue = event.target.value;

onFocus( inputValue );
const { disableSuggestions, value } = this.props;

// When opening the link editor, if there's a value present, we want to load the suggestions pane with the results for this input search value
// Don't re-run the suggestions on focus if there are already suggestions present (prevents searching again when tabbing between the input and buttons)
if (
inputValue &&
value &&
! disableSuggestions &&
! this.isUpdatingSuggestions &&
! ( suggestions && suggestions.length )
) {
// Ensure the suggestions are updated with the current input value
this.updateSuggestions( inputValue );
this.updateSuggestions( value );
}
}

Expand Down

0 comments on commit e6603a6

Please sign in to comment.