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 Table of Contents heading leak #23677

Merged
merged 5 commits into from
Feb 19, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions code/ui/blocks/src/components/TableOfContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,13 @@ export const TableOfContents = ({
tocSelector: '.toc-wrapper',
contentSelector: contentsSelector ?? '.sbdocs-content',
headingSelector: headingSelector ?? 'h3',
ignoreSelector: ignoreSelector ?? '.skip-toc',
headingsOffset: 40,
scrollSmoothOffset: -40,
/**
* Ignore headings that did not
* come from the main markdown code.
*/
// ignoreSelector: ':not(.sbdocs), .hide-from-toc',
ignoreSelector: ignoreSelector ?? '.docs-story *, .skip-toc',
Copy link
Contributor

Choose a reason for hiding this comment

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

@shilman — This approach seems sound to me, but you're the one who left the commented-out version to seemingly accomplish the same thing, so thought you'd like to chime in.

headingsOffset: 40,
scrollSmoothOffset: -40,
orderedList: false,
/**
* Prevent default linking behavior,
Expand Down
16 changes: 8 additions & 8 deletions docs/writing-docs/autodocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ Storybook's auto-generated documentation pages can be quite long and difficult t

By default, the table of contents on the documentation page will only show the `h3` headings that are automatically generated. However, if you want to customize the table of contents, you can add more parameters to the `toc` property. The following options and examples of how to use them are available.

| Option | Description |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `contentsSelector` | Defines the container's CSS selector for search for the headings <br/> `toc: { contentsSelector: '.sbdocs-content' }` |
| `disable` | Hides the table of contents for the documentation pages <br/> `toc: { disable: true }` |
| `headingSelector` | Defines the list of headings to feature in the table of contents <br/> `toc: { headingSelector: 'h1, h2, h3' }` |
| `ignoreSelector` | Configures the table of contents to ignore specific headings or stories <br/> `toc: { ignoreSelector: 'h2' }` |
| `title` | Defines a title caption for the table of contents. <br/>Accepts one of: `string`, `null`, React element <br/> `toc: { title: 'Table of Contents' }` |
| `unsafeTocbotOptions` | Provides additional [`TocBot`](https://tscanlin.github.io/tocbot/) configuration options <br/> `toc: { unsafeTocbotOptions: { orderedList: true } }` |
| Option | Description |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `contentsSelector` | Defines the container's CSS selector for search for the headings <br/> `toc: { contentsSelector: '.sbdocs-content' }` |
| `disable` | Hides the table of contents for the documentation pages <br/> `toc: { disable: true }` |
| `headingSelector` | Defines the list of headings to feature in the table of contents <br/> `toc: { headingSelector: 'h1, h2, h3' }` |
| `ignoreSelector` | Configures the table of contents to ignore specific headings or stories. By default, the table of contents will ignore all content placed within Story blocks <br/> `toc: { ignoreSelector: '.docs-story h2' }` |
| `title` | Defines a title caption for the table of contents. <br/>Accepts one of: `string`, `null`, React element <br/> `toc: { title: 'Table of Contents' }` |
| `unsafeTocbotOptions` | Provides additional [`TocBot`](https://tscanlin.github.io/tocbot/) configuration options <br/> `toc: { unsafeTocbotOptions: { orderedList: true } }` |

<Callout variant="info">

Expand Down