Skip to content

Commit 1305062

Browse files
fix(util): added optional offset parameter
1 parent dc9273a commit 1305062

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

packages/react/src/patterns/sub-patterns/TableOfContents/TOCMobile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const TOCMobile = ({ menuItems, selectedId, menuLabel, updateState }) => {
4545
const title = filteredItems[0].title;
4646
updateState(id, title);
4747
const selector = `a[name="${id}"]`;
48-
smoothScroll(null, selector);
48+
smoothScroll(null, selector, 50);
4949
};
5050

5151
/**

packages/utilities/src/utilities/smoothScroll/smoothScroll.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
*
2020
* @param {*} e event object
2121
* @param {*} selector menu item selector id
22+
* @param {number} offset top offset for the scroll
2223
* @returns {null} Returns null if no scroll is needed
2324
*/
24-
const smoothScroll = (e, selector) => {
25+
const smoothScroll = (e, selector, offset = 0) => {
2526
let getSelector;
2627
if (e !== null) {
2728
e.preventDefault();
@@ -35,7 +36,7 @@ const smoothScroll = (e, selector) => {
3536
window.scroll({
3637
top:
3738
document.querySelector(getSelector).getBoundingClientRect().top -
38-
50 +
39+
offset +
3940
window.scrollY,
4041
behavior: 'smooth',
4142
});

0 commit comments

Comments
 (0)