Skip to content

Commit 89c550c

Browse files
author
Mahesh Kothur
committed
feat(utility): addressed the review comments
1 parent 9cda24d commit 89c550c

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const TOCDesktop = ({ menuItems, selectedId, updateState }) => {
6666
const title = filteredItems[0].title;
6767
updateState(id, title);
6868
const selector = `a[name="${id}"]`;
69-
smoothScroll({ e: null, selector });
69+
smoothScroll({ selector });
7070
};
7171

7272
/**

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const TOCMobile = ({ menuItems, selectedId, menuLabel, updateState }) => {
7272
const title = filteredItems[0].title;
7373
updateState(id, title);
7474
const selector = `a[name="${id}"]`;
75-
smoothScroll({ e: null, selector });
75+
smoothScroll({ selector });
7676
};
7777

7878
/**

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

+12-11
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@
2020
* @param {object} { e: Event, Selector: QuerySelector for the target element }
2121
*/
2222
const smoothScroll = ({ e, selector }) => {
23-
if (e !== null) {
23+
let getSelector;
24+
if (e) {
2425
e.preventDefault();
25-
const id = e.currentTarget.getAttribute('href');
26-
document.querySelector(id).scrollIntoView({
27-
behavior: 'smooth',
28-
block: 'start',
29-
});
30-
} else if (selector !== null) {
31-
document.querySelector(selector).scrollIntoView({
32-
behavior: 'smooth',
33-
block: 'start',
34-
});
26+
getSelector = e.currentTarget.getAttribute('href');
27+
} else if (selector) {
28+
getSelector = selector;
29+
} else {
30+
return null;
3531
}
32+
document.querySelector(getSelector).scrollIntoView({
33+
behavior: 'smooth',
34+
block: 'start',
35+
});
3636
};
37+
3738
export default smoothScroll;

0 commit comments

Comments
 (0)