From 402e43cd8db20b365404789ef46085688ec3d6e1 Mon Sep 17 00:00:00 2001 From: Radoslav Karaivanov Date: Wed, 25 Nov 2026 16:20:03 +0200 Subject: [PATCH] fix(forms): update the name and readonly attributes at once A change of `name` now writes the `name` attribute at once, as on a native control. Before, a control that submits a string, such as the input, the select or a single selection combo, used the old name in the form data until the next render. A null or undefined name removes the attribute. A change of `readOnly` now writes the `readonly` attribute at once, so constraint validation follows it. Before, a required empty control that became read-only blocked a form submission until the next render. This applies to the date picker, date range picker, date time input, input, mask input, rating and textarea. The attribute write does not set the property again, so the property keeps the value that code set, as with `reflect: true`. A new `@reflect` JSDoc tag keeps these properties marked as reflected in the manifest. --- .../skills/add-component-property/SKILL.md | 7 + .github/CODING_GUIDELINES.md | 11 +- CHANGELOG.md | 3 + api-reference/igc-checkbox.md | 2 +- api-reference/igc-color-picker.md | 2 +- api-reference/igc-combo.md | 2 +- api-reference/igc-date-picker.md | 2 +- api-reference/igc-date-range-picker.md | 2 +- api-reference/igc-date-time-input.md | 4 +- api-reference/igc-file-input.md | 2 +- api-reference/igc-input.md | 4 +- api-reference/igc-mask-input.md | 4 +- api-reference/igc-radio.md | 2 +- api-reference/igc-rating.md | 2 +- api-reference/igc-select.md | 2 +- api-reference/igc-switch.md | 2 +- api-reference/igc-textarea.md | 2 +- public-api.json | 3 - scripts/build-typedoc.mjs | 1 + src/components/checkbox/spec.md | 1 + src/components/color-picker/spec.md | 1 + src/components/combo/combo-form.spec.ts | 3 +- src/components/combo/spec.md | 1 + .../date-picker/date-picker.base.ts | 5 +- src/components/date-picker/spec.md | 1 + src/components/date-range-picker/spec.md | 1 + src/components/date-time-input/spec.md | 1 + src/components/file-input/spec.md | 1 + src/components/input/input.ts | 5 +- src/components/input/spec.md | 1 + src/components/mask-input/spec.md | 1 + src/components/radio/spec.md | 1 + src/components/rating/rating.ts | 9 +- src/components/rating/spec.md | 3 +- src/components/select/spec.md | 1 + src/components/slider/spec.md | 1 + src/components/textarea/spec.md | 1 + src/components/textarea/textarea.ts | 7 +- src/internals/mixins/form-read-only.spec.ts | 109 +++++++++++++ src/internals/mixins/form-submission.spec.ts | 145 +++++++++++++++--- src/internals/mixins/forms/associated.ts | 54 ++++++- src/internals/mixins/forms/types.ts | 2 + src/internals/mixins/mask-behavior.ts | 7 +- src/internals/testing/helpers.spec.ts | 17 ++ 44 files changed, 382 insertions(+), 56 deletions(-) create mode 100644 src/internals/mixins/form-read-only.spec.ts diff --git a/.agents/skills/add-component-property/SKILL.md b/.agents/skills/add-component-property/SKILL.md index e0d516411..9f6319651 100644 --- a/.agents/skills/add-component-property/SKILL.md +++ b/.agents/skills/add-component-property/SKILL.md @@ -64,6 +64,8 @@ public items: Array = []; - Objects and arrays get `attribute: false` and are never reflected. - Spell out the attribute for multi-word properties and HTML look-alikes (`readOnly` → `readonly`). +- A property that writes its own attribute, without `reflect: true`, gets `@reflect` after + `@attr`. Then the manifest shows it as reflected. - A read-only value is a getter, not a `readonly @property`. ### 2. Write the description @@ -106,6 +108,11 @@ In a form-associated control, a property that is part of constraint validation ( `_revalidate` config (`onChange: ({ host }) => host._validate()`) as `src/components/input/input.ts` does. +The browser reads the `readonly` attribute of a form-associated control at once: a control +with it is not validated. Declare `readOnly` with +`@property({ type: Boolean, attribute: 'readonly' })` and `@coercedProperty(reflectReadOnly)` +from `#internals/mixins/forms/associated.js`, not with `reflect: true`, and add `@reflect`. + ### 4. Add tests Test the default value and a programmatic change after `elementUpdated()`. Test the attribute diff --git a/.github/CODING_GUIDELINES.md b/.github/CODING_GUIDELINES.md index 58082ee80..5ab496049 100644 --- a/.github/CODING_GUIDELINES.md +++ b/.github/CODING_GUIDELINES.md @@ -201,7 +201,8 @@ declare global { - Override `requestUpdate()` only when a reaction cannot wait for the next update, also for a property of a base class. Lit calls it from the setter with the name and the old value. Call `super.requestUpdate()` first, and compare the value with the old value. The form - mixin submits the form value again there, and the radio moves to the group of a new `name`. + mixin writes the `name` attribute there and submits the form value again. The radio + moves to the group of a new `name`. - Export a new component from `src/index.ts`, in alphabetical order: ```ts @@ -730,8 +731,9 @@ A parser, converter or serializer that takes user or stored input also gets prop Keep the field initializer. It gives the default value, and `onChange` does not run for it. Use hand-written accessors only for a computed getter or for storage outside the instance. - To share a config between properties, put it in a static field, as - `IgcInputComponent._revalidate` does. + To share a config between the properties of one class, put it in a static field, as + `IgcInputComponent._revalidate` does. To share a config between classes, export it from + a module, as `reflectReadOnly` in `#internals/mixins/forms/associated.js` does. ## Custom Events @@ -1042,6 +1044,9 @@ edits. */ ``` +- Some properties write their own attribute and do not use the `reflect` option of + `@property`. Put `@reflect` after `@attr` on them, so the manifest shows them as reflected. + Examples are `name`, `disabled` and `readOnly` of the form controls. - A deprecated member uses this format: ``@deprecated since [SemVer]. Use the `[new API]` [type] instead.`` diff --git a/CHANGELOG.md b/CHANGELOG.md index 9480897c9..c2a49563e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,6 +98,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - A year spin stops at year 9999 and at year 1, and a year outside them, such as one set from code, only moves toward them. Before, a spin past year 9999 gave a five digit year that did not fit the input. - A `prompt` that is also a separator of the input format no longer makes a typed date incomplete. Examples are `-` with `yyyy-MM-dd`, and `-` with the ` - ` of the date range picker. Before, the `igcInput` detail of a complete date was `null`, and an arrow key or a spin started again from today. - Ctrl + Arrow Left and Ctrl + Arrow Right stop at each date part in an input format without separators, such as `yyyyMMdd`, and do not stop inside a separator of more than one character, such as `, `. Before, the date time input went to the start or the end of the input, and the single input of the date range picker skipped a part. +- #### Date picker, Date range picker, Date time input, Input, Mask input, Rating, Textarea + - A change of `readOnly` updates the `readonly` attribute at once, as for a native control, so constraint validation follows it at once. Before, the attribute changed in the next render. Until then, a required empty control that became read-only still blocked a form submission. - #### Date picker, Date time input - `stepUp(DatePart.AmPm)` and `stepDown(DatePart.AmPm)` read AM or PM from the value. Before, while the input did not have focus and the display format was different from the input format, they read the display text, so they did nothing or switched only from PM to AM. - #### Date range picker @@ -111,6 +113,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - The selected files are submitted under the current `name`. Before, a change of `name` kept them under the old name, and a `name` set after the selection submitted no files. - #### Form controls - A change of the `value` or `checked` attribute keeps the control pristine, so a later `defaultValue` or `defaultChecked` still sets the value, as for a native control. + - A change of `name` updates the `name` attribute at once, as for a native control, so the form data takes the new name. Before, a control that submits a string kept the old name until the next render. Such controls include the input, the select and a single selection combo. A `null` or `undefined` name also removes the attribute at once. - #### Input, Textarea - `stepUp()`, `stepDown()` and `setRangeText()` no longer clear the value when you call them before the first render. - #### Mask input diff --git a/api-reference/igc-checkbox.md b/api-reference/igc-checkbox.md index f2f61c413..45eca52f5 100644 --- a/api-reference/igc-checkbox.md +++ b/api-reference/igc-checkbox.md @@ -22,7 +22,7 @@ defineComponents(IgcCheckboxComponent); The `checked` attribute also sets it. - `name`: `string`. Attribute: `name`, reflected. The name of the control, submitted with the form data. -- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`. +- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`, reflected. Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. - `invalid`: `boolean`. Default: `false`. Attribute: `invalid`. diff --git a/api-reference/igc-color-picker.md b/api-reference/igc-color-picker.md index b31efe06c..1eea9b9a0 100644 --- a/api-reference/igc-color-picker.md +++ b/api-reference/igc-color-picker.md @@ -64,7 +64,7 @@ defineComponents(IgcColorPickerComponent); new default also sets the value. The `value` attribute also sets it. - `name`: `string`. Attribute: `name`, reflected. The name of the control, submitted with the form data. -- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`. +- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`, reflected. Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. - `invalid`: `boolean`. Default: `false`. Attribute: `invalid`. diff --git a/api-reference/igc-combo.md b/api-reference/igc-combo.md index 1879a09ce..080bc1926 100644 --- a/api-reference/igc-combo.md +++ b/api-reference/igc-combo.md @@ -103,7 +103,7 @@ defineComponents(IgcComboComponent); new default also sets the value. The `value` attribute also sets it. - `name`: `string`. Attribute: `name`, reflected. The name of the control, submitted with the form data. -- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`. +- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`, reflected. Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. - `invalid`: `boolean`. Default: `false`. Attribute: `invalid`. diff --git a/api-reference/igc-date-picker.md b/api-reference/igc-date-picker.md index d98e00506..1001152af 100644 --- a/api-reference/igc-date-picker.md +++ b/api-reference/igc-date-picker.md @@ -43,7 +43,7 @@ defineComponents(IgcDatePickerComponent); new default also sets the value. The `value` attribute also sets it. - `name`: `string`. Attribute: `name`, reflected. The name of the control, submitted with the form data. -- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`. +- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`, reflected. Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. - `invalid`: `boolean`. Default: `false`. Attribute: `invalid`. diff --git a/api-reference/igc-date-range-picker.md b/api-reference/igc-date-range-picker.md index 070b34e09..a91baa9a1 100644 --- a/api-reference/igc-date-range-picker.md +++ b/api-reference/igc-date-range-picker.md @@ -48,7 +48,7 @@ defineComponents(IgcDateRangePickerComponent); new default also sets the value. The `value` attribute also sets it. - `name`: `string`. Attribute: `name`, reflected. The name of the control, submitted with the form data. -- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`. +- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`, reflected. Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. - `invalid`: `boolean`. Default: `false`. Attribute: `invalid`. diff --git a/api-reference/igc-date-time-input.md b/api-reference/igc-date-time-input.md index c3f4cb34f..68a26d6a3 100644 --- a/api-reference/igc-date-time-input.md +++ b/api-reference/igc-date-time-input.md @@ -17,7 +17,7 @@ defineComponents(IgcDateTimeInputComponent); state lives in the masked text and is committed - together with an `igcChange` event - when the edit is committed on blur. Use the `igcInput` event to observe the value as it is being typed. -- `readOnly`: `boolean`. Default: `false`. Attribute: `readOnly`, reflected. +- `readOnly`: `boolean`. Default: `false`. Attribute: `readonly`, reflected. Whether the control is read-only. The user cannot change its value. - `mask`: `string`. Attribute: `mask`. The mask pattern of the component. @@ -37,7 +37,7 @@ defineComponents(IgcDateTimeInputComponent); new default also sets the value. The `value` attribute also sets it. - `name`: `string`. Attribute: `name`, reflected. The name of the control, submitted with the form data. -- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`. +- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`, reflected. Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. - `invalid`: `boolean`. Default: `false`. Attribute: `invalid`. diff --git a/api-reference/igc-file-input.md b/api-reference/igc-file-input.md index bde9be250..8de8f48bd 100644 --- a/api-reference/igc-file-input.md +++ b/api-reference/igc-file-input.md @@ -42,7 +42,7 @@ defineComponents(IgcFileInputComponent); new default also sets the value. The `value` attribute also sets it. - `name`: `string`. Attribute: `name`, reflected. The name of the control, submitted with the form data. -- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`. +- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`, reflected. Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. - `invalid`: `boolean`. Default: `false`. Attribute: `invalid`. diff --git a/api-reference/igc-input.md b/api-reference/igc-input.md index 4223b7e81..2baa0abca 100644 --- a/api-reference/igc-input.md +++ b/api-reference/igc-input.md @@ -15,7 +15,7 @@ defineComponents(IgcInputComponent); The value of the control. - `type`: `'number' | 'text' | 'email' | 'password' | 'search' | 'tel' | 'url'`. Default: `'text'`. Attribute: `type`, reflected. The type of the control. -- `readOnly`: `boolean`. Default: `false`. Attribute: `readOnly`, reflected. +- `readOnly`: `boolean`. Default: `false`. Attribute: `readonly`, reflected. Whether the control is read-only. - `inputMode`: `string`. Attribute: `inputmode`. A hint to the browser for which virtual keyboard layout to display. @@ -55,7 +55,7 @@ defineComponents(IgcInputComponent); new default also sets the value. The `value` attribute also sets it. - `name`: `string`. Attribute: `name`, reflected. The name of the control, submitted with the form data. -- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`. +- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`, reflected. Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. - `invalid`: `boolean`. Default: `false`. Attribute: `invalid`. diff --git a/api-reference/igc-mask-input.md b/api-reference/igc-mask-input.md index 1c8097cbc..797033f82 100644 --- a/api-reference/igc-mask-input.md +++ b/api-reference/igc-mask-input.md @@ -25,7 +25,7 @@ defineComponents(IgcMaskInputComponent); The mask pattern of the control. - `prompt`: `string`. Default: `'_'`. Attribute: `prompt`. The prompt symbol to use for unfilled parts of the mask pattern. -- `readOnly`: `boolean`. Default: `false`. Attribute: `readOnly`, reflected. +- `readOnly`: `boolean`. Default: `false`. Attribute: `readonly`, reflected. Whether the control is read-only. The user cannot change its value. - `selectionStart`: `number`. Read-only. No attribute. The offset of the start of the text selection, in UTF-16 code units. @@ -41,7 +41,7 @@ defineComponents(IgcMaskInputComponent); new default also sets the value. The `value` attribute also sets it. - `name`: `string`. Attribute: `name`, reflected. The name of the control, submitted with the form data. -- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`. +- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`, reflected. Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. - `invalid`: `boolean`. Default: `false`. Attribute: `invalid`. diff --git a/api-reference/igc-radio.md b/api-reference/igc-radio.md index a8d72c53a..7208168e0 100644 --- a/api-reference/igc-radio.md +++ b/api-reference/igc-radio.md @@ -28,7 +28,7 @@ defineComponents(IgcRadioComponent); The `checked` attribute also sets it. - `name`: `string`. Attribute: `name`, reflected. The name of the control, submitted with the form data. -- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`. +- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`, reflected. Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. - `invalid`: `boolean`. Default: `false`. Attribute: `invalid`. diff --git a/api-reference/igc-rating.md b/api-reference/igc-rating.md index 19ef2d934..2ad82398d 100644 --- a/api-reference/igc-rating.md +++ b/api-reference/igc-rating.md @@ -48,7 +48,7 @@ defineComponents(IgcRatingComponent); new default also sets the value. The `value` attribute also sets it. - `name`: `string`. Attribute: `name`, reflected. The name of the control, submitted with the form data. -- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`. +- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`, reflected. Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. - `invalid`: `boolean`. Default: `false`. Attribute: `invalid`. diff --git a/api-reference/igc-select.md b/api-reference/igc-select.md index ee6608c87..8a260aa89 100644 --- a/api-reference/igc-select.md +++ b/api-reference/igc-select.md @@ -39,7 +39,7 @@ defineComponents(IgcSelectComponent); new default also sets the value. The `value` attribute also sets it. - `name`: `string`. Attribute: `name`, reflected. The name of the control, submitted with the form data. -- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`. +- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`, reflected. Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. - `invalid`: `boolean`. Default: `false`. Attribute: `invalid`. diff --git a/api-reference/igc-switch.md b/api-reference/igc-switch.md index d63fcce80..0bb0b7e15 100644 --- a/api-reference/igc-switch.md +++ b/api-reference/igc-switch.md @@ -20,7 +20,7 @@ defineComponents(IgcSwitchComponent); The `checked` attribute also sets it. - `name`: `string`. Attribute: `name`, reflected. The name of the control, submitted with the form data. -- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`. +- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`, reflected. Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. - `invalid`: `boolean`. Default: `false`. Attribute: `invalid`. diff --git a/api-reference/igc-textarea.md b/api-reference/igc-textarea.md index 80f1bfa95..438384c19 100644 --- a/api-reference/igc-textarea.md +++ b/api-reference/igc-textarea.md @@ -67,7 +67,7 @@ defineComponents(IgcTextareaComponent); new default also sets the value. The `value` attribute also sets it. - `name`: `string`. Attribute: `name`, reflected. The name of the control, submitted with the form data. -- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`. +- `disabled`: `boolean`. Default: `false`. Attribute: `disabled`, reflected. Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. - `invalid`: `boolean`. Default: `false`. Attribute: `invalid`. diff --git a/public-api.json b/public-api.json index b1076c174..f731e055e 100644 --- a/public-api.json +++ b/public-api.json @@ -1763,7 +1763,6 @@ "placeholder": "string", "prompt": "string", "readonly": "boolean", - "readOnly": "boolean", "required": "boolean", "spin-loop": "boolean", "value": "Date | null" @@ -2362,7 +2361,6 @@ "pattern": "string | undefined", "placeholder": "string", "readonly": "boolean", - "readOnly": "boolean", "required": "boolean", "step": "number | undefined", "type": "InputType ('email' | 'number' | 'password' | 'search' | 'tel' | 'text' | 'url')", @@ -2577,7 +2575,6 @@ "placeholder": "string", "prompt": "string", "readonly": "boolean", - "readOnly": "boolean", "required": "boolean", "value": "string", "value-mode": "MaskInputValueMode ('raw' | 'withFormatting')" diff --git a/scripts/build-typedoc.mjs b/scripts/build-typedoc.mjs index aa3db4903..ecdb43176 100644 --- a/scripts/build-typedoc.mjs +++ b/scripts/build-typedoc.mjs @@ -122,6 +122,7 @@ async function main() { '@cssproperty', '@cssstate', '@attr', + '@reflect', ], suppressCommentWarningsInDeclarationFiles: true, name: 'Ignite UI for Web Components', diff --git a/src/components/checkbox/spec.md b/src/components/checkbox/spec.md index c5f080755..f4054e7fe 100644 --- a/src/components/checkbox/spec.md +++ b/src/components/checkbox/spec.md @@ -62,6 +62,7 @@ This directory hosts two form-associated components that share the same base imp | 11 | 2026-11-11 | Enter submits only through the first submit button of the form, as for a native checkbox, and not after a canceled `keypress` | | 12 | 2026-11-18 | A change of the `checked` attribute or of `value` keeps the control pristine, as for a native checkbox | | 13 | 2026-11-20 | Only a change by the user animates the checkbox and the switch; a change from code and the first render show at once; no transitions with reduced motion. The Material switch thumb moves with a transition, not with keyframes; while a change shows at once, the transitions that the app sets on parts and slotted elements stop too | +| 14 | 2026-11-25 | `name` updates its attribute at once | ## Overview diff --git a/src/components/color-picker/spec.md b/src/components/color-picker/spec.md index 794dbb0fb..72fd328e1 100644 --- a/src/components/color-picker/spec.md +++ b/src/components/color-picker/spec.md @@ -67,6 +67,7 @@ | 17 | 2026-11-18 | In input mode, the text input shows only the invalid state of the picker, and reports the validity of the picker | | 18 | 2026-11-23 | A disabled picker stays closed; the shared disabled popup suite | | 19 | 2026-11-20 | In input mode, a color that the user picks animates the input; a value from code shows at once | +| 20 | 2026-11-25 | `name` updates its attribute at once | ## Overview diff --git a/src/components/combo/combo-form.spec.ts b/src/components/combo/combo-form.spec.ts index 455ed4356..1d3932932 100644 --- a/src/components/combo/combo-form.spec.ts +++ b/src/components/combo/combo-form.spec.ts @@ -72,8 +72,7 @@ describe('Combo', () => { it('submits the value under a new name (single)', async () => { spec.setProperties({ singleSelect: true }); - // A string value goes under the `name` attribute, which the update reflects. - await spec.rename('renamed', true); + await spec.rename('renamed'); spec.assertSubmitHasValues(['BG01']); }); diff --git a/src/components/combo/spec.md b/src/components/combo/spec.md index 7feec2317..77d6e2b59 100644 --- a/src/components/combo/spec.md +++ b/src/components/combo/spec.md @@ -111,6 +111,7 @@ | 35 | 2026-11-19 | Test scenarios: in single selection, a pick or a clear that the app cancels after the user types shows the kept selection again, and the clear button clears a value that has no record. The selection model keeps `value` in sync; the behavior does not change | | 36 | 2026-11-23 | A disabled combo stays closed; the shared disabled popup suite | | 37 | 2026-11-20 | A selection by the user animates the option checkboxes; a value from code, a new `data`, a reused row and a value that an `igcChange` handler keeps show at once | +| 38 | 2026-11-25 | `name` updates its attribute at once | ## Overview diff --git a/src/components/date-picker/date-picker.base.ts b/src/components/date-picker/date-picker.base.ts index e3ca4bc08..b4997e164 100644 --- a/src/components/date-picker/date-picker.base.ts +++ b/src/components/date-picker/date-picker.base.ts @@ -23,6 +23,7 @@ import { import type { IgcCalendarResourceStrings } from '#internals/i18n/EN/calendar.resources.js'; import type { UnpackCustomEvent } from '#internals/mixins/event-emitter.js'; import { FormAssociatedRequiredMixin } from '#internals/mixins/forms/associated-required.js'; +import { reflectReadOnly } from '#internals/mixins/forms/associated.js'; import type { FormValue } from '#internals/mixins/forms/form-value.js'; import { renderSlottedIcon } from '#internals/templates/slotted-icon.js'; import { asArray, firstOf } from '#internals/utils/arrays.js'; @@ -295,9 +296,11 @@ export abstract class IgcDatePickerBaseComponent< /** * Whether the control is read-only. The user cannot change the value or open the calendar. * @attr readonly + * @reflect * @default false */ - @property({ type: Boolean, reflect: true, attribute: 'readonly' }) + @property({ type: Boolean, attribute: 'readonly' }) + @coercedProperty(reflectReadOnly) public readOnly = false; /** diff --git a/src/components/date-picker/spec.md b/src/components/date-picker/spec.md index d69925cf0..02ae62d3f 100644 --- a/src/components/date-picker/spec.md +++ b/src/components/date-picker/spec.md @@ -87,6 +87,7 @@ | 22 | 2026-11-23 | A disabled picker stays closed; the shared disabled popup suite | | 23 | 2026-11-20 | A date that the user picks animates the input; a value from code, also from an `igcChange` handler, shows at once | | 24 | 2026-11-25 | The calendar selects a complete typed date, keeps the last selection while the date is incomplete or invalid, and clears it for an empty input; the calendar shows the value again when the edit ends; the input and change events of slotted content go on to the application | +| 25 | 2026-11-25 | `name` and `readOnly` update their attributes at once | ## Overview diff --git a/src/components/date-range-picker/spec.md b/src/components/date-range-picker/spec.md index 1592215b6..4d6f03dbb 100644 --- a/src/components/date-range-picker/spec.md +++ b/src/components/date-range-picker/spec.md @@ -89,6 +89,7 @@ | 29 | 2026-11-23 | A disabled picker stays closed and disabling discards a draft; the shared disabled popup suite | | 30 | 2026-11-20 | A range that the user picks animates the inputs; a value from code, also from an `igcChange` handler, shows at once | | 31 | 2026-11-25 | While the user types, an incomplete or invalid end keeps the end that the calendar selects, and a blank end drops out, in both layouts; the calendar shows the value again when the edit ends, and with two inputs a new range from code keeps the edit of an end whose date stays; a complete range parses strictly when the separator holds the prompt | +| 32 | 2026-11-25 | `name` and `readOnly` update their attributes at once | ## Overview diff --git a/src/components/date-time-input/spec.md b/src/components/date-time-input/spec.md index 6f0adc214..c0e29763e 100644 --- a/src/components/date-time-input/spec.md +++ b/src/components/date-time-input/spec.md @@ -77,6 +77,7 @@ | 20 | 2026-11-20 | A year spin stops at year 1 and at year 9999 and does not loop; a year outside them only moves toward them; the value accepts an ISO string with a signed six digit year | | 21 | 2026-11-20 | A value from code and the first render show at once, also the Material label that moves up; no transitions with reduced motion; while a change shows at once, the transitions that the app sets on parts and slotted elements stop too | | 22 | 2026-11-25 | Add the edit parse, which gives a picker calendar the typed date, the previous date while the date is incomplete, or `null` for a blank mask; a strict parse reads the prompt only in the date parts, so a literal can be the prompt | +| 23 | 2026-11-25 | `name` and `readOnly` update their attributes at once | ## Overview diff --git a/src/components/file-input/spec.md b/src/components/file-input/spec.md index 39567dd0e..aaa163990 100644 --- a/src/components/file-input/spec.md +++ b/src/components/file-input/spec.md @@ -60,6 +60,7 @@ | 10 | 2026-11-02 | A `focus()` call before the first render applies after the render | | 11 | 2026-11-19 | The files are submitted under the current `name`, also a `name` set after the selection | | 12 | 2026-11-20 | A value from code and the first render show at once; no transitions with reduced motion | +| 13 | 2026-11-25 | `name` updates its attribute at once | ## Overview diff --git a/src/components/input/input.ts b/src/components/input/input.ts index 8f29a19cc..f24f2a628 100644 --- a/src/components/input/input.ts +++ b/src/components/input/input.ts @@ -9,6 +9,7 @@ import { type CoercedPropertyConfig, } from '#internals/decorators/coerced-property.js'; import { registerComponent } from '#internals/definitions/register.js'; +import { reflectReadOnly } from '#internals/mixins/forms/associated.js'; import { createFormValueState } from '#internals/mixins/forms/form-value.js'; import { partMap } from '#internals/part-map.js'; import { hasNegativeTabIndex } from '#internals/utils/dom.js'; @@ -146,9 +147,11 @@ export default class IgcInputComponent extends IgcInputBaseComponent { * Whether the control is read-only. * * @attr readonly + * @reflect * @default false */ - @property({ type: Boolean, reflect: true }) + @property({ type: Boolean, attribute: 'readonly' }) + @coercedProperty(reflectReadOnly) public readOnly = false; /** diff --git a/src/components/input/spec.md b/src/components/input/spec.md index ed60c59e4..b7eab0851 100644 --- a/src/components/input/spec.md +++ b/src/components/input/spec.md @@ -77,6 +77,7 @@ | 17 | 2026-11-16 | `stepUp`, `stepDown` and `setRangeText` before the first render keep the value | | 18 | 2026-11-18 | A change of the `value` attribute keeps the control pristine, as for a native input | | 19 | 2026-11-20 | A value from code and the first render show at once, also the Material label that moves up; no transitions with reduced motion; while a change shows at once, the transitions that the app sets on parts and slotted elements stop too | +| 20 | 2026-11-25 | `name` and `readOnly` update their attributes at once | ## Overview diff --git a/src/components/mask-input/spec.md b/src/components/mask-input/spec.md index 0b22fda56..6bea208da 100644 --- a/src/components/mask-input/spec.md +++ b/src/components/mask-input/spec.md @@ -65,6 +65,7 @@ | 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 | +| 17 | 2026-11-25 | `name` and `readOnly` update their attributes at once | ## Overview diff --git a/src/components/radio/spec.md b/src/components/radio/spec.md index 176c8c5a2..5340ac24c 100644 --- a/src/components/radio/spec.md +++ b/src/components/radio/spec.md @@ -63,6 +63,7 @@ | 11 | 2026-11-18 | A change of `value` keeps the radio pristine, as for a native radio | | 12 | 2026-11-19 | The group owns its form state: the validity follows a join, a leave and a reset at once, a checked radio that joins clears the group, a removed radio is a group of its own, each radio keeps its default, and `invalid` comes in DOM order | | 13 | 2026-11-20 | Only a change by the user animates the radio, also the radio that a user check unchecks; a change from code and the first render show at once; no transitions with reduced motion; while a change shows at once, the transitions that the app sets on parts and slotted elements stop too | +| 14 | 2026-11-25 | `name` updates its attribute at once | ## Overview diff --git a/src/components/rating/rating.ts b/src/components/rating/rating.ts index c8062581e..476dbbb5a 100644 --- a/src/components/rating/rating.ts +++ b/src/components/rating/rating.ts @@ -26,7 +26,10 @@ import { coercedProperty } from '#internals/decorators/coerced-property.js'; import { cancelDeferredFocus, deferFocus } from '#internals/deferred-focus.js'; import { registerComponent } from '#internals/definitions/register.js'; import { EventEmitterMixin } from '#internals/mixins/event-emitter.js'; -import { FormAssociatedMixin } from '#internals/mixins/forms/associated.js'; +import { + FormAssociatedMixin, + reflectReadOnly, +} from '#internals/mixins/forms/associated.js'; import { FormValueNumberTransformers } from '#internals/mixins/forms/form-transformers.js'; import { createFormValueState } from '#internals/mixins/forms/form-value.js'; import { isLTR, pointToFraction } from '#internals/utils/dom.js'; @@ -258,9 +261,11 @@ export default class IgcRatingComponent extends FormAssociatedMixin( * ignores user input. * * @attr readonly + * @reflect * @default false */ - @property({ type: Boolean, reflect: true, attribute: 'readonly' }) + @property({ type: Boolean, attribute: 'readonly' }) + @coercedProperty(reflectReadOnly) public readOnly = false; /** diff --git a/src/components/rating/spec.md b/src/components/rating/spec.md index b70b3a267..a5d506d90 100644 --- a/src/components/rating/spec.md +++ b/src/components/rating/spec.md @@ -56,6 +56,7 @@ | 7 | 2026-10-21 | API descriptions aligned with the JSDoc. | | 8 | 2026-11-02 | A `focus()` call before the first render applies after the render | | 9 | 2026-11-18 | A value set from code before the first render makes the rating dirty, so a later `defaultValue` does not replace it | +| 10 | 2026-11-25 | `disabled` is marked as reflected. `name` and `readOnly` update their attributes at once | ## Overview @@ -207,7 +208,7 @@ value: `{0}` is replaced with the current value and `{1}` with the maximum. | `allowReset` | `allow-reset` | yes | `boolean` | `false` | Clicking the current value resets it to `0`. | | `readOnly` | `readonly` | yes | `boolean` | `false` | Whether the rating is read-only. A read-only rating shows its value but ignores user input. | | `name` | `name` | yes | `string` | — | The name submitted with the form data. | -| `disabled` | `disabled` | no | `boolean` | `false` | Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. | +| `disabled` | `disabled` | yes | `boolean` | `false` | Whether the control is disabled. A disabled control is not validated, and the form does not submit its value. | | `invalid` | `invalid` | no | `boolean` | `false` | The invalid visual state of the component. | | `defaultValue` | — | — | `number` | — | The value restored on a form reset. | | `form` | — | — | `HTMLFormElement \| null` | — | The associated form. Read-only. | diff --git a/src/components/select/spec.md b/src/components/select/spec.md index 18599bd82..1105deeb5 100644 --- a/src/components/select/spec.md +++ b/src/components/select/spec.md @@ -73,6 +73,7 @@ This directory hosts four public components: [`igc-select`](#igc-select), [`igc- | 12 | 2026-11-18 | Tab keeps an unmatched value; Tab and Escape ignore `defaultPrevented` on the select; the shared popup rules suite | | 13 | 2026-11-23 | A disabled select stays closed; the shared disabled popup suite | | 14 | 2026-11-20 | A selection by the user animates the input; a value that an `igcChange` handler or other code sets shows at once | +| 15 | 2026-11-25 | `name` updates its attribute at once | ## Overview diff --git a/src/components/slider/spec.md b/src/components/slider/spec.md index 0899b32f3..092aeef54 100644 --- a/src/components/slider/spec.md +++ b/src/components/slider/spec.md @@ -60,6 +60,7 @@ | 9 | 2026-10-29 | The base of the slider has no transition, so the slider hides at the same time as a hidden ancestor | | 10 | 2026-11-02 | A `focus()` call before the first render applies after the render | | 11 | 2026-11-18 | A change of the user that fails validation shows the invalid styles at once | +| 12 | 2026-11-25 | `name` updates its attribute at once | ## Overview diff --git a/src/components/textarea/spec.md b/src/components/textarea/spec.md index e99ec39ff..0959c0602 100644 --- a/src/components/textarea/spec.md +++ b/src/components/textarea/spec.md @@ -69,6 +69,7 @@ | 11 | 2026-11-02 | A `focus()` call before the first render applies after the render; `focus()` and `blur()` in the API | | 12 | 2026-11-16 | `setRangeText` before the first render keeps the value | | 13 | 2026-11-20 | A value from code and the first render show at once, also the Material label that moves up; no transitions with reduced motion; while a change shows at once, the transitions that the app sets on parts and slotted elements stop too | +| 14 | 2026-11-25 | `name` and `readOnly` update their attributes at once | ## Overview diff --git a/src/components/textarea/textarea.ts b/src/components/textarea/textarea.ts index 4919ab882..d767089f1 100644 --- a/src/components/textarea/textarea.ts +++ b/src/components/textarea/textarea.ts @@ -18,11 +18,13 @@ import { setSlots, type SlotChangeCallbackParameters, } from '#internals/controllers/slot.js'; +import { coercedProperty } from '#internals/decorators/coerced-property.js'; import { shadowOptions } from '#internals/decorators/shadow-options.js'; import { cancelDeferredFocus, deferFocus } from '#internals/deferred-focus.js'; import { registerComponent } from '#internals/definitions/register.js'; import { EventEmitterMixin } from '#internals/mixins/event-emitter.js'; import { FormAssociatedRequiredMixin } from '#internals/mixins/forms/associated-required.js'; +import { reflectReadOnly } from '#internals/mixins/forms/associated.js'; import { createFormValueState } from '#internals/mixins/forms/form-value.js'; import { renderInputShell, @@ -251,8 +253,11 @@ export default class IgcTextareaComponent extends FormAssociatedRequiredMixin( * Whether the control is read-only. * * @attr readonly + * @reflect + * @default false */ - @property({ type: Boolean, reflect: true, attribute: 'readonly' }) + @property({ type: Boolean, attribute: 'readonly' }) + @coercedProperty(reflectReadOnly) public readOnly = false; /** diff --git a/src/internals/mixins/form-read-only.spec.ts b/src/internals/mixins/form-read-only.spec.ts new file mode 100644 index 000000000..6b613a25f --- /dev/null +++ b/src/internals/mixins/form-read-only.spec.ts @@ -0,0 +1,109 @@ +import { expect, fixture, html, unsafeStatic } from '@open-wc/testing'; +import IgcDatePickerComponent from '../../components/date-picker/date-picker.js'; +import IgcDateRangePickerComponent from '../../components/date-range-picker/date-range-picker.js'; +import IgcDateTimeInputComponent from '../../components/date-time-input/date-time-input.js'; +import IgcInputComponent from '../../components/input/input.js'; +import IgcMaskInputComponent from '../../components/mask-input/mask-input.js'; +import IgcRatingComponent from '../../components/rating/rating.js'; +import IgcTextareaComponent from '../../components/textarea/textarea.js'; +import { defineComponents } from '../definitions/defineComponents.js'; +import { createFormAssociatedTestBed } from '../testing/form-testbed.spec.js'; +import { attributeWrites } from '../testing/helpers.spec.js'; +import type { IgcFormControl } from './forms/types.js'; + +type ReadOnlyControl = IgcFormControl & { readOnly: boolean }; + +const controls = [ + IgcDatePickerComponent, + IgcDateRangePickerComponent, + IgcDateTimeInputComponent, + IgcInputComponent, + IgcMaskInputComponent, + IgcRatingComponent, + IgcTextareaComponent, +]; + +describe('Form control readOnly', () => { + before(() => defineComponents(...controls)); + + for (const { tagName } of controls) { + it(`${tagName}: takes the control out of validation at once`, async () => { + const tag = unsafeStatic(tagName); + const control = await fixture(html`<${tag}>`); + + control.readOnly = true; + expect(control.willValidate).to.be.false; + + control.readOnly = false; + expect(control.willValidate).to.be.true; + }); + } + + describe('attribute', () => { + let input: IgcInputComponent; + + beforeEach(async () => { + input = await fixture(html``); + }); + + it('is written once for a change', () => { + const writes = attributeWrites(input, 'readonly', () => { + input.readOnly = true; + input.readOnly = true; + }); + + expect(writes).to.equal(1); + }); + + it('is absent for undefined', () => { + input.readOnly = undefined as unknown as boolean; + expect(input.hasAttribute('readonly')).to.be.false; + + input.readOnly = true; + input.readOnly = undefined as unknown as boolean; + expect(input.hasAttribute('readonly')).to.be.false; + expect(input.readOnly).to.be.undefined; + }); + + it('sets the property, with no second write', () => { + expect( + attributeWrites(input, 'readonly', () => + input.setAttribute('readonly', '') + ) + ).to.equal(1); + expect(input.readOnly).to.be.true; + + expect( + attributeWrites(input, 'readonly', () => + input.removeAttribute('readonly') + ) + ).to.equal(1); + expect(input.readOnly).to.be.false; + }); + + it('stays through an upgrade', async () => { + const tag = `read-only-upgrade-${crypto.randomUUID()}`; + const parent = await fixture(html`
`); + parent.innerHTML = `<${tag} readonly>`; + + customElements.define(tag, class extends IgcInputComponent {}); + const control = parent.firstElementChild as IgcInputComponent; + + expect(control.readOnly).to.be.true; + expect(control.hasAttribute('readonly')).to.be.true; + }); + }); + + it('lets the form submit a required empty control that becomes read-only', async () => { + const spec = createFormAssociatedTestBed( + html`` + ); + await spec.setup(IgcInputComponent.tagName); + + spec.assertSubmitFails(); + + spec.element.readOnly = true; + + spec.assertSubmitPasses(); + }); +}); diff --git a/src/internals/mixins/form-submission.spec.ts b/src/internals/mixins/form-submission.spec.ts index 740a97475..f1dcae8f6 100644 --- a/src/internals/mixins/form-submission.spec.ts +++ b/src/internals/mixins/form-submission.spec.ts @@ -5,7 +5,8 @@ import { html, unsafeStatic, } from '@open-wc/testing'; -import { LitElement } from 'lit'; +import { LitElement, type PropertyDeclarations } from 'lit'; +import { attributeWrites } from '../testing/helpers.spec.js'; import type { Validator } from '../validators.js'; import { EventEmitterMixin } from './event-emitter.js'; import { FormAssociatedMixin } from './forms/associated.js'; @@ -26,11 +27,33 @@ const modeValidator: Validator = { }, }; -class SubmissionHost extends FormAssociatedMixin( +/** A control whose string value the form submits under the `name` attribute. */ +class ValueHost extends FormAssociatedMixin( EventEmitterMixin<{ igcChange: CustomEvent }>(LitElement) ) { - public static override properties = { + public static override properties: PropertyDeclarations = { value: { type: String }, + }; + + protected override readonly _formValue = createFormValueState(this, { + initialValue: '', + }); + + public set value(value: string) { + this._formValue.setValueAndFormState(value); + } + + public get value(): string { + return this._formValue.value; + } + + protected override render() { + return html``; + } +} + +class SubmissionHost extends ValueHost { + public static override properties: PropertyDeclarations = { mode: { type: String }, label: { type: String }, }; @@ -76,14 +99,6 @@ class SubmissionHost extends FormAssociatedMixin( return [modeValidator]; } - public set value(value: string) { - this._formValue.setValueAndFormState(value); - } - - public get value(): string { - return this._formValue.value; - } - public get pristine(): boolean { return this._isPristine; } @@ -102,10 +117,10 @@ class SubmissionHost extends FormAssociatedMixin( this.submissions++; super._setFormValue(value, state); } +} - protected override render() { - return html``; - } +function submitted(form: HTMLFormElement): [string, FormDataEntryValue][] { + return Array.from(new FormData(form)); } describe('Form submission reads', () => { @@ -117,10 +132,6 @@ describe('Form submission reads', () => { tag = defineCE(class extends SubmissionHost {}); }); - function submitted(): [string, FormDataEntryValue][] { - return Array.from(new FormData(form)); - } - async function createHost(attributes: string): Promise { form = await fixture( html`
@@ -142,10 +153,10 @@ describe('Form submission reads', () => { it('submits again at once when a property that it reads changes', () => { host.name = 'renamed'; - expect(submitted()).to.eql([['renamed', 'a']]); + expect(submitted(form)).to.eql([['renamed', 'a']]); host.mode = 'upper'; - expect(submitted()).to.eql([['renamed', 'A']]); + expect(submitted(form)).to.eql([['renamed', 'A']]); }); it('does not submit again for a property that it does not read', () => { @@ -194,7 +205,7 @@ describe('Form submission reads', () => { it('submits the attributes of an upgrade in any order', async () => { await createHost('value="a" mode="upper" name="field"'); - expect(submitted()).to.eql([['field', 'A']]); + expect(submitted(form)).to.eql([['field', 'A']]); }); it('submits at the first connect what was set before it', () => { @@ -205,7 +216,7 @@ describe('Form submission reads', () => { form.replaceChildren(element); - expect(submitted()).to.eql([['field', 'A']]); + expect(submitted(form)).to.eql([['field', 'A']]); }); it('does not submit again before the first connect', () => { @@ -227,10 +238,98 @@ describe('Form submission reads', () => { expect(host.submissions).to.equal(count + 1); form.append(host); - expect(submitted()).to.eql([['renamed', 'a']]); + expect(submitted(form)).to.eql([['renamed', 'a']]); }); it('runs no validator in the constructor', () => { expect(createElement).not.to.throw(); }); }); + +describe('Form submission name', () => { + let tag: string; + let host: ValueHost; + let form: HTMLFormElement; + + before(() => { + tag = defineCE(class extends ValueHost {}); + }); + + beforeEach(async () => { + form = await fixture( + html` + <${unsafeStatic(tag)} name="field"> + ` + ); + host = form.querySelector(tag)!; + host.value = 'a'; + }); + + it('keys a string submission by a new name at once', () => { + host.name = 'renamed'; + + expect(host.getAttribute('name')).to.equal('renamed'); + expect(submitted(form)).to.eql([['renamed', 'a']]); + }); + + /** Sets `name` from code and returns the number of attribute writes. */ + function setName(value: unknown): number { + return attributeWrites(host, 'name', () => { + host.name = value as string; + }); + } + + it('removes the attribute at once for null and undefined', () => { + for (const empty of [null, undefined]) { + host.name = 'field'; + + expect(setName(empty)).to.equal(1); + expect(host.name).to.equal(empty); + expect(setName(empty)).to.equal(0); + expect(host.hasAttribute('name')).to.be.false; + expect(submitted(form)).to.eql([]); + } + }); + + it('keeps an empty name as an empty attribute', () => { + host.name = ''; + + expect(host.getAttribute('name')).to.equal(''); + expect(submitted(form)).to.eql([]); + }); + + it('writes the attribute only for a different name', () => { + expect(setName('field')).to.equal(0); + expect(setName('renamed')).to.equal(1); + }); + + it('writes a number name once and keeps the number', () => { + expect(setName(5)).to.equal(1); + expect(host.name).to.equal(5); + expect(setName(5)).to.equal(0); + expect(host.getAttribute('name')).to.equal('5'); + }); + + it('follows a change of the attribute', () => { + expect( + attributeWrites(host, 'name', () => host.setAttribute('name', 'renamed')) + ).to.equal(1); + expect(host.name).to.equal('renamed'); + + expect( + attributeWrites(host, 'name', () => host.removeAttribute('name')) + ).to.equal(1); + expect(host.name).to.be.null; + }); + + it('writes the attribute before the first connect', () => { + const element = document.createElement(tag) as ValueHost; + element.name = 'other'; + element.value = 'b'; + + expect(element.getAttribute('name')).to.equal('other'); + + form.replaceChildren(element); + expect(submitted(form)).to.eql([['other', 'b']]); + }); +}); diff --git a/src/internals/mixins/forms/associated.ts b/src/internals/mixins/forms/associated.ts index b56c40018..4f1713e2f 100644 --- a/src/internals/mixins/forms/associated.ts +++ b/src/internals/mixins/forms/associated.ts @@ -7,7 +7,9 @@ import { internalsOf, } from '../../controllers/internals.js'; import { enterKey, isComposingKey, isKey } from '../../controllers/keys.js'; +import type { CoercedPropertyConfig } from '../../decorators/coerced-property.js'; import { getHostLocale } from '../../i18n/i18n-controller.js'; +import { setOrRemoveAttribute } from '../../utils/dom.js'; import { addSafeEventListener, preventDefault, @@ -198,6 +200,39 @@ function submitImplicitly(form: HTMLFormElement, fromTextField: boolean): void { //#endregion +/** The attribute that each control writes for one of its properties now. */ +const ownAttributeWrites = new WeakMap(); + +/** + * Runs `write`, which makes `attribute` of `host` follow a property at once. + * The attribute does not set the property again, so the property keeps the + * value that code set, as with the `reflect` option of a Lit property. + */ +function writeOwnAttribute( + host: Element, + attribute: string, + write: () => void +): void { + ownAttributeWrites.set(host, attribute); + + try { + write(); + } finally { + ownAttributeWrites.delete(host); + } +} + +/** + * Writes the `readonly` attribute at once. The browser does not validate a + * control that has this attribute. + */ +export const reflectReadOnly: CoercedPropertyConfig = { + onChange: ({ host, value: readOnly }) => + writeOwnAttribute(host, 'readonly', () => + host.toggleAttribute('readonly', Boolean(readOnly)) + ), +}; + /** * `stateKey` names the state property, whose attribute sets the default. * `hostAria` lists more host attributes to forward, see `HostAriaMixin`. @@ -278,14 +313,16 @@ function BaseFormAssociated( /** * The name of the control, submitted with the form data. * @attr + * @reflect */ - @property({ reflect: true }) + @property() public name!: string; /** * Whether the control is disabled. A disabled control is not validated, * and the form does not submit its value. * @attr + * @reflect * @default false */ @property({ type: Boolean }) @@ -387,6 +424,17 @@ function BaseFormAssociated( super.requestUpdate(...args); const [name, oldValue] = args; + // The form uses the attribute as the key of a string value. + if (name === 'name' && !Object.is(this.name, oldValue)) { + const attribute = this.name == null ? null : `${this.name}`; + + if (this.getAttribute('name') !== attribute) { + writeOwnAttribute(this, 'name', () => + setOrRemoveAttribute(this, 'name', attribute) + ); + } + } + // Lit calls this from the setter of each reactive property, at once. if ( this.__submitsOnChange && @@ -709,6 +757,10 @@ function BaseFormAssociated( prev: string | null, current: string | null ): void { + if (ownAttributeWrites.get(this) === name) { + return; + } + if (name !== stateKey) { super.attributeChangedCallback(name, prev, current); return; diff --git a/src/internals/mixins/forms/types.ts b/src/internals/mixins/forms/types.ts index 597fe3c36..580d78280 100644 --- a/src/internals/mixins/forms/types.ts +++ b/src/internals/mixins/forms/types.ts @@ -50,6 +50,7 @@ export declare class BaseFormAssociatedElement { * Whether the control is disabled. A disabled control is not validated, and * the form does not submit its value. * @attr + * @reflect * @default false */ public disabled: boolean; @@ -65,6 +66,7 @@ export declare class BaseFormAssociatedElement { /** * The name of the control, submitted with the form data. * @attr + * @reflect */ public name: string; diff --git a/src/internals/mixins/mask-behavior.ts b/src/internals/mixins/mask-behavior.ts index 44b2cbc90..baff9ecd6 100644 --- a/src/internals/mixins/mask-behavior.ts +++ b/src/internals/mixins/mask-behavior.ts @@ -12,6 +12,7 @@ import { metaKey, shiftKey, } from '../controllers/key-bindings.js'; +import { coercedProperty } from '../decorators/coerced-property.js'; import { createMaskHistory, type MaskEditKind, @@ -19,6 +20,7 @@ import { } from '../mask-history.js'; import type { MaskedInputOptions } from '../templates/masked-input.js'; import type { AbstractConstructor } from './constructor.js'; +import { reflectReadOnly } from './forms/associated.js'; import type { BaseFormAssociatedElement } from './forms/types.js'; export type MaskSelection = { @@ -98,6 +100,7 @@ export declare class MaskBehaviorElementInterface { /** * Whether the control is read-only. The user cannot change its value. * @attr readonly + * @reflect * @default false */ public readOnly: boolean; @@ -271,9 +274,11 @@ export function MaskBehaviorMixin< * Whether the control is read-only. The user cannot change its value. * * @attr readonly + * @reflect * @default false */ - @property({ type: Boolean, reflect: true }) + @property({ type: Boolean, attribute: 'readonly' }) + @coercedProperty(reflectReadOnly) public readOnly = false; /** diff --git a/src/internals/testing/helpers.spec.ts b/src/internals/testing/helpers.spec.ts index b7bd0eaa5..1fd7d573a 100644 --- a/src/internals/testing/helpers.spec.ts +++ b/src/internals/testing/helpers.spec.ts @@ -236,6 +236,23 @@ export function catchListenerErrors(fn: () => void): unknown[] { return errors; } +/** Runs `fn` and returns the number of writes of `attribute` on `element`. */ +export function attributeWrites( + element: Element, + attribute: string, + fn: () => void +): number { + const observer = new MutationObserver(() => {}); + observer.observe(element, { attributeFilter: [attribute] }); + + try { + fn(); + return observer.takeRecords().length; + } finally { + observer.disconnect(); + } +} + /** * Axe options for components that publish required ARIA relations through * ARIA element reflection. Reflection blanks the content attribute that axe