Skip to content

Commit

Permalink
docs(Storybook): fix anchor click navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas742 committed Aug 10, 2022
1 parent 33683bb commit 0d30309
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ const ThemeProviderDecorator = makeDecorator({
useEffect(() => {
const onAnchorClick = (e) => {
const { hash } = e.currentTarget;
window.parent.location.replace('#' + hash.replace(/^#/, ''));
const { href, hash: prevHash } = window.parent.location;
if (prevHash) {
const updatedHref = href.replace(/#(.*)/, hash);
window.parent.location.replace(updatedHref);
} else {
window.parent.location.replace(`${href}${hash}`);
}
};
const toKebabCase = (str) =>
str &&
Expand Down

0 comments on commit 0d30309

Please sign in to comment.