Skip to content

number_input: Built-in stepping, input restriction, and normalization#2460

Merged
madcodelife merged 7 commits into
mainfrom
number-input-builtin-step
Jun 15, 2026
Merged

number_input: Built-in stepping, input restriction, and normalization#2460
madcodelife merged 7 commits into
mainfrom
number-input-builtin-step

Conversation

@madcodelife

@madcodelife madcodelife commented Jun 12, 2026

Copy link
Copy Markdown
Member

Enhances NumberInput to work out of the box and match web <input type=number> behavior:

  • Built-in stepping: / keys and +/- buttons now step the value internally by step (default 1) and emit InputEvent::Change. Add step/step_by/min/max (plus set_* runtime setters) on InputState. min/max clamp on stepping and on blur; stepping follows web semantics (a step that can't move in the pressed direction is a no-op). step_by receives the current value and StepAction so the step can differ by direction (e.g. a price tick size at a range boundary).
  • Input restriction: a NumberInput-bound state now only accepts a valid number (optional leading sign, digits, single decimal point) by default; opt out via set_mask_pattern(MaskPattern::None, ...).
  • Full-width normalization: full-width digits/signs and the ideographic full stop (12。5) are normalized to ASCII (12.5) for CJK IME users; a bare leading dot (.5) is completed to 0.5.

Undo/redo now records a whole-document change when the mask reshapes the text, so masked values undo correctly.

madcodelife and others added 7 commits June 12, 2026 13:54
- `InputState` gains `step`/`step_by`/`min`/`max` builder methods and `set_*` runtime counterparts
- `NumberInput` now defaults to `MaskPattern::Number` (number-only input, full-width normalization, bare dot auto-completion). Opt out via `set_mask_pattern(MaskPattern::None)`
- New `NumberStep` enum supports fixed and by-value dynamic step strategies
- Fix undo/redo with mask: use whole-document history entry when mask changes text
- Fix invalid text trap: pre-existing invalid values can be edited to fix
Allow the step value to differ by direction at a range boundary (e.g. a
price tick size where a boundary belongs to a different tick going up vs
down), and simplify the internal stepping branch now that `step` defaults
to 1.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The previous three-tier price-tick example was both wrong (mismatched
boundary ticks, duplicated branches) and too heavy for an example. Replace
it with a clear two-tier case where the boundary 1.0 uses the lower tick
going down and the upper tick going up, kept consistent across the story,
docs, and unit test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@madcodelife madcodelife merged commit aa08592 into main Jun 15, 2026
4 checks passed
@madcodelife madcodelife deleted the number-input-builtin-step branch June 15, 2026 03:05
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.

1 participant