Skip to content

Commit f0992b4

Browse files
committed
Revert to use body for scroll to top becasue of bug with smoothscroll-polyfill
1 parent 4e0f79e commit f0992b4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ import { HashLink } from 'react-router-hash-link';
7272
```js
7373
import { HashLink } from 'react-router-hash-link';
7474
<HashLink to="/path#top">Link to Top of Page</HashLink>
75+
// or
76+
<HashLink to="#top">Link to Top of Page</HashLink>
7577
```
7678

7779
### Scroll with offset

src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@ function reset() {
1919
function getElAndScroll() {
2020
let element = null;
2121
if (hashFragment === '#') {
22-
element = document.documentElement;
22+
// use document.body instead of document.documentElement because of a bug in smoothscroll-polyfill in safari
23+
// see https://github.com/iamdustan/smoothscroll/issues/138
24+
// while smoothscroll-polyfill is not included, it is the recommended way to implement smoothscroll
25+
// in browsers that don't natively support el.scrollIntoView({ behavior: 'smooth' })
26+
element = document.body;
2327
} else {
2428
// check for element with matching id before assume '#top' is the top of the document
2529
// see https://html.spec.whatwg.org/multipage/browsing-the-web.html#target-element
2630
const id = hashFragment.replace('#', '');
2731
element = document.getElementById(id);
2832
if (element === null && hashFragment === '#top') {
29-
element = document.documentElement;
33+
// see above comment for why document.body instead of document.documentElement
34+
element = document.body;
3035
}
3136
}
3237

0 commit comments

Comments
 (0)