Repository navigation
Conversation
`ui.range`'s min and max setters only wrote the props, so narrowing a bound
left the current position outside the range: with value={'min': 10, 'max': 90}
and then `r.max = 50`, the value stayed {'min': 10, 'max': 90} and the browser
kept the old model value too, because QRange does not emit an update when its
bounds move. QPagination does emit one, which is why it recovers on its own.
`ui.number` already clamps inside the very same setters, so this follows that
path: both setters call `_clamp_value`, which pulls both positions into the
current bounds and writes only when something actually moved.
Covered by screen tests: the two clamping cases fail on main and pass here, and
test_range, test_number and test_pagination pass together (31 tests).
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
ui.range'sminandmaxsetters write the prop and stop there, so moving a bound past the current position leaves the value outside the range. Withvalue={'min': 10, 'max': 90}:The browser keeps that stale model value as well, because QRange does not emit an update when its bounds move. I first suspected the same problem in
ui.pagination(it has the same setters), but there QPagination reports the clamped value back, so it recovers on its own and needs no change.Implementation
ui.numberalready clamps in exactly these two setters (self.sanitize()at the end ofminandmax), soui.rangefollows that path instead of gaining new public API: after writing the prop, both setters call a small_clamp_value, which pulls each position into[min, max]and writes the value only when something actually moved. Widening the bounds therefore stays a no-op, andNonestaysNone.The degenerate case behaves like
ui.number's arithmetic: when the bounds themselves are crossed (min > max), both positions land onmax.Two screen tests cover it: they shrink the upper bound and raise the lower bound, then check the clamping through a label bound to
value. A third test asserts that widening the bounds leaves the value untouched.Progress
ui.numbercounterparts nowBefore the change, the two clamping tests fail on
main; with it,tests/test_range.py,tests/test_number.pyandtests/test_pagination.pypass together (31 tests, Python 3.13, Windows).