Skip to content

Commit

Permalink
feat: use Pointer Lock API for Number input (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassaid authored Jan 22, 2025
1 parent 428240c commit b9c6376
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/clever-experts-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'leva': minor
---

feat: use Pointer Lock API for Number input
9 changes: 8 additions & 1 deletion packages/leva/src/components/Number/Number.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ type DraggableLabelProps = {

const DraggableLabel = React.memo(({ label, onUpdate, step, innerLabelTrim }: DraggableLabelProps) => {
const [dragging, setDragging] = useState(false)
const bind = useDrag(({ active, delta: [dx], event, memo = 0 }) => {
const bind = useDrag(({ active, delta: [dx], event, memo = 0, first, last, target }) => {
if (first) {
const label = target as HTMLElement
label.requestPointerLock()
}
if (last) {
document.exitPointerLock()
}
setDragging(active)
memo += dx / 2
if (Math.abs(memo) >= 1) {
Expand Down

0 comments on commit b9c6376

Please sign in to comment.