Skip to content

Commit

Permalink
Addon-docs: Fix story scroll-to heuristics (#8629)
Browse files Browse the repository at this point in the history
Addon-docs: Fix story scroll-to heuristics
  • Loading branch information
shilman committed Nov 9, 2019
1 parent 05d064d commit 629119c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion addons/docs/src/blocks/DocsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ export const DocsContainer: React.FunctionComponent<DocsContainerProps> = ({
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',
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/client/preview/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export default function start(render, { decorateStory } = {}) {
previousViewMode = viewMode;
previousId = id;

if (!forceRender) {
if (!forceRender && viewMode !== 'docs') {
document.documentElement.scrollTop = 0;
}
};
Expand Down

0 comments on commit 629119c

Please sign in to comment.