diff --git a/storybook/stories/design-system/patterns/settings-page/router.tsx b/storybook/stories/design-system/patterns/settings-page/router.tsx index dccf2d4678906f..1b261b7ba2b245 100644 --- a/storybook/stories/design-system/patterns/settings-page/router.tsx +++ b/storybook/stories/design-system/patterns/settings-page/router.tsx @@ -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 } ); }, [ pathname ] ); return containerRef; @@ -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, } ); } diff --git a/storybook/stories/design-system/patterns/settings-page/style.module.css b/storybook/stories/design-system/patterns/settings-page/style.module.css index 87fcc7fad638cc..db74f3f73e78ce 100644 --- a/storybook/stories/design-system/patterns/settings-page/style.module.css +++ b/storybook/stories/design-system/patterns/settings-page/style.module.css @@ -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;