diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ede17f05..9480897c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Enter closes the open list also when no item is active, as in the select. Before, the list stayed open. - #### Library - The library supports the last 2 major versions of Chrome, Edge, Firefox, Opera and Safari. The fallbacks for older browsers are removed, and the styles no longer have vendor prefixes for them. +- #### Mask input + - A change of `mask` after the first render fits the value to the new mask. `value` becomes the raw value of the text that the new mask shows. For example, value `1234` with the mask `00-00` becomes `12` after a change to `00`, and stays `12` after a change back. The change emits no events and keeps the control pristine. The attributes and properties that you set before the first render do not fit the value. They read it with the final `mask` and `prompt`, in any order. A change of `prompt` keeps the raw value and the positions of the text. Before, `value` kept the characters that the mask cut, so the `raw` and `withFormatting` modes submitted different text. Ignite UI for Angular changes only the text. - #### Navigation drawer - A drawer that is `open` on its first render shows at once, with no slide and no backdrop fade. This also applies when a framework renders the drawer open after a user action. To slide it in, call `show()`, or set `open` after the first render. - #### QR code @@ -114,6 +116,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - #### Mask input - The submitted value is `value`. A change of `valueMode`, `mask` or `prompt` updates it and the validity at once, also when the `value` attribute comes before `value-mode` or `mask`. Before, the form kept the old text, `badInput` could stay set for a valid value, and the attribute order could submit the raw text in `withFormatting` mode. - A formatted value that you empty submits nothing. Before, the form submitted the empty mask, such as `__-__`. + - A focused empty control shows the empty mask of a new `mask` or `prompt`. Before, it kept the old empty mask, and a typed character could put its old prompts or literals into the value. + - A write of the same `value`, `mask` or `prompt`, as a React wrapper does on each render, keeps the text that you typed. Before, it moved the characters after an empty position to the left. A write of the same empty value also removed the empty mask from a focused control. + - A change of `prompt` keeps the empty positions of the text. Before, it moved the characters after an empty position to the left. + - A change of `mask` or `prompt` keeps the placeholder on an unfocused control whose value fills no position, as a value write does. Before, it showed the empty mask. + - A value with the mask length and each literal in its place, such as the `igcChange` detail in `withFormatting` mode, keeps its positions. For example, `12-34` with the mask `00-00` shows `12-34`, and `value` in `raw` mode reads `1234`. Before, the input read the literals as typed characters and showed `12-_3`, so a two-way binding in `withFormatting` mode broke the text. A prompt character in the value shows as an empty position. - #### QR code - A logo no longer makes a short value unreadable. The component selects a larger version, so that the logo hides no more codewords than the error correction recovers. When you set `version`, the logo gets smaller. - A code with `square-style="circle"` no longer fails to scan at some sizes, about 1 time in 10. For this fix, a `square` corner dot in a `circle` corner square draws as a circle. diff --git a/src/components/mask-input/mask-input.spec.ts b/src/components/mask-input/mask-input.spec.ts index cf4594c09..3463d39c6 100644 --- a/src/components/mask-input/mask-input.spec.ts +++ b/src/components/mask-input/mask-input.spec.ts @@ -1,6 +1,7 @@ import { elementUpdated, expect, fixture } from '@open-wc/testing'; import { html } from 'lit'; import { spy } from 'sinon'; +import { internalsOf } from '#internals/controllers/internals.js'; import { ctrlKey, metaKey, @@ -14,6 +15,7 @@ import { runHostComboboxTests, } from '#internals/testing/form-testbed.spec.js'; import { + simulateBackspaceOver, simulateBlur, simulateFocus, simulateInput, @@ -104,6 +106,28 @@ describe('Masked input', () => { expect(input.value).to.equal(parser.apply(element.value)); }); + for (const [mask, value, changed, back] of [ + ['CCC', 'a*b', 'a*b', 'a*b'], + ['CCCC', '_a*b', '*a*b', '_a*b'], + ['00-00', '_١-٣٤', '*1-34', '_1-34'], + ]) { + it(`keeps the positions of ${value} on a change of prompt and back`, async () => { + element.mask = mask; + element.value = value; + const raw = element.value; + await elementUpdated(element); + + element.prompt = '*'; + await elementUpdated(element); + expect(input.value).to.equal(changed); + + element.prompt = '_'; + await elementUpdated(element); + expect(input.value).to.equal(back); + expect(element.value).to.equal(raw); + }); + } + it('mask change (no value)', async () => { element.mask = 'CCCC'; syncParser(); @@ -123,6 +147,33 @@ describe('Masked input', () => { expect(input.value).to.equal(parser.apply(element.value)); }); + it('shows the empty mask of a new mask or prompt while focused', async () => { + element.focus(); + element.mask = '00-00'; + await elementUpdated(element); + expect(input.value).to.equal('__-__'); + + element.prompt = '*'; + await elementUpdated(element); + expect(input.value).to.equal('**-**'); + + // A write of the same empty value keeps the empty mask. + element.value = ''; + await elementUpdated(element); + expect(input.value).to.equal('**-**'); + + element.setSelectionRange(0, 0); + input.value = '1**-**'; + input.setSelectionRange(1, 1); + simulateInput(input, { + inputType: 'insertText', + skipValueProperty: true, + }); + await elementUpdated(element); + + expect(element.value).to.equal('1'); + }); + it('placeholder is updated correctly', async () => { const placeholder = 'Enter payment info'; syncParser(); @@ -852,6 +903,43 @@ describe('Masked input', () => { expect(input.value).to.equal('1_2-___'); }); + it('keeps interior holes on a write of the same value, mask or prompt', async () => { + await type('123'); + await simulateBackspaceOver(element, 0, 1); + expect(input.value).to.equal('_23_______'); + + const { value, mask, prompt } = element; + element.value = value; + element.mask = mask; + element.prompt = prompt; + await elementUpdated(element); + + expect(input.value).to.equal('_23_______'); + expect(element.value).to.equal('23'); + }); + + it('draws a change of prompt from the text of a new mask', async () => { + await type('123'); + await simulateBackspaceOver(element, 0, 1); + + element.mask = 'CC-CC'; + element.prompt = '*'; + await elementUpdated(element); + + expect(input.value).to.equal('23-**'); + }); + + it('keeps interior holes on a change of prompt', async () => { + await type('123'); + await simulateBackspaceOver(element, 0, 1); + + element.prompt = '*'; + await elementUpdated(element); + + expect(input.value).to.equal('*23*******'); + expect(element.value).to.equal('23'); + }); + it('starts a new step when the caret moves', async () => { await type('12'); @@ -1096,6 +1184,175 @@ describe('Masked input', () => { }); }); + const shown = () => spec.element.renderRoot.querySelector('input')!.value; + + describe('a change of mask fits the value', () => { + beforeEach(async () => { + await spec.setAttributes({ mask: '00-00', value: '1234' }, true); + }); + + it('to the raw value of the new text', async () => { + spec.setProperties({ mask: '00' }); + + expect(spec.element.value).to.equal('12'); + spec.assertSubmitHasValue('12'); + + spec.setProperties({ valueMode: 'withFormatting' }); + expect(spec.element.value).to.equal('12'); + spec.assertSubmitHasValue('12'); + + await elementUpdated(spec.element); + expect(shown()).to.equal('12'); + }); + + it('in one submission, with no events, and the control stays pristine', () => { + const setFormValue = spy(internalsOf(spec.element)!, 'setFormValue'); + const emitEvent = spy(spec.element, 'emitEvent'); + + spec.setProperties({ mask: '00' }); + + expect(setFormValue).calledOnceWith('12'); + expect(emitEvent).not.called; + spec.assertIsPristine(); + }); + + it('and a switch back does not restore the cut characters', () => { + spec.setProperties({ mask: '00' }); + spec.setProperties({ mask: '00-00' }); + + expect(spec.element.value).to.equal('12'); + // `badInput` stops the submit, so read the form data. + expect(spec.formData.get(spec.element.name)).to.equal('12'); + expect(spec.element.validity.badInput).to.be.true; + }); + + it('to an empty value when no character fits', async () => { + spec.setProperties({ mask: 'LL' }); + + expect(spec.element.value).to.equal(''); + spec.assertSubmitHasValue(null); + + await elementUpdated(spec.element); + expect(shown()).to.equal(''); + }); + + it('but a change of prompt keeps the raw value', () => { + spec.setProperties({ mask: '00', value: '1234' }); + spec.setProperties({ prompt: '*' }); + + expect(spec.element.value).to.equal('1234'); + spec.assertSubmitHasValue('1234'); + }); + + it('but not while the attributes set up the control', async () => { + const bed = createFormAssociatedTestBed( + html`` + ); + await bed.setup(IgcMaskInputComponent.tagName); + + expect(bed.element.value).to.equal('1234'); + }); + }); + + describe('a masked text as the value', () => { + beforeEach(async () => { + await spec.setProperties({ + mask: '00-00', + valueMode: 'withFormatting', + }); + }); + + for (const [value, text, raw] of [ + ['12-34', '12-34', '1234'], + ['1_-34', '1_-34', '134'], + ['1a-34', '1_-34', '1a34'], + ]) { + it(`keeps the positions of ${value} and stores ${raw}`, async () => { + await spec.setProperties({ value }, true); + + expect(spec.element.value).to.equal(text); + expect(shown()).to.equal(text); + expect(spec.formData.get(spec.element.name)).to.equal(text); + + spec.setProperties({ valueMode: 'raw' }); + expect(spec.element.value).to.equal(raw); + }); + } + + it('stores the raw value also for a mask without literals', () => { + spec.setProperties({ mask: 'CCC', value: 'a_c' }); + expect(spec.element.value).to.equal('a_c'); + + spec.setProperties({ valueMode: 'raw' }); + expect(spec.element.value).to.equal('ac'); + }); + + for (const [attributes, value, text] of [ + ['value="12-34" mask="00-00"', '1234', '12-34'], + ['mask="00-00" value="12-34"', '1234', '12-34'], + ['value="a_b" mask="CCC" prompt="*"', 'a_b', 'a_b'], + ['prompt="*" mask="CCC" value="a_b"', 'a_b', 'a_b'], + ]) { + it(`reads ${attributes} in any order`, async () => { + const form = await fixture( + `
` + ); + const element = form.querySelector(IgcMaskInputComponent.tagName)!; + + expect(element.value).to.equal(value); + expect(new FormData(form).get('setup')).to.equal(value); + expect(element.renderRoot.querySelector('input')!.value).to.equal( + text + ); + }); + } + + it('reads a setRangeText edit of the setup with the final mask', () => { + const element = document.createElement(IgcMaskInputComponent.tagName); + + element.value = '99'; + element.setRangeText('1234', 0, 2); + element.mask = '00-00'; + + expect(element.value).to.equal('1234'); + }); + + it('keeps its positions on a change of prompt', () => { + spec.setProperties({ value: '1_-34' }); + spec.setProperties({ prompt: '*' }); + expect(spec.element.value).to.equal('1*-34'); + + spec.setProperties({ valueMode: 'raw' }); + expect(spec.element.value).to.equal('134'); + }); + + it('fits a new mask', () => { + spec.setProperties({ value: '12-34', mask: '00/00' }); + + expect(spec.element.value).to.equal('12/34'); + spec.assertSubmitHasValue('12/34'); + }); + }); + + it('shows the default again on a reset to the same raw value', async () => { + await spec.setAttributes({ mask: '0C', value: '1' }, true); + + // `_1` keeps the raw value `1`. + await spec.setProperties({ value: '_1' }, true); + expect(shown()).to.equal('_1'); + expect(spec.element.validity.badInput).to.be.true; + + spec.reset(); + await elementUpdated(spec.element); + + expect(shown()).to.equal('1_'); + expect(spec.element.validity.badInput).to.be.false; + }); + it('updates badInput after a change of mask', () => { spec.setProperties({ mask: '00-00', value: '12' }); expect(spec.element.validity.badInput).to.be.true; diff --git a/src/components/mask-input/mask-input.ts b/src/components/mask-input/mask-input.ts index 361dd74dd..6cbde5c46 100644 --- a/src/components/mask-input/mask-input.ts +++ b/src/components/mask-input/mask-input.ts @@ -102,6 +102,12 @@ export default class IgcMaskInputComponent extends MaskBehaviorMixin( transformers: IgcMaskInputComponent._transformers, }); + /** The last value written. A `mask` or `prompt` change before the first update reads it again. */ + private _setupValue = ''; + + /** The last text written or edited, and its prompt. A prompt change draws the text from it again. */ + private _source = { text: '', prompt: this._parser.prompt }; + //#endregion //#region Public attributes and properties @@ -130,9 +136,15 @@ export default class IgcMaskInputComponent extends MaskBehaviorMixin( @property() public set value(string: string) { const value = string ?? ''; - this._maskedValue = this._parser.apply(value); - this._updateMaskDisplay(); - this._formValue.setValueAndFormState(value); + const raw = this._parser.rawValue(value); + this._setupValue = value; + + // A write of the current value, as a React wrapper does on each render, keeps the text. + if (value !== this.value || raw !== this._formValue.value) { + this._showText(value); + } + + this._formValue.setValueAndFormState(raw); } public get value(): string { @@ -152,8 +164,23 @@ export default class IgcMaskInputComponent extends MaskBehaviorMixin( */ @property() public override set mask(value: string) { + const previous = this._parser.mask; this._parser.mask = value; + + if (this._parser.mask === previous) { + return; + } + + if (!this.hasUpdated) { + this._applySetupValue(); + return; + } + + // A bare write of the new raw value. The `reads` hook submits it. this._reapplyMask(); + this._writeFrom('normalize', () => { + this._formValue.value = this._parser.parse(this._maskedValue); + }); } public override get mask(): string { @@ -168,8 +195,25 @@ export default class IgcMaskInputComponent extends MaskBehaviorMixin( */ @property() public override set prompt(value: string) { + const previous = this._parser.prompt; this._parser.prompt = value; - this._reapplyMask(); + + if (this._parser.prompt === previous) { + return; + } + + if (!this.hasUpdated) { + this._applySetupValue(); + return; + } + + // The source keeps the positions, also of a character that matches the new prompt. + const { text, prompt } = this._source; + this._maskedValue = this._parser.apply(text, prompt); + + if (!this._focused) { + this._updateMaskDisplay(); + } } public override get prompt(): string { @@ -200,13 +244,12 @@ export default class IgcMaskInputComponent extends MaskBehaviorMixin( //#region Internal methods - /** - * Bypasses the `value` setter, whose `apply(parse(x))` left-packs the text: - * `1_2-___` would become `12_-___`. - */ + /** Not through the `value` setter, which also empties a focused empty mask. */ protected override _commitMaskedValue(value: string): void { this._maskedValue = value; + this._source = { text: value, prompt: this._parser.prompt }; this._formValue.setValueAndFormState(this._parser.parse(value)); + this._setupValue = this._formValue.value; // Only `setRangeText` gets here unfocused. An emptied mask then reads as empty, as after a blur. if (!this._focused) { @@ -218,11 +261,42 @@ export default class IgcMaskInputComponent extends MaskBehaviorMixin( this._emitTouchedEvent('igcInput', { detail: this.value }); } - /** Applies a new mask or prompt to the current value. */ + /** Shows a value in the current mask. An empty mask shows the placeholder. */ + private _showText(value: string): void { + this._maskedValue = this._parser.apply(value); + this._source = { text: value, prompt: this._parser.prompt }; + this._updateMaskDisplay(); + } + + /** Reads the setup value again with the current mask and prompt. The `reads` hook submits it. */ + private _applySetupValue(): void { + const value = this._setupValue; + + if (value) { + this._showText(value); + this._writeFrom('normalize', () => { + this._formValue.value = this._parser.rawValue(value); + }); + } + } + + /** Shows the default first: the setter keeps the text of the same raw value, and validation reads it. */ + protected override _restoreDefaultValue(): void { + this._showText(this._formValue.defaultValue); + super._restoreDefaultValue(); + } + + /** Shows the value, or the empty mask of a focused control, in a new mask. */ private _reapplyMask(): void { - if (this.value) { + if (this._formValue.value || this._maskedValue) { this._maskedValue = this._parser.apply(this._formValue.value); } + + this._source = { text: this._maskedValue, prompt: this._parser.prompt }; + + if (!this._focused) { + this._updateMaskDisplay(); + } } protected override _isValueEmpty(): boolean { diff --git a/src/components/mask-input/mask-parser.property.spec.ts b/src/components/mask-input/mask-parser.property.spec.ts index 0f2fae727..b18ff4fbf 100644 --- a/src/components/mask-input/mask-parser.property.spec.ts +++ b/src/components/mask-input/mask-parser.property.spec.ts @@ -162,6 +162,17 @@ describe('Mask parser properties', () => { ); }); + it('keeps a masked text when it applies it again', () => { + fc.assert( + fc.property(tokens, anyPrompt, anyInput, (parts, prompt, input) => { + const { parser } = setup(parts, prompt); + const masked = parser.apply(input); + + expect(parser.apply(masked)).to.equal(masked); + }) + ); + }); + it('places each valid character of a replace at the next input position', () => { fc.assert( fc.property(filledMask, ({ parts, prompt, input }) => { diff --git a/src/components/mask-input/mask-parser.spec.ts b/src/components/mask-input/mask-parser.spec.ts index 251ae17ec..553196bcb 100644 --- a/src/components/mask-input/mask-parser.spec.ts +++ b/src/components/mask-input/mask-parser.spec.ts @@ -82,6 +82,48 @@ describe('Mask parser', () => { expect(parser.apply('ABCD99')).to.equal('CC-ABCD-99_-99'); }); + it('keeps the positions of a masked text', () => { + parser.mask = '00-00'; + + expect(parser.isMaskedText('12-34')).to.be.true; + expect(parser.apply('12-34')).to.equal('12-34'); + expect(parser.apply('1_-34')).to.equal('1_-34'); + expect(parser.apply('1a-34')).to.equal('1_-34'); + // A masked text keeps its UTF-16 positions, also for an astral character. + expect(parser.apply('😀-34')).to.equal('__-34'); + + // The text of another mask, or a raw value, is input. + expect(parser.isMaskedText('12/34')).to.be.false; + expect(parser.apply('12/34')).to.equal('12-_3'); + expect(parser.isMaskedText('1234')).to.be.false; + + parser.mask = 'CC-CC'; + expect(parser.apply('ab-c')).to.equal('ab--c'); + + // Without literals, the mask length is enough. + parser.mask = 'CCC'; + expect(parser.isMaskedText('a_c')).to.be.true; + expect(parser.apply('a_c')).to.equal('a_c'); + }); + + it('reads the raw value of a masked text only', () => { + parser.mask = '00-00'; + + expect(parser.rawValue('1_-34')).to.equal('134'); + expect(parser.rawValue('1a-34')).to.equal('1a34'); + expect(parser.rawValue('12345')).to.equal('12345'); + }); + + it('reads a masked text with the prompt that it was written with', () => { + parser.mask = 'CC_CC'; + parser.prompt = '*'; + + // The literal `_` stays, and a `*` of the input is a character. + expect(parser.apply('1___4', '_')).to.equal('1*_*4'); + expect(parser.apply('**_*4', '_')).to.equal('**_*4'); + expect(parser.apply('**_*4')).to.equal('**_*4'); + }); + it('validates mask pattern rules', () => { const validate = (string: string) => parser.isValidString(parser.apply(string)); diff --git a/src/components/mask-input/mask-parser.ts b/src/components/mask-input/mask-parser.ts index 78c24fbb8..0bfeb22b0 100644 --- a/src/components/mask-input/mask-parser.ts +++ b/src/components/mask-input/mask-parser.ts @@ -84,11 +84,13 @@ function isSurrogate(char: string): boolean { return (char.charCodeAt(0) & 0xf800) === 0xd800; } +/** Returns the ASCII digit of a Unicode digit. Any other character stays. */ +function toAsciiDigit(char: string): string { + return UNICODE_DIGIT_TO_ASCII.get(char.charCodeAt(0)) ?? char; +} + function replaceUnicodeNumbers(text: string): string { - return text.replace( - /\p{Nd}/gu, - (digit) => UNICODE_DIGIT_TO_ASCII.get(digit.charCodeAt(0)) ?? digit - ); + return text.replace(/\p{Nd}/gu, toAsciiDigit); } const MASK_PATTERNS = new Map([ @@ -378,6 +380,11 @@ export class MaskParser { }; } + /** The raw value of a value from code. A masked text loses its literals and prompts. Other input stays. */ + public rawValue(input: string): string { + return this.isMaskedText(input) ? this.parse(input) : input; + } + /** Unmasks the string: removes the prompts and the literals. */ public parse(masked = ''): string { const literalPositions = this.literalPositions; @@ -405,8 +412,26 @@ export class MaskParser { }); } - /** Fits the input into the mask from left to right and skips invalid characters. */ - public apply(input = ''): string { + /** Whether the input has the mask length and each literal in its place, as a text that `apply` returns. */ + public isMaskedText(input: string): boolean { + if (input.length !== this._escapedMask.length) { + return false; + } + + for (const [position, literal] of this._literals) { + if (input[position] !== literal) { + return false; + } + } + + return true; + } + + /** + * Fits the input into the mask from left to right and skips invalid characters. A masked text keeps its + * positions. `empty`, the prompt of the input, marks an empty position. + */ + public apply(input = '', empty = this.prompt): string { const literals = this._literals; const prompt = this.prompt; const escapedMask = this._escapedMask; @@ -422,10 +447,12 @@ export class MaskParser { return result.join(''); } - // Normalize Unicode digits to ASCII. Split by code point, so that an astral character - // is one invalid character. - const normalizedInput = Array.from(replaceUnicodeNumbers(input)); - const inputLength = normalizedInput.length; + // A masked text splits by UTF-16 unit, as its positions do. Other input splits by + // code point, so that an astral character is one invalid character. + const chars = this.isMaskedText(input) + ? input.split('').filter((_, position) => !literals.has(position)) + : Array.from(input); + const inputLength = chars.length; let inputIndex = 0; for (let i = 0; i < length && inputIndex < inputLength; i++) { @@ -433,8 +460,15 @@ export class MaskParser { continue; } - if (validate(normalizedInput[inputIndex], escapedMask[i])) { - result[i] = normalizedInput[inputIndex]; + // Normalize after the check, so that a digit prompt stays a prompt. + const char = chars[inputIndex]; + + if (char !== empty) { + const normalized = toAsciiDigit(char); + + if (validate(normalized, escapedMask[i])) { + result[i] = normalized; + } } // An invalid character is consumed too. diff --git a/src/components/mask-input/spec.md b/src/components/mask-input/spec.md index c44d87dfb..0b22fda56 100644 --- a/src/components/mask-input/spec.md +++ b/src/components/mask-input/spec.md @@ -64,6 +64,7 @@ | 13 | 2026-11-11 | Enter submits as in a native form, after the `keypress` | | 14 | 2026-11-19 | The submitted value is `value`; it follows a change of `valueMode`, `mask` or `prompt`, and an emptied control submits nothing | | 15 | 2026-11-20 | A value from code and the first render show at once; no transitions with reduced motion | +| 16 | 2026-11-25 | A change of `mask` fits the value; a masked text as the value keeps its positions; a same-value write and a `prompt` change keep the text | ## Overview @@ -224,6 +225,17 @@ into a literal by escaping it: An empty control returns an empty string in both modes. +A value with the mask length and each literal in its place, such as `12-34` for the mask `00-00`, is a masked text. +It keeps its positions, also the empty ones, and `value` in `raw` mode reads `1234`. So the `igcChange` detail of +`withFormatting` mode can go back into `value`, as a two-way binding does. A prompt character in a value shows as an +empty position, and a masked text drops it from the raw value. A write of the current value keeps the text. + +A change of `mask` after the first render fits the value to the new mask. `value` becomes the raw value of the text +that the new mask shows. Value `1234` with the mask `00-00` becomes `12` after a change to `00`, and stays `12` after a +change back. The change emits no events and keeps the control pristine. The attributes and properties that you set +before the first render do not fit the value. They read it with the final `mask` and `prompt`, in any order. A change +of `prompt` keeps the raw value and the positions of the text. Ignite UI for Angular changes only the text. + #### Prompt character ```html @@ -440,8 +452,10 @@ The groups below mirror the `describe` blocks of the suite. ### Generic properties 1. Sensible default values. -2. Changing the prompt character, with and without a value. -3. Changing the mask, with and without a value. +2. Changing the prompt character, with and without a value. A change and a change back keep the positions of the + value, also of a character that the new prompt matches. +3. Changing the mask, with and without a value. A focused empty control shows the empty mask of a new mask or + prompt, and keeps it on a write of the same empty value. 4. The placeholder is updated correctly. 5. An empty value, with and without literals, and an empty read-only value on focus. 6. Reading the value without literals, and switching a value with literals to one without. @@ -465,7 +479,8 @@ Grouped as `Undo / redo` in the suite. 18. Collapses a run of typed characters into a single step, and redoes the restored run. 19. Supports the alternate shortcuts. -20. Preserves interior holes in the mask. +20. Preserves interior holes in the mask, also on a write of the same value, mask or prompt, and on a change of + prompt, also after a change of mask. 21. Starts a new step when the caret moves. 22. Collapses a run of backspaces into a single step, and keeps typing and deleting as separate steps. 23. Records a paste as its own step. @@ -480,11 +495,10 @@ Grouped as `Undo / redo` in the suite. Driven by `createFormAssociatedTestBed`. 29. Is form associated, and is not associated on submit without a value. -30. Is associated on submit, including with value formatting enabled. The submitted value follows a change of - `valueMode`, `mask` and `prompt`, also from attributes in any order, and `badInput` follows a change of `mask`. - A formatted value that the user empties submits nothing. +30. Is associated on submit, including with value formatting enabled. `badInput` follows a change of `mask`. A + formatted value that the user empties submits nothing. 31. Is correctly reset on form reset, with and without value formatting, after a `setAttribute` call, and refreshes - the rendered masked value and placeholder afterwards. + the rendered masked value and placeholder afterwards. A reset to the same raw value shows the default text again. 32. Is correctly submitted on Enter, and does not submit while the value is invalid. A real Enter submits once. 33. Reflects the disabled state of an ancestor `fieldset`. @@ -496,49 +510,67 @@ Driven by `createFormAssociatedTestBed`. The focus after the form checks and the `invalid` event rules come from the form-associated mixin. The [input suite](../input/spec.md#form-validity-checks) covers them. +#### the submitted value follows + +36. A change of `valueMode`, `mask` or `prompt` updates the submitted value in one submission, also from attributes + in any order. + +#### a change of mask fits the value + +37. The value becomes the raw value of the new text. The change submits once, emits no events and keeps the control + pristine. +38. A change back does not restore the cut characters. A value that fits no position becomes empty. +39. A change of `prompt` keeps the raw value. The attributes of the first render keep the value. + +#### a masked text as the value + +40. A masked text keeps its positions and its empty positions, and stores its raw value, also for a mask without + literals and from attributes in any order. A `setRangeText` edit before the first render reads with the final mask. +41. A change of `prompt` keeps its positions, and a change of `mask` fits it. + ### defaultValue -36. Form integration - correct initial state, correct submission, correct reset, and dropping the undo history on +42. Form integration - correct initial state, correct submission, correct reset, and dropping the undo history on reset. -37. Validation - fails the initial validation, and passes once `defaultValue` is updated. +43. Validation - fails the initial validation, and passes once `defaultValue` is updated. ### Validation message slots Generated by `runValidationContainerTests`. -38. `value-missing` with `required`. -39. `bad-input` with an unsatisfied mask pattern. -40. `custom-error` after `setCustomValidity`. -41. `invalid` with `required`. +44. `value-missing` with `required`. +45. `bad-input` with an unsatisfied mask pattern. +46. `custom-error` after `setCustomValidity`. +47. `invalid` with `required`. ### External label association Generated by `runExternalLabelAssociationTests`. -42. An external `label` bound through `for`, and a `label` wrapping the host, are projected onto the native input as +48. An external `label` bound through `for`, and a `label` wrapping the host, are projected onto the native input as `ariaLabelledByElements`, and clicking it focuses the control. A `label` added after the first render names the control from the first focus, an axe audit passes with only an external `label`, and the host `aria-labelledby` and `aria-label` follow the [naming order](../input/spec.md#naming-order). ### Parser and history unit suites -43. [`mask-parser.spec.ts`](./mask-parser.spec.ts) covers the parser on its own: every flag, literals and escaping, - applying and parsing values, Unicode digit normalization, and edge and boundary conditions, including UTF-16 - positions after an astral literal, and astral input and prompts rejected whole. -44. [`mask-history.spec.ts`](../../internals/mask-history.spec.ts) covers the history on its own: recording, coalescing, traversal +49. [`mask-parser.spec.ts`](./mask-parser.spec.ts) covers the parser on its own: every flag, literals and escaping, + applying and parsing values, a masked text as input, Unicode digit normalization, and edge and boundary + conditions, including UTF-16 positions after an astral literal, and astral input and prompts rejected whole. +50. [`mask-history.spec.ts`](../../internals/mask-history.spec.ts) covers the history on its own: recording, coalescing, traversal and invalidation of the steps. -45. [`mask-parser.property.spec.ts`](./mask-parser.property.spec.ts) checks, for generated masks, prompts and input: +51. [`mask-parser.property.spec.ts`](./mask-parser.property.spec.ts) checks, for generated masks, prompts and input: the escaped mask and literal positions; `apply` and `replace` never throw, keep the mask length, literals and - flag rules, and never split an astral character; the `apply` / `parse` round-trip; digit normalization; the - non-literal position lookups; and prompt normalization. + flag rules, and never split an astral character; the `apply` / `parse` round-trip; `apply` keeps a masked text; + digit normalization; the non-literal position lookups; and prompt normalization. ### Host ARIA -46. The shared host description suite: the host `aria-describedby` describes the native control after the helper +52. The shared host description suite: the host `aria-describedby` describes the native control after the helper text, and follows a change and a removal. `required` sets `aria-required`. -47. The shared host combobox suite (`runHostComboboxTests`): the cases of the +53. The shared host combobox suite (`runHostComboboxTests`): the cases of the [input](../input/spec.md#host-combobox-state), without the projection case. -48. The shared focus suite (`runFocusBeforeRenderTests`): a `focus()` call right after the element connects focuses +54. The shared focus suite (`runFocusBeforeRenderTests`): a `focus()` call right after the element connects focuses the same element as a call after the first render. `blur()`, a later `focus()` on another element and a removal that lasts until the render cancel the call, but a move in the same task keeps it. After the render, `focus()` takes the focus at once and `blur()` removes it. A `focus()` call before the render on a component with @@ -553,6 +585,8 @@ The [input suite](../input/spec.md#value-state-motion) covers the motion of the - The mask input does not expose a `type` attribute, since it is always an input of type `text`. - The component does not format values by locale; the mask is a literal pattern, not a number or date format. Use [`igc-date-time-input`](../date-time-input/spec.md) for date and time editing. +- A value from code keeps the characters that the mask cannot show, also with the `mask` of the same setup: + `value="1234" mask="00"` gives `1234` in any attribute order. Only a change of `mask` after the first render fits it. ## Accessibility