diff --git a/site/theme/template/Content/ComponentDoc.jsx b/site/theme/template/Content/ComponentDoc.jsx index e85a59d8cc..35cf7f6a99 100644 --- a/site/theme/template/Content/ComponentDoc.jsx +++ b/site/theme/template/Content/ComponentDoc.jsx @@ -41,20 +41,19 @@ export default class ComponentDoc extends React.Component { demos.filter(demo => demo.meta.only) : demos.filter(demo => demo.preview); showedDemo.sort((a, b) => a.meta.order - b.meta.order) .forEach((demoData, index) => { + const demoElem = ( + + ); if (index % 2 === 0 || isSingleCol) { - leftChildren.push( - - ); + leftChildren.push(demoElem); } else { - rightChildren.push( - - ); + rightChildren.push(demoElem); } }); const expandTriggerClass = classNames({ diff --git a/site/theme/template/Content/Demo.jsx b/site/theme/template/Content/Demo.jsx index d65c53cdc4..4a99d1684e 100644 --- a/site/theme/template/Content/Demo.jsx +++ b/site/theme/template/Content/Demo.jsx @@ -22,10 +22,21 @@ export default class Demo extends React.Component { return (this.state.codeExpand || this.props.expand) !== (nextState.codeExpand || nextProps.expand); } + componentDidMount() { + const { meta, location } = this.props; + if (meta.id === location.hash.slice(1)) { + this.anchor.click(); + } + } + handleCodeExapnd = () => { this.setState({ codeExpand: !this.state.codeExpand }); } + saveAnchor = (anchor) => { + this.anchor = anchor; + } + render() { const props = this.props; const { @@ -70,7 +81,7 @@ export default class Demo extends React.Component {
- + {localizedTitle} } filename={meta.filename} />