Skip to content

Commit

Permalink
Format Library: Refactor inline link to use onFocusOutside
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed May 22, 2019
1 parent 36416be commit 6419f0d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions packages/format-library/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

### Internal

- The inline link component has been refactored to focus changes using the `Popover` component's `onFocusOutside` prop.

## 1.2.10 (2019-01-03)

## 1.2.9 (2018-12-18)
Expand Down
10 changes: 5 additions & 5 deletions packages/format-library/src/link/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class InlineLinkUI extends Component {
this.onKeyDown = this.onKeyDown.bind( this );
this.onChangeInputValue = this.onChangeInputValue.bind( this );
this.setLinkTarget = this.setLinkTarget.bind( this );
this.onClickOutside = this.onClickOutside.bind( this );
this.onFocusOutside = this.onFocusOutside.bind( this );
this.resetState = this.resetState.bind( this );
this.autocompleteRef = createRef();

Expand Down Expand Up @@ -226,13 +226,13 @@ class InlineLinkUI extends Component {
}
}

onClickOutside( event ) {
onFocusOutside() {
// The autocomplete suggestions list renders in a separate popover (in a portal),
// so onClickOutside fails to detect that a click on a suggestion occurred in the
// so onFocusOutside fails to detect that a click on a suggestion occurred in the
// LinkContainer. Detect clicks on autocomplete suggestions using a ref here, and
// return to avoid the popover being closed.
const autocompleteElement = this.autocompleteRef.current;
if ( autocompleteElement && autocompleteElement.contains( event.target ) ) {
if ( autocompleteElement && autocompleteElement.contains( document.activeElement ) ) {
return;
}

Expand All @@ -259,7 +259,7 @@ class InlineLinkUI extends Component {
value={ value }
isActive={ isActive }
addingLink={ addingLink }
onClickOutside={ this.onClickOutside }
onFocusOutside={ this.onFocusOutside }
onClose={ this.resetState }
focusOnMount={ showInput ? 'firstElement' : false }
renderSettings={ () => (
Expand Down

0 comments on commit 6419f0d

Please sign in to comment.