You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(mask-input): fit the value to a new mask - #2651
After the first render, a change of mask makes the value the raw text that the new mask shows. Value 1234 becomes 12 after a change from 00-00 to 00, and stays 12 after a change back. The change emits no events and keeps the control pristine. The attributes keep the value in any order. A change of prompt keeps the raw value.
Fixes:
A value with the mask length and its literals in place, such as the igcChange detail in withFormatting mode, keeps its positions. Before, 12-34 showed as 12-_3, so a two-way binding broke the text.
A write of the same value, mask or prompt, as React wrappers do on each render, keeps the typed text.
A change of prompt keeps the empty positions of the text.
A focused empty control shows the empty mask of a new mask or prompt.
Type of Change
Bug fix (non-breaking change that fixes an issue)
New feature (non-breaking change that adds functionality)
Checklist
My code follows the project's coding standards
I have tested my changes locally
I have updated documentation if needed
I have added a CHANGELOG.md entry under [Unreleased]
After the first render, a change of mask makes the value the raw text
that the new mask shows. Value 1234 becomes 12 after a change from
00-00 to 00, and stays 12 after a change back. The change emits no
events and keeps the control pristine. The attributes keep the value
in any order. A change of prompt keeps the raw value.
Fixes:
- A value with the mask length and its literals in place, such as the
igcChange detail in withFormatting mode, keeps its positions. Before,
12-34 showed as 12-_3, so a two-way binding broke the text.
- A write of the same value, mask or prompt, as React wrappers do on
each render, keeps the typed text.
- A change of prompt keeps the empty positions of the text.
- A focused empty control shows the empty mask of a new mask or prompt.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Mask-input initialization remains attribute-order dependent, and form reset can skip rebuilding the display, leaving an invalid state instead of restoring the default.
Updates mask input behavior so mask changes fit the stored value to the displayed text, while formatted values and repeated binding writes preserve character positions.
Changes:
Fits values to new masks after the first render without emitting events.
Preserves formatted text, empty positions, and focused empty masks.
Adds regression and property-based tests, plus specification and changelog updates.
File
Description
src/components/mask-input/spec.md
Documents value fitting, position preservation, and test scenarios.
src/components/mask-input/mask-parser.ts
Recognizes masked text, extracts raw values, and swaps prompts.
src/components/mask-input/mask-parser.spec.ts
Tests formatted input parsing and prompt replacement.
Before the first render, a change of mask or prompt reads the last
written value again. So masked text and prompt attributes give the same
value in any order: value="12-34" mask="00-00" and the reverse both give
1234. A setRangeText edit before the first render is kept too.
A form reset builds the text from the default value again, also when
the raw value stays the same. Before, a text with an empty position,
such as _1 for the mask 0C, stayed after the reset and kept badInput set.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Changing the prompt character can erase an entered character from the displayed value while leaving the raw value unchanged, causing a display/submission mismatch.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Prompt changes erase input characters that collide with the prompt
src/components/mask-input/mask-parser.ts:396
After the first render, with mask="CCC" and value a*b, changing the prompt from _ to * and back displays a_b, while the raw value and submission in raw mode remain a*b. The second change mistakes the entered * for an empty slot. Preserve filled-slot information across prompt changes, or explicitly handle collisions with entered characters, so changing the prompt back does not erase existing text.
The text cannot tell a typed character from a prompt that is the same
character. With mask CCC and value a*b, a prompt change from _ to * and
back showed a_b, while the value stayed a*b.
A prompt change now swaps the prompt in place only while the text still
shows the raw value. If it does not, the text is built from the raw
value again.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Active findings show that prompt changes and same-value writes can silently discard raw characters or shift masked positions, including normalized Unicode digits.
Same-value writes can discard raw characters after a prompt change
src/components/mask-input/mask-input.ts:136
In raw mode, set mask = 'CCC' and value = 'a*b', then change prompt to '*': element.value = element.value reparses the unchanged value and stores/submits 'ab'. This silently loses data during a React-style same-value write. Preserve the existing raw state for these writes while still normalizing an explicitly restored default on form reset.
A prompt change now draws the text again from the last text that was
written or edited, with the prompt that it had. Before, a text with a
character that matched the new prompt was built from the compact raw
value, so its empty positions moved. With mask CCCC, _a*b came back as
a*b_ after a change to * and back. With mask 00-00, _١-٣٤ became 13-4*.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because a prompt change followed by a same-value assignment can silently lose a literal character from the raw/submitted value and overwrite its source.
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
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.
Description
After the first render, a change of mask makes the value the raw text that the new mask shows. Value 1234 becomes 12 after a change from 00-00 to 00, and stays 12 after a change back. The change emits no events and keeps the control pristine. The attributes keep the value in any order. A change of prompt keeps the raw value.
Fixes:
Type of Change
Checklist
CHANGELOG.mdentry under[Unreleased]