Skip to content

Commit

Permalink
fix button link modal not closing (#3508)
Browse files Browse the repository at this point in the history
* fix button link modal not closing

* reseting selectedSuggestion on select and refactoring
  • Loading branch information
vladanost authored and aduth committed Nov 21, 2017
1 parent d1c4d29 commit 359f11f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions blocks/url-input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,20 @@ class UrlInput extends Component {
if ( this.state.selectedSuggestion ) {
event.stopPropagation();
const post = this.state.posts[ this.state.selectedSuggestion ];
this.props.onChange( post.link );
this.setState( {
showSuggestions: false,
} );
this.selectLink( post.link );
}
}
}
}

selectLink( link ) {
this.props.onChange( link );
this.setState( {
selectedSuggestion: null,
showSuggestions: false,
} );
}

componentWillUnmount() {
if ( this.suggestionsRequest ) {
this.suggestionsRequest.abort();
Expand Down Expand Up @@ -212,7 +217,7 @@ class UrlInput extends Component {
className={ classnames( 'blocks-url-input__suggestion', {
'is-selected': index === selectedSuggestion,
} ) }
onClick={ () => this.props.onChange( post.link ) }
onClick={ () => this.selectLink( post.link ) }
aria-selected={ index === selectedSuggestion }
>
{ post.title.rendered || __( '(no title)' ) }
Expand Down

0 comments on commit 359f11f

Please sign in to comment.