From 0cc8fd37cd8e688cf77ddf87a7317b6fb6264ab2 Mon Sep 17 00:00:00 2001 From: Thomas Allmer Date: Tue, 29 Oct 2019 23:50:17 +0100 Subject: [PATCH] fix(docs): scroll from story to story not always from top --- addons/docs/src/blocks/DocsContainer.tsx | 7 ++++++- lib/core/src/client/preview/start.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/docs/src/blocks/DocsContainer.tsx b/addons/docs/src/blocks/DocsContainer.tsx index 5d302106994d..a415bac0b7d1 100644 --- a/addons/docs/src/blocks/DocsContainer.tsx +++ b/addons/docs/src/blocks/DocsContainer.tsx @@ -54,9 +54,14 @@ export const DocsContainer: FunctionComponent = ({ context, element = document.getElementById(storyBlockIdFromId(storyId)); } if (element) { + const allStories = element.parentElement.querySelectorAll('[id|="anchor-"]'); + let block = 'start'; + if (allStories && allStories[0] === element) { + block = 'end'; // first story should be shown with the intro content above + } element.scrollIntoView({ behavior: 'smooth', - block: 'end', + block, inline: 'nearest', }); } diff --git a/lib/core/src/client/preview/start.js b/lib/core/src/client/preview/start.js index 1420c75b76f6..646ec16b42d6 100644 --- a/lib/core/src/client/preview/start.js +++ b/lib/core/src/client/preview/start.js @@ -270,7 +270,7 @@ export default function start(render, { decorateStory } = {}) { previousViewMode = viewMode; previousId = id; - if (!forceRender) { + if (!forceRender && viewMode !== 'docs') { document.documentElement.scrollTop = 0; } };