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