mirror of
https://github.com/linsa-io/linsa.git
synced 2026-04-23 08:48:37 +02:00
fix(link): Keybind, scroll behaviour, restrict drag to vertical (#176)
* chore: expose scrollActiveElementIntoView * feat(utils): editable element * fix: memoize exceptionRefs, use animation frame and check editable element * fix: improve btn on mobile * chore(drps): bump framer motion version * fix(link): big fix * chore: remove comment code * feat: touch device
This commit is contained in:
@@ -13,7 +13,8 @@ export function useActiveItemScroll<T extends HTMLElement>(options: ActiveItemSc
|
||||
|
||||
const scrollActiveElementIntoView = useCallback((index: number) => {
|
||||
const activeElement = elementRefs.current[index]
|
||||
activeElement?.scrollIntoView({ block: "nearest" })
|
||||
activeElement?.focus()
|
||||
// activeElement?.scrollIntoView({ block: "nearest" })
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
@@ -26,5 +27,5 @@ export function useActiveItemScroll<T extends HTMLElement>(options: ActiveItemSc
|
||||
elementRefs.current[index] = element
|
||||
}, [])
|
||||
|
||||
return setElementRef
|
||||
return { setElementRef, scrollActiveElementIntoView }
|
||||
}
|
||||
|
||||
20
web/hooks/use-touch-sensor.ts
Normal file
20
web/hooks/use-touch-sensor.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { useState, useEffect } from "react"
|
||||
|
||||
export function useTouchSensor() {
|
||||
const [isTouchDevice, setIsTouchDevice] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const detectTouch = () => {
|
||||
setIsTouchDevice("ontouchstart" in window || navigator.maxTouchPoints > 0)
|
||||
}
|
||||
|
||||
detectTouch()
|
||||
window.addEventListener("touchstart", detectTouch, false)
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("touchstart", detectTouch)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return isTouchDevice
|
||||
}
|
||||
Reference in New Issue
Block a user