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 authored Oct 30, 2019
2 parents 2694435 + 0cc8fd3 commit 536a0bd
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 @@ -54,9 +54,14 @@ export const DocsContainer: FunctionComponent<DocsContainerProps> = ({ 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',
});
}
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 @@ -272,7 +272,7 @@ export default function start(render, { decorateStory } = {}) {
previousViewMode = viewMode;
previousId = id;

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

1 comment on commit 536a0bd

@vercel
Copy link

@vercel vercel bot commented on 536a0bd Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.