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] Linking to sections. #8184

Closed
ellisio opened this issue Sep 24, 2019 · 10 comments
Closed

[addon-docs] Linking to sections. #8184

ellisio opened this issue Sep 24, 2019 · 10 comments

Comments

@ellisio
Copy link

ellisio commented Sep 24, 2019

I am using @storybook/addon-docs@5.2.1. Is it possible to link to a header further in the document? We have sections that are quite long and would love to link between parts of the page.

GitHub Wiki markdown would be something like this:

<Meta title="Design System|Some Page" />

## Foo

Hey, check out [Bar][#Bar]

// Imagine several hundreds of lines of markdown here.

## Bar

This is Bar! Way below the page fold.

I know there is @storybook/addon-links, but I'm not sure that works in the MDX stories from what I've gathered poking through the GitHub issues here.

@shilman
Copy link
Member

shilman commented Sep 24, 2019

I'm not sure! MDX support is still early and we might need to add this in 5.3! 😅

@Fleuv
Copy link

Fleuv commented Nov 15, 2019

It's possible to do something like this:

## Foo

Hey, check out [Bar][#Bar]

// Imagine several hundreds of lines of markdown here.

## Bar <a id="Bar" />

This is Bar! Way below the page fold.

Some tests on Firefox v70

The href of the first anchor will be #Bar as expected, although for some reason after clicking the URL ends up using the iframe.html page:

http://localhost:6006/iframe.html?id=foo--bar&viewMode=docs#Bar

While I expected it to use the default index:

http://localhost:6006/?path=/docs/foo--bar#Bar

Also I noticed that neither the iframe.html as the default index page was capable of scrolling down to the target anchor on initial load. However at the iframe.html page I was able to scroll down to the target anchor by clicking the anchor with the href. This didn't work for the default index page after changing the href to the absolute url mentioned above.

Using LinkTo as mention in #8618 doesn't work at all.

@shilman
Copy link
Member

shilman commented Nov 15, 2019

Gadzooks!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.3.0-alpha.46 containing PR #8132 that references this issue. Upgrade today to try it out!

You can find this prerelease on the @next NPM tag.

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Nov 15, 2019
@shilman shilman reopened this Nov 15, 2019
@robbeman
Copy link

Using LinkTo as mention in #8618 doesn't work at all.

The question there was to link to another story, not to link to a page anchor. In my case it did work to link to other stories. I did not test anchors, so I'm sorry if I caused confusion on that part.

@shilman
Copy link
Member

shilman commented Dec 4, 2019

Ta-da!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.3.0-beta.15 containing PR #9051 that references this issue. Upgrade today to try it out!

You can find this prerelease on the @next NPM tag.

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Dec 4, 2019
@nik72619c
Copy link

Hi, could someone please link me to the sample code snippet to test it out ?

@lisamartin00
Copy link
Contributor

@nik72619c you should get anchors on headers for free on .mdx files. So for example, I can link to the props section of this story:
https://storybookjs.netlify.app/official-storybook/?path=/docs/addons-docs-mdx-id--hello-story#props

Or here's a way to add them globally based off of this example (although I'm super new to addon-docs, so maybe there's a better way):

preview.js

import { DocsContainer } from '@storybook/addon-docs/blocks';
import { addParameters } from "@storybook/react";
import DocsPageTemplate from '../src/DocsPageTemplate.mdx';

addParameters({
  docs: {
    container: DocsContainer,
    page: DocsPageTemplate,
  },
});

DocsPageTemplate.mdx

import {
  Title,
  Subtitle,
  Description,
  Primary,
  Props,
  Stories,
} from '@storybook/addon-docs/blocks';

<Title />

Hey there, [Props](#props) are below

<Subtitle />
<Description />
<Primary />

## Props
<Props />

<Stories />

@cgreene-st
Copy link

@lisamartin00 I'm not seeing it work the way I'd expect. Not sure if somethings changed since then, but If I go to click on ## Welcome it's stripping out the ?path part in the URL and brining me to an empty page.

I might create a ticket with a minimum reproducible bug because I don't think this is working as intended

image
image

@lisamartin00
Copy link
Contributor

lisamartin00 commented Dec 7, 2021

@cgreene-st yes I agree - that is easily reproducible on their site, so it's probably either a regression or anchors are handled differently now since it's been over a year. sounds like it's worth filing a separate ticket 👍

@cgreene-st
Copy link

For anyone that finds themselves here, the bug is being tracked here #16918

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants