feat: add smooth keyboard scroll support#519
Conversation
Add smoothKeyboard option (default: true) that enables smooth-scrolled keyboard navigation — ArrowUp/Down/Left/Right, Space, PageUp/Down, Home, End. Keys are orientation-aware (gestureOrientation: both/vertical/horizontal), skip editable elements (input/textarea/select/contentEditable), respect data-lenis-prevent and prevent/virtualScroll callbacks, and never intercept Tab. Closes the accessibility gap where wheel users get smooth scroll but keyboard-only users get native jerky scroll.
|
@realhardik is attempting to deploy a commit to the Darkroom Open Source Team on Vercel. A member of the Team first needs to authorize it. |
|
Why ±100px from arrows, is this an arbitrary value, where does it come from? |
±100 is based on the deltaY value Chrome commonly produces for a single wheel notch in pixel mode. It also felt like a reasonable since 50 seemed too slow, while 200 felt too fast. Using 100 keeps keyboard scrolling roughly aligned with wheel scrolling while maintaining a comfortable navigation speed. |
|
On my macbook this value is 40px so i'm wondering if there is a way to get the correct value on every machine. |
The 100px i mentioned is standard from the wheel event. What you might have checked is value from arrow event. (I was trying to match arrow's speed with standard scroll speed) But, If you want consistency across devices, we can multiply a constant with viewport's height to let's say scroll 10% of screen on every arrow key event. Let me know if you like that approach. |
Summary
Adds smooth-scrolled keyboard navigation to Lenis. Currently Lenis handles
wheelandtouchevents but completely ignores keyboard input — keyboard-only users get native jerky scroll while mouse/trackpad users get buttery smooth scroll. This closes that accessibility gap.Closes issue #518
New option
Keys handled
ArrowUp/ArrowDowngestureOrientation: 'both')ArrowLeft/ArrowRightgestureOrientation: 'both')SpaceShift+SpacePageUp/PageDownHomeEndTabSafety checks
<input>,<textarea>,<select>,contentEditableelementsdata-lenis-preventon focused elementprevent()andvirtualScroll()callbacksgestureOrientation(vertical / horizontal / both)virtual-scrollevent for keyboard actionsisStopped/isLockedstateFiles changed
packages/core/src/types.ts— AddedsmoothKeyboardtoLenisOptions,KeyboardEventtoVirtualScrollDatapackages/core/src/lenis.ts—onKeyDownhandler,isEditableElementhelper, lifecycle setup/teardownNon-breaking
smoothKeyboarddefaults totruebut can be disabled