Skip to content
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
10 changes: 6 additions & 4 deletions code/addons/docs/template/stories/docs2/UtfSymbolScroll.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { Meta } from '@storybook/addon-docs/blocks';

> Instruction below works only in iframe.html. Unknown code in normal mode (with manager) removes hash from url.

Click on [link](#anchor-with-utf-symbols-абвг). That will jump scroll to anchor after green block below. Then reload page and
it should smooth-scroll to that anchor.
Click on [link](#anchor-with-utf-symbols-абвг). That will jump scroll to anchor after green block below. Then reload page and
it should smooth-scroll to that anchor.

<div style={{ height: "1500px", background: "green", color: "white" }}>Space for scroll test</div>
<div style={{ height: "1500px", background: "green", color: "white" }}>
Space for scroll test
</div>

## Anchor with utf symbols (абвг)
## Anchor with utf symbols (абвг)
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ export class PreviewWithSelection<TRenderer extends Renderer> extends Preview<TR
);
} else {
this.currentRender.renderToElement(
this.view.prepareForDocs(),
this.view.prepareForDocs({ scrollReset: storyIdChanged || viewModeChanged }),
// This argument is used for docs, which is currently only compatible with HTMLElements
this.renderStoryToElement.bind(this) as any
);
Expand Down
2 changes: 1 addition & 1 deletion code/core/src/preview-api/modules/preview-web/View.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface View<TStorybookRoot> {
// Get ready to render a story, returning the element to render to
prepareForStory(story: PreparedStory<any>): TStorybookRoot;

prepareForDocs(): TStorybookRoot;
prepareForDocs(options?: { scrollReset?: boolean }): TStorybookRoot;

showErrorDisplay(err: { message?: string; stack?: string }): void;

Expand Down
12 changes: 9 additions & 3 deletions code/core/src/preview-api/modules/preview-web/WebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,19 @@ export class WebView implements View<HTMLElement> {
return document.getElementById('storybook-root')!;
}

prepareForDocs() {
prepareForDocs({ scrollReset = true }: { scrollReset?: boolean } = {}) {
this.showMain();
this.showDocs();
this.applyLayout('fullscreen');

document.documentElement.scrollTop = 0;
document.documentElement.scrollLeft = 0;
// Only reset scroll when navigating to a new docs page, not on HMR re-renders.
// Without this guard, hot-reloading a story file while scrolled down on a docs page
// causes the page to jump back to the top.

if (scrollReset) {
document.documentElement.scrollTop = 0;
document.documentElement.scrollLeft = 0;
}

return this.docsRoot();
}
Expand Down
Loading