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

This commit is contained in:
Endi 2019-11-02 17:40:51 +07:00 committed by GitHub
parent 0baaad3365
commit c41c19e10c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 9 deletions

View file

@ -20,6 +20,7 @@ function Home() {
([#1860](https://github.com/facebook/Docusaurus/issues/1860)) ([#1860](https://github.com/facebook/Docusaurus/issues/1860))
### Bug Fixes ### 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. - 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. 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 ```js

View file

@ -11,7 +11,11 @@ import React from 'react';
import './styles.css'; import './styles.css';
const Heading = Tag => ({id, ...props}) => ( const Heading = Tag => ({id, ...props}) => {
if (!id) {
return <Tag {...props} />;
}
return (
<Tag {...props}> <Tag {...props}>
<a aria-hidden="true" className="anchor" id={id} /> <a aria-hidden="true" className="anchor" id={id} />
<a aria-hidden="true" className="hash-link" href={`#${id}`}> <a aria-hidden="true" className="hash-link" href={`#${id}`}>
@ -19,6 +23,7 @@ const Heading = Tag => ({id, ...props}) => (
</a> </a>
{props.children} {props.children}
</Tag> </Tag>
); );
};
export default Heading; export default Heading;