Skip to content

Keep RangeSlider number inputs in handle order - #4223

Open
Sasha-P wants to merge 1 commit into
plotly:devfrom
Sasha-P:fix-rangeslider-direct-input
Open

Sasha-P wants to merge 1 commit into
plotly:devfrom
Sasha-P:fix-rangeslider-direct-input

Conversation

@Sasha-P

@Sasha-P Sasha-P commented Nov 30, 2026

Copy link
Copy Markdown

Closes #4222.

The number inputs of dcc.RangeSlider could publish a value or drag_value with the low end above the high end. I listed this under "Not covered by this PR" in #3926. The two PRs do not depend on each other and can merge in either order.

The bug

For a slider at [5, 15], type 18 into the min input and press Tab. The slider and both inputs show [15, 15], but the callbacks get:

updatemode value drag_value
"drag" [18, 15] [18, 15]
"mouseup" [15, 15] [18, 15]

The max input does the same in the other direction ([5, 3] after typing 3). allowCross makes no difference.

The cause is in the input handlers in RangeSlider.tsx:

  • onChange published any typed number that passed the min, max and step check, without comparing it to the other handle.
  • onBlur clamped the number to the other handle, but published the result only with updatemode="mouseup", and only as value.

Changes

  • onChange of both inputs: a typed number past the other handle is not published.
  • onBlur of both inputs: the clamped pair is published as value and drag_value in both update modes.
  • test_slkb002_range_input_constrained_by_min_max: its last line asserted drag_value is [7, 5], the out-of-order pair. It now asserts [5, 5].
  • New test test_slkb006_range_input_keeps_handle_order, run for drag and mouseup. It types past the other handle in each input, then checks the final props and that no callback got an out-of-order pair.

With this PR the example above ends with value and drag_value both at [15, 15] in both update modes.

What does not change

  • The inputs stop at the other handle for both allowCross=True and allowCross=False. That was already the behavior on blur. This PR only fixes what is published.
  • Until blur, the input and the handle show the typed number (18 in the example).
  • In drag mode, a typed number that keeps the pair in order is still published on each keystroke. Typing 18 publishes [1, 15] after the first digit.
  • Focusing an input and leaving it without typing does not fire a callback.

Tests

  • components/dash-core-components/tests/integration/sliders/: 36 passed in headless Chrome.
  • test_sliders_keyboard_input.py: 7 passed in headless Firefox.
  • Without the change to RangeSlider.tsx, 3 of those 7 fail:
    • test_slkb002_range_input_constrained_by_min_max: drag_value is [7, 5]
    • test_slkb006_range_input_keeps_handle_order[drag]: value is [18, 15], drag_value is [18, 15]
    • test_slkb006_range_input_keeps_handle_order[mouseup]: value is [15, 15], drag_value is [18, 15]
  • Merged locally with fix RangeSlider allow_cross #3926: no conflicts, and the same directory gives 46 passed in headless Chrome.

Contributor Checklist

  • This PR targets dev (fix or chore) or next (feature, new API, breaking change), see Which branch to target
  • I have broken down my PR scope into the following TODO tasks
    • Do not publish a typed number that is past the other handle
    • Publish the clamped pair as value and drag_value on blur
    • Test both inputs in both update modes
  • I have run the tests locally and they passed. (refer to testing section in contributing)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follows
    • this GitHub #PR number updates the dash docs
    • here is the show and tell thread in Plotly Dash community

Generated with Claude Code

Do not publish a typed min above the max, or a max below the min, while
typing. On blur, publish the clamped result as both value and
drag_value in every updatemode.

Before, updatemode="drag" left value out of order after blur, and
updatemode="mouseup" left drag_value stale.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

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.

[BUG] dcc.RangeSlider number inputs publish a value with the low end above the high end

1 participant