fc82d2f6d5
* Use Redix FocusTrap (#5638) * Use Redix FocusTrap * force resolutions on radix libs * add focus guards * use @radix-ui/dismissable-layer for escape handling * fix banner menu keypress by using `Pressable` * add menu in dialog example to storybook --------- Co-authored-by: Samuel Newman <mozzius@protonmail.com> * use DismissableLayer/FocusScope for composer * fix storybook dialog * thread Portal through Prompt and avatar/banner * fix dialog style regression * remove tamagui --------- Co-authored-by: Eric Bailey <git@esb.lol>
32 lines
647 B
TypeScript
32 lines
647 B
TypeScript
import {useEffect} from 'react'
|
|
|
|
import {isWeb} from '#/platform/detection'
|
|
|
|
let refCount = 0
|
|
|
|
function incrementRefCount() {
|
|
if (refCount === 0) {
|
|
document.body.style.overflow = 'hidden'
|
|
document.documentElement.style.scrollbarGutter = 'auto'
|
|
}
|
|
refCount++
|
|
}
|
|
|
|
function decrementRefCount() {
|
|
refCount--
|
|
if (refCount === 0) {
|
|
document.body.style.overflow = ''
|
|
document.documentElement.style.scrollbarGutter = ''
|
|
}
|
|
}
|
|
|
|
export function useWebBodyScrollLock(isLockActive: boolean) {
|
|
useEffect(() => {
|
|
if (!isWeb || !isLockActive) {
|
|
return
|
|
}
|
|
incrementRefCount()
|
|
return () => decrementRefCount()
|
|
})
|
|
}
|