Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon-docs: Fix story scroll-to heuristics #8629

Merged
merged 1 commit into from
Oct 30, 2019
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
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 @@ -270,7 +270,7 @@ export default function start(render, { decorateStory } = {}) {
previousViewMode = viewMode;
previousId = id;

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