-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the inserter behave as a popover (#24429)
- Loading branch information
1 parent
1fdbab7
commit 4e5019e
Showing
8 changed files
with
151 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/edit-post/src/components/layout/popover-wrapper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
withConstrainedTabbing, | ||
withFocusReturn, | ||
withFocusOutside, | ||
} from '@wordpress/components'; | ||
import { Component } from '@wordpress/element'; | ||
import { ESCAPE } from '@wordpress/keycodes'; | ||
|
||
function stopPropagation( event ) { | ||
event.stopPropagation(); | ||
} | ||
|
||
const DetectOutside = withFocusOutside( | ||
class extends Component { | ||
handleFocusOutside( event ) { | ||
this.props.onFocusOutside( event ); | ||
} | ||
|
||
render() { | ||
return this.props.children; | ||
} | ||
} | ||
); | ||
|
||
const FocusManaged = withConstrainedTabbing( | ||
withFocusReturn( ( { children } ) => children ) | ||
); | ||
|
||
export default function PopoverWrapper( { onClose, children, className } ) { | ||
// Event handlers | ||
const maybeClose = ( event ) => { | ||
// Close on escape | ||
if ( event.keyCode === ESCAPE && onClose ) { | ||
event.stopPropagation(); | ||
onClose(); | ||
} | ||
}; | ||
|
||
// Disable reason: this stops certain events from propagating outside of the component. | ||
// - onMouseDown is disabled as this can cause interactions with other DOM elements | ||
/* eslint-disable jsx-a11y/no-static-element-interactions */ | ||
return ( | ||
<div | ||
className={ className } | ||
onKeyDown={ maybeClose } | ||
onMouseDown={ stopPropagation } | ||
> | ||
<DetectOutside onFocusOutside={ onClose }> | ||
<FocusManaged>{ children }</FocusManaged> | ||
</DetectOutside> | ||
</div> | ||
); | ||
/* eslint-enable jsx-a11y/no-static-element-interactions */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters