Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (e.key === 'Escape' || e.keyCode === 27) {
e.stopPropagation()
setIsUnloading(true)
}
}, [])
const handleScroll = useCallback(() => {
forceUpdate(n => n + 1)
if (!isUnloading) {
setIsUnloading(true)
}
}, [isUnloading])
// listen for keydown on the document
useEvent('keydown', handleKeyDown, document)
// listen for scroll and close
useEvent('scroll', handleScroll, scrollableEl)
// set loaded on mount and focus
useEffect(() => {
setIsLoaded(true)
onLoad()
if (btnRef.current) {
btnRef.current.focus({ preventScroll: true })
}
}, [onLoad])
// if unloading, tell parent that we're all done here after Nms
useEffect(() => {
[onZoomChange]
)
const handleScroll = useCallback(() => {
forceUpdate(n => n + 1)
if (!isUnloading) {
onZoomChange(false)
}
}, [isUnloading, onZoomChange])
// listen for keydown on the document
useEvent('keydown', handleKeyDown, document)
// listen for scroll and close
useEvent('scroll', handleScroll, scrollableEl)
// set loaded on mount and focus
useEffect(() => {
if (!prevIsActive && isActive) {
setIsLoaded(true)
if (btnRef.current) {
btnRef.current.focus({ preventScroll: true })
}
}
}, [isActive, prevIsActive])
useEffect(() => {
// when parent says to deactivate, begin unloading process
if (prevIsActiveFromParent && !isActiveFromParent) {
setIsUnloading(true)
onZoomChange(false)
}
},
[onZoomChange]
)
const handleScroll = useCallback(() => {
forceUpdate(n => n + 1)
if (!isUnloading) {
onZoomChange(false)
}
}, [isUnloading, onZoomChange])
// listen for keydown on the document
useEvent('keydown', handleKeyDown, document)
// listen for scroll and close
useEvent('scroll', handleScroll, scrollableEl)
// set loaded on mount and focus
useEffect(() => {
if (!prevIsActive && isActive) {
setIsLoaded(true)
if (btnRef.current) {
btnRef.current.focus({ preventScroll: true })
}
}
}, [isActive, prevIsActive])
useEffect(() => {
}
}, [])
const handleScroll = useCallback(() => {
forceUpdate(n => n + 1)
if (!isUnloading) {
setIsUnloading(true)
}
}, [isUnloading])
// listen for keydown on the document
useEvent('keydown', handleKeyDown, document)
// listen for scroll and close
useEvent('scroll', handleScroll, scrollableEl)
// set loaded on mount and focus
useEffect(() => {
setIsLoaded(true)
onLoad()
if (btnRef.current) {
btnRef.current.focus({ preventScroll: true })
}
}, [onLoad])
// if unloading, tell parent that we're all done here after Nms
useEffect(() => {
const unloadTimeout = isUnloading
? setTimeout(onUnload, transitionDuration)
: null
stories.add('with controlled; specific keys', () => {
const [isZoomed, setIsZoomed] = useState(false)
const handleKeyDown = useCallback(e => {
if (e.key === 'j' || e.keyCode === 74) {
setIsZoomed(true)
} else if (e.key === 'k' || e.keyCode === 75) {
setIsZoomed(false)
}
}, [])
useEvent('keydown', handleKeyDown, document)
return (