Skip to content

Commit

Permalink
Multi-selection: fix clearing with side click
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jan 23, 2020
1 parent dcb08f3 commit 87d0857
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const FocusCapture = forwardRef( ( {
containerRef,
noCapture,
hasMultiSelection,
multiSelectionContainer,
}, ref ) => {
const isNavigationMode = useSelect( ( select ) =>
select( 'core/block-editor' ).isNavigationMode()
Expand All @@ -54,7 +55,7 @@ const FocusCapture = forwardRef( ( {
// depending on the direction.
if ( ! selectedClientId ) {
if ( hasMultiSelection ) {
containerRef.current.focus();
multiSelectionContainer.current.focus();
return;
}

Expand Down
17 changes: 13 additions & 4 deletions packages/block-editor/src/components/writing-flow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export default function WritingFlow( { children } ) {
const container = useRef();
const focusCaptureBeforeRef = useRef();
const focusCaptureAfterRef = useRef();
const multiSelectionContainer = useRef();

const entirelySelected = useRef();

Expand Down Expand Up @@ -385,7 +386,7 @@ export default function WritingFlow( { children } ) {
} else if ( isEscape ) {
setNavigationMode( true );
}
} else if ( hasMultiSelection && isTab && target === container.current ) {
} else if ( hasMultiSelection && isTab && target === multiSelectionContainer.current ) {
// See comment above.
noCapture.current = true;

Expand Down Expand Up @@ -501,7 +502,7 @@ export default function WritingFlow( { children } ) {

useEffect( () => {
if ( hasMultiSelection && ! isMultiSelecting ) {
container.current.focus();
multiSelectionContainer.current.focus();
}
}, [ hasMultiSelection, isMultiSelecting ] );

Expand All @@ -516,14 +517,21 @@ export default function WritingFlow( { children } ) {
containerRef={ container }
noCapture={ noCapture }
hasMultiSelection={ hasMultiSelection }
multiSelectionContainer={ multiSelectionContainer }
/>
<div
ref={ container }
onKeyDown={ onKeyDown }
onMouseDown={ onMouseDown }
tabIndex={ hasMultiSelection ? '0' : undefined }
aria-label={ hasMultiSelection ? __( 'Multiple selected blocks' ) : undefined }
>
<div
ref={ multiSelectionContainer }
tabIndex={ hasMultiSelection ? '0' : undefined }
aria-label={ hasMultiSelection ? __( 'Multiple selected blocks' ) : undefined }
// Needs to be positioned within the viewport, so focus to this
// element does not scroll the page.
style={ { position: 'fixed' } }
/>
{ children }
</div>
<FocusCapture
Expand All @@ -532,6 +540,7 @@ export default function WritingFlow( { children } ) {
containerRef={ container }
noCapture={ noCapture }
hasMultiSelection={ hasMultiSelection }
multiSelectionContainer={ multiSelectionContainer }
isReverse
/>
<div
Expand Down

0 comments on commit 87d0857

Please sign in to comment.