Skip to content

Commit

Permalink
Clear selected block when clicking on the gray background (#35816)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 authored Oct 21, 2021
1 parent bd1a5b7 commit c715b4c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
8 changes: 8 additions & 0 deletions packages/edit-site/src/components/block-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
BlockTools,
__unstableBlockSettingsMenuFirstItem,
__unstableUseTypingObserver as useTypingObserver,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useMergeRefs, useViewportMatch } from '@wordpress/compose';

Expand Down Expand Up @@ -54,6 +55,7 @@ export default function BlockEditor( { setIsInserterOpen } ) {
const contentRef = useRef();
const mergedRefs = useMergeRefs( [ contentRef, useTypingObserver() ] );
const isMobileViewport = useViewportMatch( 'small', '<' );
const { clearSelectedBlock } = useDispatch( blockEditorStore );

const isTemplatePart = templateType === 'wp_template_part';

Expand Down Expand Up @@ -87,6 +89,12 @@ export default function BlockEditor( { setIsInserterOpen } ) {
'is-focus-mode': isTemplatePart,
} ) }
__unstableContentRef={ contentRef }
onClick={ ( event ) => {
// Clear selected block when clicking on the gray background.
if ( event.target === event.currentTarget ) {
clearSelectedBlock();
}
} }
>
<BackButton />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export default function ResizeHandle( { direction, resizeWidthBy } ) {
}

return (
<div className={ `resizable-editor__drag-handle is-${ direction }` }>
<>
<button
className="resizable-editor__drag-handle-button"
className={ `resizable-editor__drag-handle is-${ direction }` }
aria-label={ __( 'Drag to resize' ) }
aria-describedby={ `resizable-editor__resize-help-${ direction }` }
onKeyDown={ handleKeyDown }
Expand All @@ -35,6 +35,6 @@ export default function ResizeHandle( { direction, resizeWidthBy } ) {
>
{ __( 'Use left and right arrow keys to resize the canvas.' ) }
</VisuallyHidden>
</div>
</>
);
}
27 changes: 10 additions & 17 deletions packages/edit-site/src/components/block-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,12 @@
}

.resizable-editor__drag-handle {
$height: 100px;
position: absolute;
top: 0;
bottom: 0;
width: $grid-unit-60;

&.is-left {
left: -$grid-unit-60;
}

&.is-right {
right: -$grid-unit-60;
}
}

.resizable-editor__drag-handle-button {
$height: 100px;
position: absolute;
top: calc(50% - #{math.div($height, 2)});
left: 50%;
transform: translateX(-$grid-unit-05);
padding: 0;
margin: auto 0;
width: $grid-unit-10;
height: $height;
appearance: none;
Expand All @@ -71,6 +56,14 @@
border-radius: 4px;
border: 0;

&.is-left {
left: #{-$grid-unit-30 - $grid-unit-05};
}

&.is-right {
right: #{-$grid-unit-30 - $grid-unit-05};
}

&:hover {
background: $gray-600;
}
Expand Down

0 comments on commit c715b4c

Please sign in to comment.