Skip to content

Commit

Permalink
fix(v2): @theme/heading should not create anchor if id is not defined (
Browse files Browse the repository at this point in the history
  • Loading branch information
endiliey authored Nov 2, 2019
1 parent 0baaad3 commit c41c19e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
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;

0 comments on commit c41c19e

Please sign in to comment.