fix: preserve trailing decimal zeros in number inputs (e.g. 1.0)#1164
Open
majiayu000 wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
fix: preserve trailing decimal zeros in number inputs (e.g. 1.0)#1164majiayu000 wants to merge 2 commits intomodelcontextprotocol:mainfrom
majiayu000 wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
The number input's onBlur handler was unconditionally clearing the numeric draft, causing values like "1.0" to revert to "1". Now the draft is only cleared when the raw text matches the stringified number (e.g. "5" === "5"), so meaningful decimal notation like "1.0" persists. Also adds numeric draft tracking to ToolsTab's top-level number inputs which previously had no draft state at all. Fixes modelcontextprotocol#918 Signed-off-by: majiayu000 <1835304752@qq.com>
Integer fields now unconditionally clear numericDrafts on blur, matching DynamicJsonForm behavior. Number fields still preserve trailing decimal notation (e.g. "1.0") in the draft. Updated test to verify "1.0" typed in an integer field is stripped to "1" after blur. Signed-off-by: majiayu000 <1835304752@qq.com>
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.
Summary
Fixes #918
The
numbertype input was clearing trailing zeros on blur, so entering1.0would snap to1. This is becauseonBlurunconditionally cleared the numeric draft, andString(Number('1.0'))is'1'.The fix: only clear the draft when the raw text round-trips cleanly through
Number(). When it doesn't (like'1.0'vs'1'), the draft stays and the display value keeps showing what the user typed. Theintegercase is left as-is since integers don't need decimal preservation.Also adds a
numericDraftsstate inToolsTab.tsxfor the top-level number inputs (same pattern), and wires upJSON.rawJSONwhere available so1.0survives serialization on the wire.Type of Change
Changes Made
DynamicJsonForm.tsx: In the
case 'number'onBlur handler, changedclearNumericDraft(path)to be conditional onval === String(Number(val)). When the raw text has meaningful decimal notation (e.g.'1.0' !== '1'), the draft persists.ToolsTab.tsx: Added
numericDraftsstate for top-level number inputs with the same conditional-clear logic. BeforecallTool, drafts that don't round-trip cleanly get serialized viaJSON.rawJSONso1.0appears as1.0in the JSON payload (with a runtime check for browser support).DynamicJsonForm.test.tsx: Added two tests: one verifying
1.0is preserved after blur on anumberfield, another verifyingintegerfields still normalize1.0to1.Related Issues
Fixes #918
Testing
Test Results and/or Instructions
numberparameter1.0and click away (blur) - the input should still show1.01.0in anintegerparameter and blur - it should normalize to1npm testpasses all 489 testsChecklist
npm run prettier-fix)Breaking Changes
None.