Repository navigation
Update the displayed value when the format of ui.number changes - #6553
Open
falkoschindler wants to merge 4 commits into
Open
falkoschindler wants to merge 4 commits into
falkoschindler wants to merge 4 commits into
Conversation
`format` was a plain attribute, so `number.format = '%.1f'` at runtime changed nothing in the browser until the next value change or `sanitize()`. It is now a property whose setter re-derives the displayed value, like `prefix` and `suffix`. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WgKVNb2aAsju6ryUWTWzky
With LOOPBACK disabled, ValueElement remembers the text the client typed and keeps it on the client whenever a serialized model-value equals it. That memory was only cleared in _handle_value_change, so a setter that rewrites the prop directly, like the new format setter, left it stale: switching the format twice (e.g. back to the original one) made the browser keep the previous formatting. _to_dict now clears the memory whenever it does not preserve the prop, because the client is about to show the new value either way. This covers every path that writes the prop, so _handle_value_change no longer needs its own reset. test_prefix_and_suffix is back to its original form, and a new test_changing_format types a value, changes the format on its own and switches it back to None. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WgKVNbGnC9XfoAR9gu5RP6
Like the min and max setters, the format setter now returns early when the same format is assigned again. Before, every assignment rewrote model-value and enqueued an update, and with a format active that update replaces the text the client is typing. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WgKVNZr5cJy66ZNxJJ22Qf
This was referenced Dec 1, 2026
Both sides appended a test to tests/test_number.py; the merge keeps test_format_does_not_round_the_value_below_the_minimum from #6550 followed by test_changing_format. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WgKVNZ3csUJiybGywqbjcv
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.number'sformatwas a plain attribute, unlikemin,max,precision,prefixandsuffix, which are properties that update the element when set. Assigningnumber.format = '%.1f'at runtime therefore changed nothing in the browser until the next value change orsanitize(). Found while reviewing #6550, which madeformatdisplay-only; this is the counterpart on the other side: changing the format only touches the display.Implementation
formatbecomes a property. Its setter stores the new format and re-derives themodel-valueprop through_value_to_model_value, so the browser shows the new formatting right away. Likeminandmax, it returns early when the same format is assigned again. It does not callsanitize(): since #6550, the format has no effect on the value, so there is nothing to clamp or round.Elements without loopback remember the text the client typed and ask the client to keep it whenever a serialized
model-valueequals it. That memory was only cleared in_handle_value_change, so a setter that rewrites the prop directly left it stale, and switching the format twice (e.g. back to the original one) made the browser keep the previous formatting.ValueElement._to_dictnow clears the memory whenever it does not preserve the prop, since the client is about to show the new value either way; this covers every path that writes the prop. A newtest_changing_formattypes a value, changes the format on its own and switches it back toNone.Progress
※