Skip to content

Commit

Permalink
Only render InserterWithShortcuts on hover
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Dec 3, 2018
1 parent 68367b4 commit fd629c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 11 additions & 3 deletions packages/editor/src/components/default-block-appender/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import TextareaAutosize from 'react-autosize-textarea';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { compose } from '@wordpress/compose';
import { compose, withState } from '@wordpress/compose';
import { getDefaultBlockName } from '@wordpress/blocks';
import { decodeEntities } from '@wordpress/html-entities';
import { withSelect, withDispatch } from '@wordpress/data';
Expand All @@ -26,6 +26,8 @@ export function DefaultBlockAppender( {
showPrompt,
placeholder,
rootClientId,
hovered,
setState,
} ) {
if ( isLocked || ! isVisible ) {
return null;
Expand All @@ -49,7 +51,12 @@ export function DefaultBlockAppender( {
// The wp-block className is important for editor styles.

return (
<div data-root-client-id={ rootClientId || '' } className="wp-block editor-default-block-appender">
<div
data-root-client-id={ rootClientId || '' }
className="wp-block editor-default-block-appender"
onMouseEnter={ () => setState( { hovered: true } ) }
onMouseLeave={ () => setState( { hovered: false } ) }
>
<BlockDropZone rootClientId={ rootClientId } />
<TextareaAutosize
role="button"
Expand All @@ -59,12 +66,13 @@ export function DefaultBlockAppender( {
onFocus={ onAppend }
value={ showPrompt ? value : '' }
/>
<InserterWithShortcuts rootClientId={ rootClientId } />
{ hovered && <InserterWithShortcuts rootClientId={ rootClientId } /> }
<Inserter position="top right" />
</div>
);
}
export default compose(
withState( { hovered: false } ),
withSelect( ( select, ownProps ) => {
const { getBlockCount, getBlockName, isBlockValid, getEditorSettings, getTemplateLock } = select( 'core/editor' );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports[`DefaultBlockAppender should append a default block when input focused 1
<div
className="wp-block editor-default-block-appender"
data-root-client-id=""
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<WithDispatch(WithSelect(WithFilters(BlockDropZone))) />
<TextareaAutosize
Expand All @@ -22,7 +24,6 @@ exports[`DefaultBlockAppender should append a default block when input focused 1
rows={1}
value="Start writing or type / to choose a block"
/>
<WithSelect(WithDispatch(InserterWithShortcuts)) />
<WithSelect(IfCondition(Inserter))
position="top right"
/>
Expand All @@ -33,6 +34,8 @@ exports[`DefaultBlockAppender should match snapshot 1`] = `
<div
className="wp-block editor-default-block-appender"
data-root-client-id=""
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<WithDispatch(WithSelect(WithFilters(BlockDropZone))) />
<TextareaAutosize
Expand All @@ -44,7 +47,6 @@ exports[`DefaultBlockAppender should match snapshot 1`] = `
rows={1}
value="Start writing or type / to choose a block"
/>
<WithSelect(WithDispatch(InserterWithShortcuts)) />
<WithSelect(IfCondition(Inserter))
position="top right"
/>
Expand All @@ -55,6 +57,8 @@ exports[`DefaultBlockAppender should optionally show without prompt 1`] = `
<div
className="wp-block editor-default-block-appender"
data-root-client-id=""
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<WithDispatch(WithSelect(WithFilters(BlockDropZone))) />
<TextareaAutosize
Expand All @@ -66,7 +70,6 @@ exports[`DefaultBlockAppender should optionally show without prompt 1`] = `
rows={1}
value=""
/>
<WithSelect(WithDispatch(InserterWithShortcuts)) />
<WithSelect(IfCondition(Inserter))
position="top right"
/>
Expand Down

0 comments on commit fd629c5

Please sign in to comment.