forked from microsoft/playwright
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: strip out the search parameter in shared link (microsoft#177)
Fixes microsoft#129
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
/* eslint-disable jsx-a11y/anchor-has-content, jsx-a11y/anchor-is-valid */ | ||
import React from 'react'; | ||
import clsx from 'clsx'; | ||
import { useThemeConfig } from '@docusaurus/theme-common'; | ||
import './styles.css'; | ||
import styles from './styles.module.css'; | ||
|
||
// This component was modified to strip out the search parameter in the link | ||
|
||
const Heading = Tag => function TargetComponent({ | ||
id, | ||
...props | ||
}) { | ||
const { | ||
navbar: { | ||
hideOnScroll | ||
} | ||
} = useThemeConfig(); | ||
|
||
if (!id) { | ||
return <Tag {...props} />; | ||
} | ||
|
||
const handleOnHeadingClick = (ev) => { | ||
ev.preventDefault() | ||
const url = new URL(ev.target.href) | ||
url.search = "" | ||
history.pushState('', document.title, url.toString()); | ||
} | ||
|
||
return <Tag {...props}> | ||
<a aria-hidden="true" tabIndex={-1} className={clsx('anchor', { | ||
[styles.enhancedAnchor]: !hideOnScroll | ||
})} id={id} /> | ||
{props.children} | ||
<a className="hash-link" href={`#${id}`} onClick={handleOnHeadingClick} title="Direct link to heading"> | ||
# | ||
</a> | ||
</Tag>; | ||
}; | ||
|
||
export default Heading; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
.anchor { | ||
display: block; | ||
position: relative; | ||
top: -0.5rem; | ||
} | ||
|
||
.hash-link { | ||
opacity: 0; | ||
padding-left: 0.5rem; | ||
transition: opacity var(--ifm-transition-fast); | ||
} | ||
|
||
.hash-link:focus, | ||
*:hover > .hash-link { | ||
opacity: 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
.enhancedAnchor { | ||
top: calc(var(--ifm-navbar-height) * -1); | ||
} |