MudNumericField: Don't reformat text while typing with Immediate#13311
Conversation
When Immediate=true and a managed format (Format, Pattern, or an explicit Culture) is set, MudNumericField reformatted the input text on every keystroke, jumping the caret to the end and making multi-digit/decimal entry impossible. Typing "1234" with Format="F3" collapsed to "1.000", and the DataGrid numeric filter dropped the "." and the "0" when typing "1.008". OnInputValueChanged is wired to the inner MudInput.ValueChanged, which fires on oninput (every keystroke) when Immediate=true and on onchange (commit) when Immediate=false. The reformat block now skips the live oninput path via !Immediate, so the raw text is preserved while typing and the value is formatted on blur instead (OnBlurredAsync), matching the non-Immediate behavior and the pre-v9.1 formatting. The non-Immediate commit reformat that fixed MudBlazor#12677 is unchanged. Fixes MudBlazor#13266 Fixes MudBlazor#13250
|
This PR fixes the
The suspected shared root cause is the value→text resync running while the input is focused — Neither secondary case could be reproduced in bUnit. bUnit renders synchronously, so the Also distinct: #11818. The v8.11 "filter doesn't allow decimals / not a valid number" report predates the v9.1 reformat regression and is a separate culture/parsing issue. Not related to this PR. |
Fixes #13266
Fixes #13250
Related to #13002
Problem
When
Immediate="true"and a managed format (Format,Pattern, or an explicitCulture) is set,MudNumericFieldreformatted the input text on every keystroke. This rewrote the box and moved the caret to the end after the first character, making multi-digit and decimal entry impossible:1234withFormat="F3"collapsed to1.000(so you end up with1). — MudNumericField: Immediate=true combined with Format-Property causes issues #132661.008lost the.and the leading0, producing1008. — Can't type 0 after decimal point in filter #13250This is a regression from v8.x, which only applied the format on blur. It was introduced in #12766 (v9.1.0), which added a reformat block to
OnInputValueChangedto fix a .NET 10 blur-timing issue (#12677) — but that block also runs ononinput(every keystroke) whenImmediate=true.Fix
OnInputValueChangedis wired to the innerMudInput.ValueChanged, which fires ononinputwhenImmediate=trueand ononchange(a commit) whenImmediate=false. The reformat now skips the liveoninputpath:So the raw text is preserved while typing and the value is reformatted on blur (
OnBlurredAsync, unchanged) — restoring the v8.x /Immediate="false"behavior. The value still tracks every keystroke. The non-Immediate commit reformat that fixed #12677 is untouched, and the debounce path (DebounceInterval > 0, which already short-circuits this block) is unchanged.Repro (before this PR)
<MudNumericField Immediate="true" Format="F3" T="double?" />1234one digit at a time → field snaps to1.000after the first key and you can never enter the rest.Immediate="true"with the columnCulturebound): typing1.008produces1008.After this PR the text stays raw while typing (
1234,1.008) and is formatted on blur.Tests
MudNumericField(MudNumericField: Immediate=true combined with Format-Property causes issues #13266F3multi-digit, Can't type 0 after decimal point in filter #13250 decimal-zero) plus aPattern-trigger variant — each verified to fail before the fix and pass after.1.008one character at a time (the real-world Can't type 0 after decimal point in filter #13250 repro; previously produced1008).Checklist: