Skip to content

Commit

Permalink
chore: useReelCells内のループ処理を最適化する
Browse files Browse the repository at this point in the history
  • Loading branch information
AtsushiM committed Jan 9, 2025
1 parent 7a47f28 commit e11b4ea
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions packages/smarthr-ui/src/components/Table/useReelCells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,26 @@ export const useReelCells = () => {
}

const handleScroll = () => {
const stickyCells = currentRef.querySelectorAll('.fixedElement') || []
const stickyCells = currentRef.querySelectorAll('.fixedElement')

if (!stickyCells) {
return
}

const scrollLeft = currentRef.scrollLeft
const maxScrollLeft = currentRef.scrollWidth - currentRef.clientWidth || 0
const shouldFix = maxScrollLeft > 0 && scrollLeft < maxScrollLeft
const settableShowShadow = shouldFix
? scrollLeft > 0
: maxScrollLeft !== 0 || scrollLeft !== 0

stickyCells.forEach((cell) => {
const shouldFix = maxScrollLeft > 0 && scrollLeft < maxScrollLeft

if (shouldFix) {
cell.classList.add('fixed')
setShowShadow(scrollLeft > 0)
} else {
cell.classList.remove('fixed')
setShowShadow(maxScrollLeft === 0 && scrollLeft === 0 ? false : true)
}
cell.classList.toggle('fixed', shouldFix)
setShowShadow(settableShowShadow)
})
}

handleScroll()

currentRef.addEventListener('scroll', handleScroll)

const observer = new window.ResizeObserver(handleScroll)
Expand Down

0 comments on commit e11b4ea

Please sign in to comment.