Skip to content

Commit 1739e73

Browse files
authored
Merge pull request #67 from clirettenetchex/custom-timeout
Added custom timeout prop to override the 10 second wait if needed.
2 parents a1644cd + 28c3939 commit 1739e73

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function getElAndScroll() {
2626
return false;
2727
}
2828

29-
function hashLinkScroll() {
29+
function hashLinkScroll(timeout) {
3030
// Push onto callback queue so it runs after the DOM is updated
3131
window.setTimeout(() => {
3232
if (getElAndScroll() === false) {
@@ -38,10 +38,10 @@ function hashLinkScroll() {
3838
childList: true,
3939
subtree: true,
4040
});
41-
// if the element doesn't show up in 10 seconds, stop checking
41+
// if the element doesn't show up in specified timeout or 10 seconds, stop checking
4242
asyncTimerId = window.setTimeout(() => {
4343
reset();
44-
}, 10000);
44+
}, timeout || 10000);
4545
}
4646
}, 0);
4747
}
@@ -69,10 +69,10 @@ export function genericHashLink(As) {
6969
props.smooth
7070
? el.scrollIntoView({ behavior: "smooth" })
7171
: el.scrollIntoView());
72-
hashLinkScroll();
72+
hashLinkScroll(props.timeout);
7373
}
7474
}
75-
const { scroll, smooth, ...filteredProps } = props;
75+
const { scroll, smooth, timeout, ...filteredProps } = props;
7676
return (
7777
<As {...filteredProps} onClick={handleClick} ref={ref}>
7878
{props.children}
@@ -89,6 +89,7 @@ const propTypes = {
8989
onClick: PropTypes.func,
9090
children: PropTypes.node,
9191
scroll: PropTypes.func,
92+
timeout: PropTypes.number,
9293
to: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
9394
};
9495

0 commit comments

Comments
 (0)