Skip to content

Commit

Permalink
Focus on canvas when there's no section root
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Nov 26, 2024
1 parent 2eceb24 commit ef210ef
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/block-editor/src/components/writing-flow/use-tab-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export default function useTabNav() {
const noCaptureRef = useRef();

function onFocusCapture( event ) {
const canvasElement =
container.current.ownerDocument === event.target.ownerDocument
? container.current
: container.current.ownerDocument.defaultView.frameElement;

// Do not capture incoming focus if set by us in WritingFlow.
if ( noCaptureRef.current ) {
noCaptureRef.current = null;
Expand Down Expand Up @@ -68,13 +73,11 @@ export default function useTabNav() {
container.current
.querySelector( `[data-block="${ sectionRootClientId }"]` )
.focus();
} else {
// If we don't have any section root, focus the canvas.
canvasElement.focus();
}
} else {
const canvasElement =
container.current.ownerDocument === event.target.ownerDocument
? container.current
: container.current.ownerDocument.defaultView.frameElement;

const isBefore =
// eslint-disable-next-line no-bitwise
event.target.compareDocumentPosition( canvasElement ) &
Expand Down

0 comments on commit ef210ef

Please sign in to comment.