Repository navigation
fix(NumberField): allow backspacing through a unit suffix - #10985
shubham-cpp wants to merge 4 commits into
Conversation
NumberParser only removed complete literals before validating, so a partially deleted multi-character unit (e.g. "5 m" from "5 mL", or "5 gra" from "5 grams") left a fragment that failed validation and the keystroke was rejected. Strip a trailing fragment of a known literal when sanitizing so partial units are accepted while editing and the full unit is restored by formatting on commit. Fixes adobe#2806 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Match partial literals by prefix instead of substring, so a different unit that appears inside the configured one (e.g. "5 L" in a milliliter field, "5 g" in a kilogram field) is no longer silently parsed as the configured unit. Also dedupe partial literals after whitespace stripping, share the whitespace/format-character pattern, and simplify the trailing scan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the PR. You're failing some tests. In addition, you'll need to sign the CLA. |
|
Also, your title and description do not match |
…artial unit React 16/17 move the caret to the end after a controlled edit, so the arrow-key based step deleted the wrong text. Select the digit directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks! Pushed fddec01 for the React 16/17 failure. It was the new test, not the parser change: on React 16/17 in jsdom the caret jumps to the end after a deletion (main does this too), so the next keystroke went after the unit. The test now places the selection explicitly. The NumberField, NumberParser and useNumberFieldState suites pass locally on React 16, 17 and 19. On the title: the change is in |
|
Your title is "fix(NumberParser): allow deleting a unit one character at a time" Specifically "didn't work" You can keep it as NumberField |
|
Got it, thanks. Renamed it to "fix(NumberField): fix deleting multi-character units one character at a time" and reworded the first sentence to say exactly what fails: multi-character units like "mL" (and "grams" with |
|
You can see how your title is still misrepresenting what the PR is doing right? The PR does not fix deleting units one character at a time. It is only fixing deleting full unit strings. Please have your human review the title and the work in this PR. You have not checked the checklist item in the description. I appreciate the honesty, and I need you to include the human as per our contribution guidelines. I do not want to have back and forths with an AI agent. If I want to talk to an agent, I'll talk to my own. |
|
Hi Rob, sorry for the inconvenience. I'm taking over from the agent here. I've updated the title so it matches what the code does and what I saw when I tested it manually. Let me know if it's fine or if it needs more changes. In the description, I've also noted that this only partially addresses #2806, and listed the limitations of the current approach. Also update on CLA, I've signed it(around ~30mins ago) |


Partially addresses #2806
Summary
In a NumberField, a multi-character unit suffix can only be removed by selecting the whole unit and deleting it. Backspacing through it is rejected: Backspace on "5 mL" does nothing, and "5 grams" (
unitDisplay: 'long') only gets as far as "5 gram". Single-character units such as "g" already work. The parser only strips complete literals, so a half-deleted unit leaves a fragment that failsisValidPartialNumber, and the keystroke is rejected.This PR lets a unit suffix be removed from its end, one character at a time. It does not make every unit character deletable; see Limitations.
Following the direction @snowystinger approved in the issue,
NumberParsernow ignores a trailing prefix of a known literal (e.g. "m" from "mL") when validating and parsing. Only prefixes count, so a different unit inside the configured one ("5 L" in a milliliter field, "5 g" in a kilogram field) is still rejected instead of silently read as the configured unit. Fragments made only of number symbols (decimal, group, signs) are never stripped, so "1." keeps its meaning. Formatting restores the full unit on blur.Limitations
Because
parsesharessanitize, it also accepts a trailing prefix ('23.5 i' -> 23.5 for inch), so committing while a partial unit remains keeps the edited number instead of reverting it. Happy to limit this toisValidPartialNumberif you'd preferparsestay strict.📝 Test Instructions
parse('5 L')(milliliter) /parse('5 g')(kilogram) -> NaN.yarn jeston NumberParser, RAC/v3/S2 NumberField, useNumberField and useNumberFieldState: 6 suites, 601 passed, 2 skipped.yarn check-typesand lint pass.currencyDisplay: 'code') can't be partly deleted.AI disclosure: written with help from Claude Code (Claude Opus 5.5).
Release impact
✅ PR Checklist
🧢 Your Project
Personal contribution.
🤖 Generated with Claude Code