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

fix(v2): @theme/heading should not create anchor if id is not defined #1925

Merged
merged 1 commit into from
Nov 2, 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
1 change: 1 addition & 0 deletions CHANGELOG-2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function Home() {
([#1860](https://github.com/facebook/Docusaurus/issues/1860))

### Bug Fixes
- Fix MDX `@theme/Heading` component. If there is no id, it should not create anchor link.
- Fixed a bug in which if `themeConfig.algolia` is not defined, the custom searchbar won't appear.
If you've swizzled Algolia `SearchBar` component before, please update your source code otherwise CSS might break. See [#1909](https://github.com/facebook/docusaurus/pull/1909/files) for reference.
```js
Expand Down
23 changes: 14 additions & 9 deletions packages/docusaurus-theme-classic/src/theme/Heading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ import React from 'react';

import './styles.css';

const Heading = Tag => ({id, ...props}) => (
<Tag {...props}>
<a aria-hidden="true" className="anchor" id={id} />
<a aria-hidden="true" className="hash-link" href={`#${id}`}>
#
</a>
{props.children}
</Tag>
);
const Heading = Tag => ({id, ...props}) => {
if (!id) {
return <Tag {...props} />;
}
return (
<Tag {...props}>
<a aria-hidden="true" className="anchor" id={id} />
<a aria-hidden="true" className="hash-link" href={`#${id}`}>
#
</a>
{props.children}
</Tag>
);
};

export default Heading;