Skip to content

feat: support arrow keys on range inputs - #1354

Open
sviat-barbutsa wants to merge 1 commit into
testing-library:mainfrom
sviat-barbutsa:pr/range-input-arrow-keys
Open

sviat-barbutsa wants to merge 1 commit into
testing-library:mainfrom
sviat-barbutsa:pr/range-input-arrow-keys

Conversation

@sviat-barbutsa

Copy link
Copy Markdown

What

I added arrow-key support for focused <input type="range"> elements. When a keypress is simulated on one, it moves the slider by one step and dispatches input, then change, before keyup.

Pressing ArrowRight again at the max of a horizontal left-to-right slider does not fire either event. Canceling keydown also leaves the value untouched.

Fixes #1067 and covers the keyboard piece of #871.

Why

Gutenberg's border-width test sets the slider value directly, so I tried the published WordPress BorderControl in a local React fixture. Four ArrowRight presses moved both the slider and its linked number field from 1px to 5px across Chrome, Edge, Opera, Firefox, and Safari on macOS.

This change matched native input at every step, reporting 2px, 3px, 4px, and 5px along the way. With user-event 14.6.13, the width stayed at 1px and the component received no callbacks. (Gutenberg test)

How

  • Stepping and step="any": I used the input's native stepping methods for numeric steps, including fractional ones. For step="any", the change moves by 1% of the range to match Chrome and Safari (Firefox uses a different increment).
  • Orientation and browser quirks: I followed Chrome's arrow directions for vertical and right-to-left sliders. For example, on a horizontal RTL slider at 50, ArrowRight moved Chrome to 49 and Safari 18.2 to 51. Firefox 160 also fired change on the first ArrowRight for some sliders initialized at their maximum.
  • jsdom differences: In jsdom, a few inputs already started with a different initial value or text format before the key event ran.
  • Test suites: All 601 Jest tests passed, and the 22 new test cases passed across all three toolbox environments. The full toolbox run had 18 failures, all of which also failed on clean main. Type-checking, lint, and the build all passed.

Checklist

  • Documentation
  • Tests
  • Ready to be merged

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArrowUp / ArrowDown should fire onInput for input[type="range"]

1 participant