Skip to content

Commit dd1e5ce

Browse files
Optimize isScrollable() (#2755)
* Take advantage of short-circuiting to avoid calling getComputedStyle on non-scrollable elements. * Add changeset. * Update .changeset/nervous-apricots-search.md Co-authored-by: Josh Black <joshblack@github.com> Co-authored-by: Josh Black <joshblack@github.com>
1 parent dcb51c6 commit dd1e5ce

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

.changeset/nervous-apricots-search.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': patch
3+
---
4+
5+
Update `isScrollable` utility to only run `getComputedStyle` on scrollable content.

src/utils/scroll.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,5 @@ export function getScrollContainer(element: Element | null): Element | null {
1414
function isScrollable(element: Element) {
1515
const hasScrollableContent = element.scrollHeight > element.clientHeight
1616

17-
const overflowYStyle = window.getComputedStyle(element).overflowY
18-
const isOverflowHidden = overflowYStyle.indexOf('hidden') !== -1
19-
20-
return hasScrollableContent && !isOverflowHidden
17+
return hasScrollableContent && !(window.getComputedStyle(element).overflowY.indexOf('hidden') !== -1)
2118
}

0 commit comments

Comments
 (0)