Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ function useFocusAfterNavigate() {
if ( ! container || container.contains( activeElement ) ) {
return;
}
container.querySelector< HTMLElement >( '[role="region"]' )?.focus();
// The example sits inside a docs page, so scrolling the region into
// view would move the reader away from where they clicked.
container
.querySelector< HTMLElement >( '[role="region"]' )
?.focus( { preventScroll: true } );
Comment thread
ciampo marked this conversation as resolved.
Resolved
}, [ pathname ] );

return containerRef;
Expand Down Expand Up @@ -191,6 +195,10 @@ function createSettingsRouter( initialPath: string ) {
routeTree,
history: createBlockingMemoryHistory( initialPath ),
defaultNotFoundComponent: () => null,
// The router scrolls the window to the top after each navigation,
// which here is the docs page around the example. Returning false
// skips that, and `Page` keeps its own scroll inside the example.
scrollRestoration: () => false,
} );
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/*
* Layout containment makes the frame the containing block for the fixed
* overlays portalled into it, and clipping hides a drawer while it slides in.
* A fixed height makes `Page` scroll its own content, as it does in the admin,
* so navigating between pages of different lengths doesn't reflow the docs.
* Capping it at the viewport height keeps the whole example in view on short
* screens.
*/
.example {
position: relative;
min-block-size: 640px;
block-size: min(720px, 100dvh);
display: flex;
flex-direction: column;
contain: layout;
Expand Down
Loading