Skip to content

Commit

Permalink
Optimize isScrollable() (#2755)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
dwilsonactual and joshblack authored Jan 10, 2023
1 parent dcb51c6 commit dd1e5ce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-apricots-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Update `isScrollable` utility to only run `getComputedStyle` on scrollable content.
5 changes: 1 addition & 4 deletions src/utils/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@ export function getScrollContainer(element: Element | null): Element | null {
function isScrollable(element: Element) {
const hasScrollableContent = element.scrollHeight > element.clientHeight

const overflowYStyle = window.getComputedStyle(element).overflowY
const isOverflowHidden = overflowYStyle.indexOf('hidden') !== -1

return hasScrollableContent && !isOverflowHidden
return hasScrollableContent && !(window.getComputedStyle(element).overflowY.indexOf('hidden') !== -1)
}

0 comments on commit dd1e5ce

Please sign in to comment.