diff --git a/CHANGELOG.md b/CHANGELOG.md index c2a49563e..1cef579b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - `open = true` and a first render with `open` show the backdrop at once, as they do the dialog. So do an append of an open dialog and a reopen after a close that the dialog cannot cancel. Before, the backdrop faded in. `show()` still fades both in. - #### Dropdown - Enter closes the open list also when no item is active, as in the select. Before, the list stayed open. +- #### Form controls + - `defaultValue` has the type of the default that the control keeps. Before, its type was `unknown`. The type is `string` for the input, textarea, mask input and color picker, `number` for the rating and slider, `string | undefined` for the select, `ComboValue[]` for the combo, `Date | null` for the date time input and date picker, `DateRangeValue | null` for the date range picker, and `null` for the file input. As for `value`, the date controls also accept a string. In TypeScript, a write of another type is now an error. - #### 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 @@ -109,7 +111,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - In single input mode, the calendar shows the month of the end that you type or spin, as it does with two inputs. Before, it showed only the month of the start. - The `igcInput` and `igcChange` events of content in the prefix and suffix slots of the inputs reach your handlers, and they no longer change the value of the picker. Before, the picker stopped them, and an `igcChange` from that content cleared the value, or its end date with two inputs. - A change of `name` renames the submitted `-start` and `-end` entries at once. Before, the form submitted the range under the old name. +- #### Date time input + - The API reference and the custom elements manifest give `value` the type `Date | null`. Before, they gave `T | null`. The TypeScript type does not change. - #### File input + - A form reset always clears the selection and submits no files, also after code writes `defaultValue`. Before, the form submitted a file list written to `defaultValue` while the control showed no files, and a string one character per entry. - 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. diff --git a/api-reference/igc-color-picker.md b/api-reference/igc-color-picker.md index 1eea9b9a0..1a3413cfa 100644 --- a/api-reference/igc-color-picker.md +++ b/api-reference/igc-color-picker.md @@ -28,6 +28,10 @@ defineComponents(IgcColorPickerComponent); hsl(a) and named colors. An empty, whitespace-only or invalid string clears the value. +- `defaultValue`: `string`. No attribute. + The default value of the control. A form reset restores the value to it. + While the value is unchanged since the start or the last form reset, a + new default also sets the value. The `value` attribute also sets it. - `format`: `'hex' | 'rgb' | 'hsl'`. Default: `'hex'`. Attribute: `format`. The color format of the string value. @@ -58,10 +62,6 @@ defineComponents(IgcColorPickerComponent); - `required`: `boolean`. Default: `false`. Attribute: `required`, reflected. Whether the control is required. A required control that has no value, or is not checked, fails validation. -- `defaultValue`: `unknown`. No attribute. - The default value of the control. A form reset restores the value to it. - While the value is unchanged since the start or the last form reset, a - 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`, reflected. diff --git a/api-reference/igc-combo.md b/api-reference/igc-combo.md index 080bc1926..51785bb20 100644 --- a/api-reference/igc-combo.md +++ b/api-reference/igc-combo.md @@ -80,6 +80,10 @@ defineComponents(IgcComboComponent); - `value`: `ComboValue[]`. Attribute: `value`. The values of the selected items. With a `valueKey`, each value is that field of an item. Without it, each value is the item itself. +- `defaultValue`: `ComboValue[]`. No attribute. + The default value of the control. A form reset restores the value to it. + While the value is unchanged since the start or the last form reset, a + new default also sets the value. The `value` attribute also sets it. - `selection`: `T[]`. Read-only. No attribute. Returns the current selection as an array of objects as provided in the `data` source. - `pendingValue`: `ComboValue[]`. Read-only. No attribute. @@ -97,10 +101,6 @@ defineComponents(IgcComboComponent); - `required`: `boolean`. Default: `false`. Attribute: `required`, reflected. Whether the control is required. A required control that has no value, or is not checked, fails validation. -- `defaultValue`: `unknown`. No attribute. - The default value of the control. A form reset restores the value to it. - While the value is unchanged since the start or the last form reset, a - 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`, reflected. diff --git a/api-reference/igc-date-picker.md b/api-reference/igc-date-picker.md index 1001152af..02f34ef54 100644 --- a/api-reference/igc-date-picker.md +++ b/api-reference/igc-date-picker.md @@ -18,6 +18,10 @@ defineComponents(IgcDatePickerComponent); intermediate state stays in the editor 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. +- `defaultValue`: `Date | null`. No attribute. + The default value of the control. A form reset restores the value to it. + While the value is unchanged since the start or the last form reset, a + new default also sets the value. The `value` attribute also sets it. - `placeholder`: `string`. Attribute: `placeholder`. The placeholder text of the control. - `selectionStart`: `number`. Read-only. No attribute. @@ -37,10 +41,6 @@ defineComponents(IgcDatePickerComponent); - `required`: `boolean`. Default: `false`. Attribute: `required`, reflected. Whether the control is required. A required control that has no value, or is not checked, fails validation. -- `defaultValue`: `unknown`. No attribute. - The default value of the control. A form reset restores the value to it. - While the value is unchanged since the start or the last form reset, a - 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`, reflected. diff --git a/api-reference/igc-date-range-picker.md b/api-reference/igc-date-range-picker.md index a91baa9a1..8e2e8209f 100644 --- a/api-reference/igc-date-range-picker.md +++ b/api-reference/igc-date-range-picker.md @@ -13,6 +13,10 @@ defineComponents(IgcDateRangePickerComponent); - `value`: `DateRangeValue | null`. Attribute: `value`. The value of the picker: a range with a `start` and an `end` date, or `null` when the range is empty. +- `defaultValue`: `DateRangeValue | null`. No attribute. + The default value of the control. A form reset restores the value to it. + While the value is unchanged since the start or the last form reset, a + new default also sets the value. The `value` attribute also sets it. - `visibleMonths`: `number`. Default: `2`. Attribute: `visible-months`. The number of months displayed in the calendar: 1 or 2. - `customRanges`: `CustomDateRange[]`. Default: `[]`. No attribute. @@ -42,10 +46,6 @@ defineComponents(IgcDateRangePickerComponent); - `required`: `boolean`. Default: `false`. Attribute: `required`, reflected. Whether the control is required. A required control that has no value, or is not checked, fails validation. -- `defaultValue`: `unknown`. No attribute. - The default value of the control. A form reset restores the value to it. - While the value is unchanged since the start or the last form reset, a - 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`, reflected. diff --git a/api-reference/igc-date-time-input.md b/api-reference/igc-date-time-input.md index 68a26d6a3..386076ee8 100644 --- a/api-reference/igc-date-time-input.md +++ b/api-reference/igc-date-time-input.md @@ -10,13 +10,17 @@ defineComponents(IgcDateTimeInputComponent); ## Properties -- `value`: `T | null`. Attribute: `value`. +- `value`: `Date | null`. Attribute: `value`. The value of the input. Only ever holds a committed value. While the user is typing, the intermediate 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. +- `defaultValue`: `Date | null`. No attribute. + The default value of the control. A form reset restores the value to it. + While the value is unchanged since the start or the last form reset, a + new default also sets the value. The `value` attribute also sets it. - `readOnly`: `boolean`. Default: `false`. Attribute: `readonly`, reflected. Whether the control is read-only. The user cannot change its value. - `mask`: `string`. Attribute: `mask`. @@ -31,10 +35,6 @@ defineComponents(IgcDateTimeInputComponent); - `required`: `boolean`. Default: `false`. Attribute: `required`, reflected. Whether the control is required. A required control that has no value, or is not checked, fails validation. -- `defaultValue`: `unknown`. No attribute. - The default value of the control. A form reset restores the value to it. - While the value is unchanged since the start or the last form reset, a - 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`, reflected. diff --git a/api-reference/igc-file-input.md b/api-reference/igc-file-input.md index 8de8f48bd..a121a185a 100644 --- a/api-reference/igc-file-input.md +++ b/api-reference/igc-file-input.md @@ -13,6 +13,9 @@ defineComponents(IgcFileInputComponent); - `value`: `string`. Attribute: `value`. The value of the control: the name of the first selected file, as the native file input gives it. As for the native file input, only an empty string can be set. It clears the selection. +- `defaultValue`: `null`. No attribute. + The default value of the control. Always `null`: a file input has no + default selection, so a form reset clears it. - `multiple`: `boolean`. Default: `false`. Attribute: `multiple`, reflected. Whether the control allows the user to select more than one file. - `directory`: `boolean`. Default: `false`. Attribute: `directory`. @@ -36,10 +39,6 @@ defineComponents(IgcFileInputComponent); - `required`: `boolean`. Default: `false`. Attribute: `required`, reflected. Whether the control is required. A required control that has no value, or is not checked, fails validation. -- `defaultValue`: `unknown`. No attribute. - The default value of the control. A form reset restores the value to it. - While the value is unchanged since the start or the last form reset, a - 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`, reflected. diff --git a/api-reference/igc-input.md b/api-reference/igc-input.md index 2baa0abca..b1dcdc042 100644 --- a/api-reference/igc-input.md +++ b/api-reference/igc-input.md @@ -13,6 +13,10 @@ defineComponents(IgcInputComponent); - `value`: `string`. Attribute: `value`. The value of the control. +- `defaultValue`: `string`. No attribute. + The default value of the control. A form reset restores the value to it. + While the value is unchanged since the start or the last form reset, a + new default also sets the value. The `value` attribute also sets it. - `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. @@ -49,10 +53,6 @@ defineComponents(IgcInputComponent); - `required`: `boolean`. Default: `false`. Attribute: `required`, reflected. Whether the control is required. A required control that has no value, or is not checked, fails validation. -- `defaultValue`: `unknown`. No attribute. - The default value of the control. A form reset restores the value to it. - While the value is unchanged since the start or the last form reset, a - 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`, reflected. diff --git a/api-reference/igc-mask-input.md b/api-reference/igc-mask-input.md index 797033f82..89e227f99 100644 --- a/api-reference/igc-mask-input.md +++ b/api-reference/igc-mask-input.md @@ -21,6 +21,10 @@ defineComponents(IgcMaskInputComponent); The value of the control. Its format depends on `valueMode`. An empty value is always an empty string, regardless of the value mode. +- `defaultValue`: `string`. No attribute. + The default value of the control. A form reset restores the value to it. + While the value is unchanged since the start or the last form reset, a + new default also sets the value. The `value` attribute also sets it. - `mask`: `string`. Default: `'CCCCCCCCCC'`. Attribute: `mask`. The mask pattern of the control. - `prompt`: `string`. Default: `'_'`. Attribute: `prompt`. @@ -35,10 +39,6 @@ defineComponents(IgcMaskInputComponent); - `required`: `boolean`. Default: `false`. Attribute: `required`, reflected. Whether the control is required. A required control that has no value, or is not checked, fails validation. -- `defaultValue`: `unknown`. No attribute. - The default value of the control. A form reset restores the value to it. - While the value is unchanged since the start or the last form reset, a - 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`, reflected. diff --git a/api-reference/igc-rating.md b/api-reference/igc-rating.md index 2ad82398d..b6b1bf4ed 100644 --- a/api-reference/igc-rating.md +++ b/api-reference/igc-rating.md @@ -32,6 +32,10 @@ defineComponents(IgcRatingComponent); Use it for screen readers and for localization. - `value`: `number`. Default: `0`. Attribute: `value`. The value of the rating, clamped between 0 and `max`. +- `defaultValue`: `number`. No attribute. + The default value of the control. A form reset restores the value to it. + While the value is unchanged since the start or the last form reset, a + new default also sets the value. The `value` attribute also sets it. - `hoverPreview`: `boolean`. Default: `false`. Attribute: `hover-preview`, reflected. Whether to show a preview of the value when hovering over the symbols. - `readOnly`: `boolean`. Default: `false`. Attribute: `readonly`, reflected. @@ -42,10 +46,6 @@ defineComponents(IgcRatingComponent); to it. It also sets `step` to 1 and rounds the value up. - `allowReset`: `boolean`. Default: `false`. Attribute: `allow-reset`, reflected. Whether to reset the rating when the user selects the same value. -- `defaultValue`: `unknown`. No attribute. - The default value of the control. A form reset restores the value to it. - While the value is unchanged since the start or the last form reset, a - 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`, reflected. diff --git a/api-reference/igc-select.md b/api-reference/igc-select.md index 8a260aa89..0041762d2 100644 --- a/api-reference/igc-select.md +++ b/api-reference/igc-select.md @@ -12,6 +12,10 @@ defineComponents(IgcSelectComponent); - `value`: `string | undefined`. Attribute: `value`. The value of the control. +- `defaultValue`: `string | undefined`. No attribute. + The default value of the control. A form reset restores the value to it. + While the value is unchanged since the start or the last form reset, a + new default also sets the value. The `value` attribute also sets it. - `outlined`: `boolean`. Default: `false`. Attribute: `outlined`, reflected. Whether the control has an outlined appearance. - `autofocus`: `boolean`. Attribute: `autofocus`. @@ -33,10 +37,6 @@ defineComponents(IgcSelectComponent); - `required`: `boolean`. Default: `false`. Attribute: `required`, reflected. Whether the control is required. A required control that has no value, or is not checked, fails validation. -- `defaultValue`: `unknown`. No attribute. - The default value of the control. A form reset restores the value to it. - While the value is unchanged since the start or the last form reset, a - 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`, reflected. diff --git a/api-reference/igc-slider.md b/api-reference/igc-slider.md index f3a61a253..9b606f394 100644 --- a/api-reference/igc-slider.md +++ b/api-reference/igc-slider.md @@ -12,7 +12,7 @@ defineComponents(IgcSliderComponent); - `value`: `number`. Attribute: `value`. The current value of the component. -- `defaultValue`: `unknown`. No attribute. +- `defaultValue`: `number`. No attribute. The default value of the control. A form reset restores the value to it. While the value is unchanged since the start or the last form reset, a new default also sets the value. The `value` attribute also sets it. diff --git a/api-reference/igc-textarea.md b/api-reference/igc-textarea.md index 438384c19..36a7640f7 100644 --- a/api-reference/igc-textarea.md +++ b/api-reference/igc-textarea.md @@ -43,6 +43,10 @@ defineComponents(IgcTextareaComponent); less than 1 shows 2 lines. - `value`: `string`. Attribute: `value`. The value of the component. +- `defaultValue`: `string`. No attribute. + The default value of the control. A form reset restores the value to it. + While the value is unchanged since the start or the last form reset, a + new default also sets the value. The `value` attribute also sets it. - `spellcheck`: `boolean`. Default: `true`. Attribute: `spellcheck`. Whether the browser checks the spelling of the value. As for the native attribute, only the `"false"` attribute value turns the check off. @@ -61,10 +65,6 @@ defineComponents(IgcTextareaComponent); - `required`: `boolean`. Default: `false`. Attribute: `required`, reflected. Whether the control is required. A required control that has no value, or is not checked, fails validation. -- `defaultValue`: `unknown`. No attribute. - The default value of the control. A form reset restores the value to it. - While the value is unchanged since the start or the last form reset, a - 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`, reflected. diff --git a/cem.config.mjs b/cem.config.mjs index a0010ae3e..aadbb187a 100644 --- a/cem.config.mjs +++ b/cem.config.mjs @@ -138,17 +138,27 @@ const IMPORT_QUALIFIER = /import\("[^"]*"\)\./g; /** * The analyzer copies an inherited member as written, so a member typed with a * type parameter (`TGet` of `I18nMixin`) keeps that name, also under an - * override. Resolve it with the checker on each element. + * override. It also gives an override the type of the member that it + * overrides. Resolve both with the checker on each element. * * @example `TGet` -> `Required` on `igc-chip` + * @example `unknown` -> `Date | null` for the `defaultValue` override of `igc-date-picker` */ -function resolveTypeParametersPlugin() { +function resolveMemberTypesPlugin() { let typescript; const classNodes = new Map(); const typeParameterNames = new Set(); + /** Whether the class declares `name` with its own type annotation. */ + const declaresTyped = (node, name) => + node.members.some( + (classMember) => + classMember.name?.getText() === name && + (classMember.type ?? classMember.parameters?.[0]?.type) + ); + return { - name: 'IGC - RESOLVE TYPE PARAMETERS', + name: 'IGC - RESOLVE MEMBER TYPES', analyzePhase({ ts, node, moduleDoc }) { typescript ??= ts; @@ -176,10 +186,11 @@ function resolveTypeParametersPlugin() { const instanceType = checker.getTypeAtLocation(node); for (const [index, member] of (declaration.members ?? []).entries()) { - if ( - !member.inheritedFrom || - !typeParameterNames.has(member.type?.text) - ) { + const shouldResolve = + typeParameterNames.has(member.type?.text) || + (member.kind === 'field' && declaresTyped(node, member.name)); + + if (!(member.inheritedFrom && shouldResolve)) { continue; } @@ -294,6 +305,6 @@ export default { }), pruneExpandedTypesPlugin(), stripUndefinedDefaultsPlugin(), - resolveTypeParametersPlugin(), + resolveMemberTypesPlugin(), ], }; diff --git a/public-api.json b/public-api.json index f731e055e..814ddb0fc 100644 --- a/public-api.json +++ b/public-api.json @@ -1138,7 +1138,7 @@ "value": "string" }, "properties": { - "defaultValue": "unknown", + "defaultValue": "string", "disabled": "boolean", "form": "readonly HTMLFormElement | null", "format": "ColorFormat ('hex' | 'hsl' | 'rgb')", @@ -1250,7 +1250,7 @@ "autofocusList": "boolean", "caseSensitiveIcon": "boolean", "data": "T[]", - "defaultValue": "unknown", + "defaultValue": "ComboValue[]", "disableClear": "boolean", "disabled": "boolean", "disableFiltering": "boolean", @@ -1402,7 +1402,7 @@ }, "properties": { "activeDate": "Date", - "defaultValue": "unknown", + "defaultValue": "Date | null", "disabled": "boolean", "disabledDates": "DateRangeDescriptor[]", "displayFormat": "string", @@ -1586,7 +1586,7 @@ "properties": { "activeDate": "Date", "customRanges": "CustomDateRange[]", - "defaultValue": "unknown", + "defaultValue": "DateRangeValue | null", "disabled": "boolean", "disabledDates": "DateRangeDescriptor[]", "displayFormat": "string", @@ -1768,7 +1768,7 @@ "value": "Date | null" }, "properties": { - "defaultValue": "unknown", + "defaultValue": "Date | null", "disabled": "boolean", "displayFormat": "string", "form": "readonly HTMLFormElement | null", @@ -1793,7 +1793,7 @@ "static tagName": "readonly string", "validationMessage": "readonly string", "validity": "readonly ValidityState", - "value": "T | null", + "value": "Date | null", "willValidate": "readonly boolean" }, "methods": { @@ -2150,7 +2150,7 @@ "properties": { "accept": "string", "autofocus": "boolean", - "defaultValue": "unknown", + "defaultValue": "null", "directory": "boolean", "disabled": "boolean", "files": "readonly FileList", @@ -2370,7 +2370,7 @@ "properties": { "autocomplete": "string", "autofocus": "boolean", - "defaultValue": "unknown", + "defaultValue": "string", "disabled": "boolean", "form": "readonly HTMLFormElement | null", "inputMode": "string", @@ -2580,7 +2580,7 @@ "value-mode": "MaskInputValueMode ('raw' | 'withFormatting')" }, "properties": { - "defaultValue": "unknown", + "defaultValue": "string", "disabled": "boolean", "form": "readonly HTMLFormElement | null", "invalid": "boolean", @@ -3111,7 +3111,7 @@ }, "properties": { "allowReset": "boolean", - "defaultValue": "unknown", + "defaultValue": "number", "disabled": "boolean", "form": "readonly HTMLFormElement | null", "hoverPreview": "boolean", @@ -3223,7 +3223,7 @@ }, "properties": { "autofocus": "boolean", - "defaultValue": "unknown", + "defaultValue": "string | undefined", "disabled": "boolean", "distance": "number", "form": "readonly HTMLFormElement | null", @@ -3392,7 +3392,7 @@ "value-format": "string | undefined" }, "properties": { - "defaultValue": "unknown", + "defaultValue": "number", "disabled": "boolean", "discreteTrack": "boolean", "form": "readonly HTMLFormElement | null", @@ -3819,7 +3819,7 @@ "properties": { "autocapitalize": "string", "autocomplete": "string", - "defaultValue": "unknown", + "defaultValue": "string", "disabled": "boolean", "form": "readonly HTMLFormElement | null", "inputMode": "string", diff --git a/src/components/color-picker/color-picker.ts b/src/components/color-picker/color-picker.ts index 3cf08e16e..bf79d8dab 100644 --- a/src/components/color-picker/color-picker.ts +++ b/src/components/color-picker/color-picker.ts @@ -276,6 +276,20 @@ export default class IgcColorPickerComponent extends I18nMixin( return this._formValue.value; } + /* blazorCSSuppress */ + /** + * The default value of the control. A form reset restores the value to it. + * While the value is unchanged since the start or the last form reset, a + * new default also sets the value. The `value` attribute also sets it. + */ + public override set defaultValue(value: string) { + super.defaultValue = value; + } + + public override get defaultValue(): string { + return this._formValue.defaultValue; + } + /** * The color format of the string value. * diff --git a/src/components/combo/combo.ts b/src/components/combo/combo.ts index 66c357706..ab3164f88 100644 --- a/src/components/combo/combo.ts +++ b/src/components/combo/combo.ts @@ -623,6 +623,20 @@ export default class IgcComboComponent< return this._formValue.value; } + /* blazorCSSuppress */ + /** + * The default value of the control. A form reset restores the value to it. + * While the value is unchanged since the start or the last form reset, a + * new default also sets the value. The `value` attribute also sets it. + */ + public override set defaultValue(value: ComboValue[]) { + super.defaultValue = value; + } + + public override get defaultValue(): ComboValue[] { + return this._formValue.defaultValue; + } + /** * Returns the current selection as an array of objects as provided in the `data` source. */ diff --git a/src/components/date-picker/date-picker.ts b/src/components/date-picker/date-picker.ts index 7ab9011a3..dda6e149c 100644 --- a/src/components/date-picker/date-picker.ts +++ b/src/components/date-picker/date-picker.ts @@ -269,6 +269,20 @@ export default class IgcDatePickerComponent extends I18nMixin( return this._formValue.value; } + /* blazorCSSuppress */ + /** + * The default value of the control. A form reset restores the value to it. + * While the value is unchanged since the start or the last form reset, a + * new default also sets the value. The `value` attribute also sets it. + */ + public override set defaultValue(value: Date | string | null | undefined) { + super.defaultValue = value; + } + + public override get defaultValue(): Date | null { + return this._formValue.defaultValue; + } + /** * The placeholder text of the control. * @attr diff --git a/src/components/date-range-picker/date-range-picker.ts b/src/components/date-range-picker/date-range-picker.ts index 994a2e461..b588f002f 100644 --- a/src/components/date-range-picker/date-range-picker.ts +++ b/src/components/date-range-picker/date-range-picker.ts @@ -339,6 +339,22 @@ export default class IgcDateRangePickerComponent extends I18nMixin( return this._formValue.value; } + /* blazorCSSuppress */ + /** + * The default value of the control. A form reset restores the value to it. + * While the value is unchanged since the start or the last form reset, a + * new default also sets the value. The `value` attribute also sets it. + */ + public override set defaultValue( + value: DateRangeValue | string | null | undefined + ) { + super.defaultValue = value; + } + + public override get defaultValue(): DateRangeValue | null { + return this._formValue.defaultValue; + } + /** * The number of months displayed in the calendar: 1 or 2. * @attr visible-months diff --git a/src/components/date-time-input/date-time-input.ts b/src/components/date-time-input/date-time-input.ts index dce28aa53..5b66f0e1c 100644 --- a/src/components/date-time-input/date-time-input.ts +++ b/src/components/date-time-input/date-time-input.ts @@ -112,6 +112,20 @@ export default class IgcDateTimeInputComponent extends EventEmitterMixin< return this._formValue.value; } + /* blazorCSSuppress */ + /** + * The default value of the control. A form reset restores the value to it. + * While the value is unchanged since the start or the last form reset, a + * new default also sets the value. The `value` attribute also sets it. + */ + public override set defaultValue(value: Date | string | null | undefined) { + super.defaultValue = value; + } + + public override get defaultValue(): Date | null { + return this._formValue.defaultValue; + } + //#endregion //#region Internal API diff --git a/src/components/file-input/file-input.spec.ts b/src/components/file-input/file-input.spec.ts index 6571f9ca2..b38a8e98b 100644 --- a/src/components/file-input/file-input.spec.ts +++ b/src/components/file-input/file-input.spec.ts @@ -13,7 +13,10 @@ import { createFormAssociatedTestBed, runExternalLabelAssociationTests, } from '#internals/testing/form-testbed.spec.js'; -import { simulateFileUpload } from '#internals/testing/simulate.spec.js'; +import { + createDataTransfer, + simulateFileUpload, +} from '#internals/testing/simulate.spec.js'; import { runValidationContainerTests, type ValidationContainerTestsParams, @@ -389,6 +392,42 @@ describe('Form Integration', () => { spec.assertSubmitPasses(); }); + + describe('defaultValue from code', () => { + /** An untyped write, as from JavaScript. */ + function setDefaultValue(value: unknown): void { + (spec.element as { defaultValue: unknown }).defaultValue = value; + } + + it('keeps no default file list', async () => { + setDefaultValue(createDataTransfer(files).files); + await elementUpdated(spec.element); + + // A failed assertion on a FileList stalls the test runner. + expect(spec.element.defaultValue === null).to.be.true; + + simulateFileUpload(input, files); + await elementUpdated(spec.element); + spec.reset(); + await elementUpdated(spec.element); + + expect(spec.element.value).to.be.empty; + expect(spec.formData.getAll(spec.element.name)).to.eql([]); + }); + + it('keeps no default string', async () => { + // Regression: a reset submitted the string per character. + setDefaultValue('abc'); + await elementUpdated(spec.element); + + expect(spec.element.defaultValue).to.be.null; + + spec.reset(); + await elementUpdated(spec.element); + + expect(spec.formData.getAll(spec.element.name)).to.eql([]); + }); + }); }); describe('Validation message slots', () => { diff --git a/src/components/file-input/file-input.ts b/src/components/file-input/file-input.ts index 9ad521b67..7b574228b 100644 --- a/src/components/file-input/file-input.ts +++ b/src/components/file-input/file-input.ts @@ -172,6 +172,20 @@ export default class IgcFileInputComponent extends I18nMixin( return this._input?.value ?? ''; } + /* blazorCSSuppress */ + /** + * The default value of the control. Always `null`: a file input has no + * default selection, so a form reset clears it. + */ + public override set defaultValue(value: null) { + super.defaultValue = value; + } + + public override get defaultValue(): null { + // The transformer keeps no default. + return this._formValue.defaultValue as null; + } + /** * Whether the control allows the user to select more than one file. * @@ -215,14 +229,6 @@ export default class IgcFileInputComponent extends I18nMixin( //#region Internal methods - /** - * A file input has no default file list, so the `value` attribute gives no default. - * Otherwise a reset submits its string one character at a time. - */ - protected override _setDefaultValue(): void { - this._formValue.defaultValue = null; - } - /** Restores directly, because the read-only `value` setter never updates the form state. */ protected override _restoreDefaultValue(): void { if (this._input) { diff --git a/src/components/file-input/spec.md b/src/components/file-input/spec.md index aaa163990..626d35e41 100644 --- a/src/components/file-input/spec.md +++ b/src/components/file-input/spec.md @@ -61,6 +61,7 @@ | 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 | +| 14 | 2026-11-25 | `defaultValue` is always `null`; a file list or a string written to it no longer survives a form reset | ## Overview @@ -266,8 +267,8 @@ The component applies the `required` validator, and supports custom errors throu ``` - The selected `FileList` is submitted under `name`. -- A file input has no default selection, so a form reset always clears it. The `value` attribute never contributes a - default value. +- A file input has no default selection, so a form reset always clears it. The `value` attribute and a `defaultValue` + write never set a default, so `defaultValue` is always `null`. - A disabled control does not submit a value. As for a native control, a failed submit or `form.reportValidity()` moves the focus to the first invalid control of @@ -306,6 +307,7 @@ The browse button is excluded from the tab order, so the control is a single tab | Property | Attribute | Reflected | Type | Default | Description | | ----------------- | ------------ | --------- | --------------------------- | ------- | ------------------------------------------------------------------------------------ | | value | value | No | `string` | `''` | The value of the control: the name of the first selected file, as the native file input gives it. As for the native file input, only an empty string can be set. It clears the selection. | +| defaultValue | - | No | `null` | `null` | The default value of the control. Always `null`: a file input has no default selection, so a form reset clears it. | | files | - | No | `FileList` | - | Read-only. The list of selected files. | | multiple | multiple | Yes | `boolean` | false | Whether the control allows the user to select more than one file. | | accept | accept | No | `string` | `''` | The file types the control accepts, as a comma-separated list. | @@ -441,27 +443,33 @@ Driven by `createFormAssociatedTestBed`. 21. Reflects the disabled state of an ancestor `fieldset`. 22. Fulfils the required constraint. +#### defaultValue from code + +23. A file list written to `defaultValue` is not kept: `defaultValue` stays `null`, and a reset after a selection + clears the control and submits no files. +24. A string written to `defaultValue` is not kept: a reset submits no entries. + ### Validation message slots Generated by `runValidationContainerTests`. -23. `value-missing` with `required`. -24. `custom-error` after `setCustomValidity`. +25. `value-missing` with `required`. +26. `custom-error` after `setCustomValidity`. ### External label association Generated by `runExternalLabelAssociationTests`. -25. An external `label` bound through `for`, and a `label` wrapping the host, are projected onto the native input as +27. 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). ### Host ARIA -26. The shared host description suite: the host `aria-describedby` describes the native control after the helper +28. The shared host description suite: the host `aria-describedby` describes the native control after the helper text, and follows a change and a removal. -27. The shared focus suite (`runFocusBeforeRenderTests`): a `focus()` call right after the element connects focuses +29. 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 diff --git a/src/components/input/input.ts b/src/components/input/input.ts index f24f2a628..edb529c18 100644 --- a/src/components/input/input.ts +++ b/src/components/input/input.ts @@ -135,6 +135,20 @@ export default class IgcInputComponent extends IgcInputBaseComponent { return this._formValue.value; } + /* blazorCSSuppress */ + /** + * The default value of the control. A form reset restores the value to it. + * While the value is unchanged since the start or the last form reset, a + * new default also sets the value. The `value` attribute also sets it. + */ + public override set defaultValue(value: string) { + super.defaultValue = value; + } + + public override get defaultValue(): string { + return this._formValue.defaultValue; + } + /* alternateName: displayType */ /** * The type of the control. diff --git a/src/components/mask-input/mask-input.ts b/src/components/mask-input/mask-input.ts index 6cbde5c46..48b88366e 100644 --- a/src/components/mask-input/mask-input.ts +++ b/src/components/mask-input/mask-input.ts @@ -156,6 +156,20 @@ export default class IgcMaskInputComponent extends MaskBehaviorMixin( return value ? this._maskedValue : value; } + /* blazorCSSuppress */ + /** + * The default value of the control. A form reset restores the value to it. + * While the value is unchanged since the start or the last form reset, a + * new default also sets the value. The `value` attribute also sets it. + */ + public override set defaultValue(value: string) { + super.defaultValue = value; + } + + public override get defaultValue(): string { + return this._formValue.defaultValue; + } + /** * The mask pattern of the control. * diff --git a/src/components/rating/rating.ts b/src/components/rating/rating.ts index 476dbbb5a..c92dee8d8 100644 --- a/src/components/rating/rating.ts +++ b/src/components/rating/rating.ts @@ -247,6 +247,20 @@ export default class IgcRatingComponent extends FormAssociatedMixin( return this._formValue.value; } + /* blazorCSSuppress */ + /** + * The default value of the control. A form reset restores the value to it. + * While the value is unchanged since the start or the last form reset, a + * new default also sets the value. The `value` attribute also sets it. + */ + public override set defaultValue(value: number) { + super.defaultValue = value; + } + + public override get defaultValue(): number { + return this._formValue.defaultValue; + } + /** * Whether to show a preview of the value when hovering over the symbols. * diff --git a/src/components/rating/spec.md b/src/components/rating/spec.md index a5d506d90..36bc7c8ab 100644 --- a/src/components/rating/spec.md +++ b/src/components/rating/spec.md @@ -57,6 +57,7 @@ | 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 | +| 11 | 2026-11-25 | The `defaultValue` row has the JSDoc wording | ## Overview @@ -210,7 +211,7 @@ value: `{0}` is replaced with the current value and `{1}` with the maximum. | `name` | `name` | yes | `string` | — | The name submitted with the form data. | | `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. | +| `defaultValue` | — | — | `number` | — | The default value of the control. A form reset restores the value to it. While the value is unchanged since the start or the last form reset, a new default also sets the value. The `value` attribute also sets it. | | `form` | — | — | `HTMLFormElement \| null` | — | The associated form. Read-only. | | `validity` | — | — | `ValidityState` | — | The validity state of the control. Read-only. | | `validationMessage` | — | — | `string` | — | The validation message of the control. Read-only. | diff --git a/src/components/select/select.ts b/src/components/select/select.ts index 064ecf512..b1bbcf615 100644 --- a/src/components/select/select.ts +++ b/src/components/select/select.ts @@ -209,6 +209,20 @@ export default class IgcSelectComponent extends FormAssociatedRequiredMixin( return this._formValue.value; } + /* blazorCSSuppress */ + /** + * The default value of the control. A form reset restores the value to it. + * While the value is unchanged since the start or the last form reset, a + * new default also sets the value. The `value` attribute also sets it. + */ + public override set defaultValue(value: string | undefined) { + super.defaultValue = value; + } + + public override get defaultValue(): string | undefined { + return this._formValue.defaultValue; + } + /** * Whether the control has an outlined appearance. * @attr diff --git a/src/components/select/spec.md b/src/components/select/spec.md index 1105deeb5..2e62ea5fb 100644 --- a/src/components/select/spec.md +++ b/src/components/select/spec.md @@ -74,6 +74,7 @@ This directory hosts four public components: [`igc-select`](#igc-select), [`igc- | 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 | +| 16 | 2026-11-25 | `defaultValue` has the type of `value`, `string \| undefined` | ## Overview @@ -326,7 +327,7 @@ code already called `preventDefault()` on the key. | items | - | No | `IgcSelectItemComponent[]` | - | Read-only. The items of the select component. | | groups | - | No | `IgcSelectGroupComponent[]` | - | Read-only. The groups of the select component. | | selectedItem | - | No | `IgcSelectItemComponent \| null` | `null` | Read-only. The selected item, or `null`. | -| defaultValue | - | No | `string` | - | The default value of the control. A form reset restores the value to it. While the value is unchanged since the start or the last form reset, a new default also sets the value. The `value` attribute also sets it. | +| defaultValue | - | No | `string \| undefined` | - | The default value of the control. A form reset restores the value to it. While the value is unchanged since the start or the last form reset, a new default also sets the value. The `value` attribute also sets it. | | form | - | No | `HTMLFormElement \| null` | - | Read-only. The form that the control is associated with, or `null`. | | validity | - | No | `ValidityState` | - | Read-only. The validity state of the control. | | validationMessage | - | No | `string` | - | Read-only. The validation message of the control. It is empty when the control is valid. | diff --git a/src/components/slider/slider.ts b/src/components/slider/slider.ts index e9dc6b5da..fdd679e77 100644 --- a/src/components/slider/slider.ts +++ b/src/components/slider/slider.ts @@ -86,6 +86,20 @@ export default class IgcSliderComponent extends FormAssociatedMixin( return this._formValue.value; } + /* blazorCSSuppress */ + /** + * The default value of the control. A form reset restores the value to it. + * While the value is unchanged since the start or the last form reset, a + * new default also sets the value. The `value` attribute also sets it. + */ + public override set defaultValue(value: number) { + super.defaultValue = value; + } + + public override get defaultValue(): number { + return this._formValue.defaultValue; + } + protected override get _activeValue(): number { return this.value; } diff --git a/src/components/slider/spec.md b/src/components/slider/spec.md index 092aeef54..875b00dc5 100644 --- a/src/components/slider/spec.md +++ b/src/components/slider/spec.md @@ -61,6 +61,7 @@ | 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 | +| 13 | 2026-11-25 | The `defaultValue` row has the JSDoc wording | ## Overview @@ -273,7 +274,7 @@ Shared by `igc-slider` and `igc-range-slider`: | `value` | `value` | no | `number` | `0` | The value of the component. | | `name` | `name` | yes | `string` | — | The name submitted with the form data. | | `invalid` | `invalid` | no | `boolean` | `false` | The invalid visual state of the component. | -| `defaultValue` | — | — | `number` | — | The value restored on a form reset. | +| `defaultValue` | — | — | `number` | — | The default value of the control. A form reset restores the value to it. While the value is unchanged since the start or the last form reset, a new default also sets the value. The `value` attribute also sets it. | It also exposes the `form`, `validity`, `validationMessage` and `willValidate` members of a form-associated element. diff --git a/src/components/textarea/textarea.ts b/src/components/textarea/textarea.ts index d767089f1..026a2efb3 100644 --- a/src/components/textarea/textarea.ts +++ b/src/components/textarea/textarea.ts @@ -293,6 +293,20 @@ export default class IgcTextareaComponent extends FormAssociatedRequiredMixin( return this._formValue.value; } + /* blazorCSSuppress */ + /** + * The default value of the control. A form reset restores the value to it. + * While the value is unchanged since the start or the last form reset, a + * new default also sets the value. The `value` attribute also sets it. + */ + public override set defaultValue(value: string) { + super.defaultValue = value; + } + + public override get defaultValue(): string { + return this._formValue.defaultValue; + } + /** * Whether the browser checks the spelling of the value. As for the native attribute, * only the `"false"` attribute value turns the check off. diff --git a/src/internals/mixins/forms/form-transformers.ts b/src/internals/mixins/forms/form-transformers.ts index 3833ce5d0..71ed5c80d 100644 --- a/src/internals/mixins/forms/form-transformers.ts +++ b/src/internals/mixins/forms/form-transformers.ts @@ -94,7 +94,8 @@ export const FormValueFileListTransformers: FormValueTransformers value || null, getValue: (value) => value, - setDefaultValue: (value) => value || null, + // No default selection: a form reset always clears the files. + setDefaultValue: () => null, getDefaultValue: (value) => value, setFormValue: (files, host) => { if (!(host.name && files)) { diff --git a/stories/date-time-input.stories.ts b/stories/date-time-input.stories.ts index 5b86f18c9..1f22bc350 100644 --- a/stories/date-time-input.stories.ts +++ b/stories/date-time-input.stories.ts @@ -43,6 +43,12 @@ const metadata: Meta = { actions: { handles: ['igcInput', 'igcChange'] }, }, argTypes: { + value: { + type: 'date', + description: + 'The value of the input.\n\nOnly ever holds a committed value. While the user is typing, the intermediate\nstate lives in the masked text and is committed - together with an `igcChange`\nevent - when the edit is committed on blur. Use the `igcInput` event to observe\nthe value as it is being typed.', + control: 'date', + }, readOnly: { type: 'boolean', description: @@ -154,6 +160,15 @@ const metadata: Meta = { export default metadata; interface IgcDateTimeInputArgs { + /** + * The value of the input. + * + * Only ever holds a committed value. While the user is typing, the intermediate + * 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. + */ + value: Date; /** Whether the control is read-only. The user cannot change its value. */ readOnly: boolean; /** The mask pattern of the component. */ @@ -213,12 +228,6 @@ type Story = StoryObj; // endregion -/** - * `value` comes from a generic base component, and the analyzer records its type as - * the bare type parameter `T`, so it is left out of the generated args. - */ -type DateTimeInputStory = StoryObj; - const MINUTE = 60 * 1000; function addMinutes(date: Date, minutes: number): Date { @@ -300,7 +309,7 @@ const styles = html` `; -export const Default: DateTimeInputStory = { +export const Default: Story = { parameters: { docs: { description: {