Skip to content

Commit

Permalink
Dismiss inline toolbar by blur
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Jul 17, 2017
1 parent 8bc5077 commit d1b2a67
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions blocks/editable/index.js
Expand Up @@ -78,6 +78,7 @@ export default class Editable extends Component {
editor.on( 'nodechange', this.onNodeChange );
editor.on( 'keydown', this.onKeyDown );
editor.on( 'keyup', this.onKeyUp );
editor.on( 'blur', this.props.onBlur );
editor.on( 'selectionChange', this.onSelectionChange );
editor.on( 'PastePostProcess', this.onPastePostProcess );

Expand Down
9 changes: 3 additions & 6 deletions blocks/library/image/index.js
Expand Up @@ -63,7 +63,7 @@ registerBlockType( 'core/image', {
}
},

edit( { attributes, setAttributes, focus, setFocus, className } ) {
edit( { attributes, setAttributes, focus, setFocus, clearFocus, className } ) {
const { url, alt, caption, align, id, href } = attributes;
const updateAlt = ( newAlt ) => setAttributes( { alt: newAlt } );
const updateAlignment = ( nextAlign ) => setAttributes( { align: nextAlign } );
Expand Down Expand Up @@ -160,9 +160,6 @@ registerBlockType( 'core/image', {
'is-transient': 0 === url.indexOf( 'blob:' ),
} );

// Disable reason: Each block can be selected by clicking on it

/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
return [
controls,
focus && (
Expand All @@ -175,21 +172,21 @@ registerBlockType( 'core/image', {
</InspectorControls>
),
<figure key="image" className={ classes }>
<img src={ url } alt={ alt } onClick={ setFocus } />
<img src={ url } alt={ alt } tabIndex="-1" />
{ ( caption && caption.length > 0 ) || !! focus ? (
<Editable
tagName="figcaption"
placeholder={ __( 'Write caption…' ) }
value={ caption }
focus={ focus && focus.editable === 'caption' ? focus : undefined }
onFocus={ focusCaption }
onBlur={ () => clearFocus() }
onChange={ ( value ) => setAttributes( { caption: value } ) }
inlineToolbar
/>
) : null }
</figure>,
];
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
},

save( { attributes } ) {
Expand Down
1 change: 1 addition & 0 deletions blocks/library/image/style.scss
Expand Up @@ -5,6 +5,7 @@
img {
display: block;
width: 100%;
outline: none;
}

&.is-transient img {
Expand Down
3 changes: 2 additions & 1 deletion editor/modes/visual-editor/block.js
Expand Up @@ -333,7 +333,7 @@ class VisualEditorBlock extends Component {
'is-showing-mobile-controls': showMobileControls,
} );

const { onMouseLeave, onFocus, onInsertBlocksAfter } = this.props;
const { onMouseLeave, onFocus, onDeselect, onInsertBlocksAfter } = this.props;

// Determine whether the block has props to apply to the wrapper.
let wrapperProps;
Expand Down Expand Up @@ -401,6 +401,7 @@ class VisualEditorBlock extends Component {
setAttributes={ this.setAttributes }
insertBlocksAfter={ onInsertBlocksAfter }
setFocus={ partial( onFocus, block.uid ) }
clearFocus={ onDeselect }
mergeBlocks={ this.mergeBlocks }
className={ classnames( className, block.attributes.className ) }
id={ block.uid }
Expand Down

0 comments on commit d1b2a67

Please sign in to comment.