Skip to content

fix(mask): tell the mask literals by position - 21.2.x - #18101

Open
Hristo313 wants to merge 2 commits into
21.2.xfrom
hhristov/fix-mask-literal-positions-21.2.x
Open

Hristo313 wants to merge 2 commits into
21.2.xfrom
hhristov/fix-mask-literal-positions-21.2.x

Conversation

@Hristo313

Copy link
Copy Markdown
Contributor

Closes #17816

Description

  • MaskParsingService: a literal of the mask is told by its position and not by its value.
    • parseValueFromMask skips only the characters at the literal positions. Before, it removed every character that equals a literal, wherever it was.
    • applyMask reads a text with the mask by position. Any other value is the raw value and fills the editable positions in order, with nothing removed from it.
    • A new internal isMaskedText() holds the rule: a text has the mask when it has the length of the mask, each literal is in its place and no editable position holds half of an astral character. It follows isMaskedText in the igc-mask-input parser.
    • getNonLiteralValues is removed, as nothing uses it.
  • IgxMaskDirective is not changed.

Motivation / Context

With the mask +1 (000) 000-0000, the literals are +, 1, the space, (, ) and -. Each 1 was taken for a literal:

  • Typing 5551234567 showed +1 (555) 123-4567, but the value was 555234567.
  • On the next focus the input showed +1 (555) 234-567_, because the focus applies the mask to the text of the input again.
  • The value 5551234567 set from code was shown as +1 (555) 234-567_.
  • With includeLiterals, the value +1 (555) 123-4567 set from code was shown as +1 (555) 234-567_.
  • With the mask CCC-CCC, the text a-b-___ gave the value ab.

This is part of the igxMask / igc-mask-input parity work (#17811).

Behavior to be aware of: a value set from code that has literals in it but not the whole mask is now read as the raw value. With the mask 00/00, the value 12/3 is shown as 12/_3. Before, it was shown as 12/3_. A value with the whole mask, such as 12/34, and a raw value, such as 123, are read as expected. The rule can't be softer without bringing the bug back: if a character is skipped when it matches the literal the mask has reached, the raw value 1234567890 loses its first digit in the mask +1 (000) 000-0000. The changelog entry is marked as a behavioral change.

This is the port of #18095 to 21.2.x, with the fix for its review finding included. The library code is the same as in the 22.3.x port (#18100). It differs from master only where master converts the digits of other numbering systems, which this branch does not have. The new test in mask.directive.spec.ts is in the Jasmine form of this branch, with fakeAsync and tick.

The changelog entry is under a new 21.2.29 section, as 21.2.28 is released. The entries of #18086, which went in under 21.2.28, are moved there too.

Type of Change (check all that apply):

  • Bug fix
  • Tests
  • Changelog
  • Documentation

Component(s) / Area(s) Affected:

Mask

How Has This Been Tested?

  • Unit tests
  • Manual testing

Unit tests:

  • Four new tests in mask-parsing.service.spec.ts: the parsed value keeps a character that equals a literal, the mask applied to a raw value keeps it, a text with the mask keeps its positions, and a value without the whole mask is read as a raw value.
  • One new test in mask.directive.spec.ts: the scenario of the issue, typing and then the next focus.
  • One more case in the existing test for an astral character in applyMask: a raw value with the length of the mask.
  • The new tests fail without the fix. No existing test is changed otherwise.
  • On this branch the mask, date time editor, date utility, date picker, date range picker and time picker specs ran with Karma: 378 pass and 1 fails. The failing test is "getNumericInputFormat should return formats with date parts that the date-time editors can handle" in date-time.util.spec.ts, with NG0701: Missing locale data for the locale "ja-JP". It fails the same way without this change, because it needs locale data that another spec registers in a full run.

Manual testing, on the 22.3.x port and on master, in the dev demos with temporary fields (not part of this pull request):

  • Mask +1 (000) 000-0000: typing 5551234567 shows +1 (555) 123-4567 and the model value is 5551234567. The text stays the same after a blur and a focus.
  • The same mask with the value 5551234567 set from code: the input shows +1 (555) 123-4567.
  • The same mask with includeLiterals and the value +1 (555) 123-4567 set from code: the input shows +1 (555) 123-4567.
  • Mask CCC-CCC: typing a-b shows a-b-___ and the model value is a-b.

Test Configuration:

  • Angular version: 21.2.9
  • Browser(s): Chrome Headless 147 for the unit tests, Chrome 158 for the manual testing
  • OS: Windows 11

Checklist:

  • All relevant labels have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes CHANGELOG.MD updates for newly added functionality

🤖 Generated with Claude Code

Hristo313 and others added 2 commits December 4, 2026 10:39
A character that equals a literal of the mask was dropped from the raw
value and from a value set from code, wherever it was. With the mask
`+1 (000) 000-0000` the typed `5551234567` gave the value `555234567`.

A text with the mask, which has the mask length and each literal in its
place, is now read by position. Any other value is a raw value.

Also move the changelog entries for the prompt character fix (#17817)
to 21.2.29, as 21.2.28 is released, and drop a doubled blank line.

Closes #17816

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A raw value with an astral character and the length of the mask was
taken for a text with the mask and split by UTF-16 code unit, so the
character took two positions. With the mask `CCC` the value `😀a` was
shown as `__a` and not as `_a_`.

A text with the mask has no half of an astral character in an editable
position, as the mask never writes one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings December 4, 2026 11:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The positional mask-literal fix has no active review issues.

No open issues 🎉

What changed in this PR

Ports the positional mask-literal fix to 21.2.x, preserving user-entered characters that match literals and advancing parity with igc-mask-input.

Changes:

  • Distinguishes fully masked text from raw values using character positions.
  • Adds regression coverage for literal-valued input, refocusing, and astral characters.
  • Documents the behavior change and organizes release notes under 21.2.29.
File Description
projects/​igniteui-angular/​directives/​src/​directives/​mask/​README.md Explains positional literals and raw-value handling.
projects/​igniteui-angular/​directives/​src/​directives/​mask/​mask.directive.spec.ts Tests value preservation during typing and refocusing.
projects/​igniteui-angular/​directives/​src/​directives/​mask/​mask-parsing.service.ts Implements positional literal detection and removes obsolete filtering.
projects/​igniteui-angular/​directives/​src/​directives/​mask/​mask-parsing.service.spec.ts Covers raw and masked values, literal collisions, and astral input.
CHANGELOG.md Adds 21.2.29 notes and relocates prior prompt-character fixes.

Review effort: Balanced

@Hristo313 Hristo313 added the ❌ status: awaiting-test PRs awaiting manual verification label Dec 4, 2026
@Hristo313
Hristo313 requested a review from mddragnev December 4, 2026 11:57

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants