mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-03 12:17:20 +02:00
fix(v2): @theme/heading should not create anchor if id is not defined (#1925)
This commit is contained in:
parent
0baaad3365
commit
c41c19e10c
2 changed files with 15 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue