Skip to content

fix(mask): tell the mask literals by position - master - #18095

Open
Hristo313 wants to merge 2 commits into
masterfrom
hhristov/fix-mask-literal-positions
Open

Hristo313 wants to merge 2 commits into
masterfrom
hhristov/fix-mask-literal-positions

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. A text has the mask when it has the length of the mask and each literal is in its place. Any other value is the raw value and fills the editable positions in order, with nothing removed from it.
    • A new internal isMaskedText() holds that rule. It is the same rule as isMaskedText in the igc-mask-input parser. A literal is also recognized when it is written as a digit of another numbering system, as before.
    • getNonLiteralValues is removed, as nothing uses it.
  • IgxMaskDirective is not changed, except for a doubled blank line in writeValue.

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.

The changelog entry is under 22.3.3, next to the entries of #18084, as the fix is also meant for 22.3.x and 21.2.x. The ports follow after the review of this pull request.

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.
  • The new tests fail without the fix. Before them, no test used a mask in which a literal is also valid input.
  • No existing test is changed.
  • The mask, date time editor, date utility, date picker, date range picker and time picker specs pass, 584/584 in 12 spec files.

Manual testing, 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. Undo and redo restore the text and the value.

Test Configuration:

  • Angular version: 22.3.0
  • Browser(s): Chrome 158
  • 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

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 drop two doubled blank lines left by the prompt character fix.

Closes #17816

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

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.

🟡 Changes recommended

The mask-length-matching branch splits astral characters into invalid positions, shifting subsequent valid characters and requiring code-point-safe iteration with a regression test.

1 open issue
What changed in this PR

Fixes mask literals being confused with editable characters, addressing #17816 and advancing parity with igc-mask-input.

Changes:

  • Identifies literals by position when applying masks and extracting values.
  • Adds regression tests for literal-valued input and refocusing.
  • Documents the changed handling of partially formatted programmatic values.
File Description
projects/​igniteui-angular/​directives/​src/​directives/​mask/​README.md Explains positional literals and formatted-value detection.
projects/​igniteui-angular/​directives/​src/​directives/​mask/​mask.directive.ts Removes an extra blank line only.
projects/​igniteui-angular/​directives/​src/​directives/​mask/​mask.directive.spec.ts Tests typing and refocusing with a numeric literal.
projects/​igniteui-angular/​directives/​src/​directives/​mask/​mask-parsing.service.ts Replaces value-based literal filtering with positional handling.
projects/​igniteui-angular/​directives/​src/​directives/​mask/​mask-parsing.service.spec.ts Tests literal preservation and raw-versus-formatted interpretation.
CHANGELOG.md Records the fix and behavioral change.

Review effort: Balanced

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 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

No active review issues are recorded for the positional mask-literal handling change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

[Mask] Raw value drops characters that equal a mask literal

3 participants