@govtechsg/sgds-web-component 3.30.1-rc.6 → 3.30.1-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/components/Checkbox/index.umd.min.js +2 -2
  2. package/components/Checkbox/index.umd.min.js.map +1 -1
  3. package/components/Checkbox/sgds-checkbox.d.ts +7 -1
  4. package/components/Checkbox/sgds-checkbox.js +14 -0
  5. package/components/Checkbox/sgds-checkbox.js.map +1 -1
  6. package/components/ComboBox/index.umd.min.js +266 -266
  7. package/components/ComboBox/index.umd.min.js.map +1 -1
  8. package/components/DataTable/index.umd.min.js +301 -301
  9. package/components/DataTable/index.umd.min.js.map +1 -1
  10. package/components/Datepicker/index.umd.min.js +1 -1
  11. package/components/Datepicker/index.umd.min.js.map +1 -1
  12. package/components/FileUpload/index.umd.min.js +1 -1
  13. package/components/FileUpload/index.umd.min.js.map +1 -1
  14. package/components/Input/index.umd.min.js +1 -1
  15. package/components/Input/index.umd.min.js.map +1 -1
  16. package/components/QuantityToggle/index.umd.min.js +1 -1
  17. package/components/QuantityToggle/index.umd.min.js.map +1 -1
  18. package/components/Radio/index.umd.min.js +1 -1
  19. package/components/Radio/index.umd.min.js.map +1 -1
  20. package/components/Select/index.umd.min.js +1 -1
  21. package/components/Select/index.umd.min.js.map +1 -1
  22. package/components/Textarea/index.umd.min.js +1 -1
  23. package/components/Textarea/index.umd.min.js.map +1 -1
  24. package/components/index.umd.min.js +2 -2
  25. package/components/index.umd.min.js.map +1 -1
  26. package/custom-elements.json +10 -3
  27. package/index.umd.min.js +722 -722
  28. package/index.umd.min.js.map +1 -1
  29. package/package.json +1 -1
  30. package/react/components/Checkbox/sgds-checkbox.cjs.js +14 -0
  31. package/react/components/Checkbox/sgds-checkbox.cjs.js.map +1 -1
  32. package/react/components/Checkbox/sgds-checkbox.js +14 -0
  33. package/react/components/Checkbox/sgds-checkbox.js.map +1 -1
  34. package/react/utils/validatorMixin.cjs.js +2 -3
  35. package/react/utils/validatorMixin.cjs.js.map +1 -1
  36. package/react/utils/validatorMixin.js +2 -3
  37. package/react/utils/validatorMixin.js.map +1 -1
  38. package/types/react.d.ts +1 -1
  39. package/utils/validatorMixin.d.ts +1 -1
  40. package/utils/validatorMixin.js +2 -3
  41. package/utils/validatorMixin.js.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@govtechsg/sgds-web-component",
3
- "version": "3.30.1-rc.6",
3
+ "version": "3.30.1-rc.7",
4
4
  "description": "",
5
5
  "main": "./index.umd.js",
6
6
  "module": "./index.js",
@@ -93,6 +93,18 @@ var SgdsCheckbox = class extends require_validatorMixin.SgdsFormValidatorMixin(r
93
93
  e.preventDefault();
94
94
  this.invalid = true;
95
95
  }
96
+ /** Override mixin to match native checkbox: send value only when checked, default to "on". */
97
+ _mixinSetFormValue() {
98
+ super._mixinSetFormValue(this.checked ? this.value ?? "on" : null);
99
+ }
100
+ /** @internal */
101
+ _handleCheckedChange() {
102
+ this._mixinSetFormValue();
103
+ }
104
+ /** @internal */
105
+ _handleValueChange() {
106
+ this._mixinSetFormValue();
107
+ }
96
108
  /** @internal */
97
109
  _handleDisabledChange() {
98
110
  this.setInvalid(false);
@@ -219,6 +231,8 @@ require_decorate.default([(0, lit_decorators_js.property)({
219
231
  reflect: true
220
232
  })], SgdsCheckbox.prototype, "invalidFeedback", void 0);
221
233
  require_decorate.default([(0, lit_decorators_js.state)()], SgdsCheckbox.prototype, "_isTouched", void 0);
234
+ require_decorate.default([require_watch.watch("checked", { waitUntilFirstUpdate: true })], SgdsCheckbox.prototype, "_handleCheckedChange", null);
235
+ require_decorate.default([require_watch.watch("value", { waitUntilFirstUpdate: true })], SgdsCheckbox.prototype, "_handleValueChange", null);
222
236
  require_decorate.default([require_watch.watch("disabled", { waitUntilFirstUpdate: true })], SgdsCheckbox.prototype, "_handleDisabledChange", null);
223
237
  require_decorate.default([require_watch.watch("_isTouched", { waitUntilFirstUpdate: true })], SgdsCheckbox.prototype, "_handleIsTouched", null);
224
238
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"sgds-checkbox.cjs.js","names":["SgdsFormValidatorMixin","FormControlElement","HasSlotController","formCheckStyles","checkboxStyle","SgdsIcon","classMap","ifDefined","live","nothing","property","defaultValue","state","watch"],"sources":["../../../../src/components/Checkbox/sgds-checkbox.ts"],"sourcesContent":["import { html, nothing } from \"lit\";\nimport { property, state } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport { ifDefined } from \"lit/directives/if-defined.js\";\nimport { live } from \"lit/directives/live.js\";\nimport SgdsIcon from \"../Icon/sgds-icon\";\nimport FormControlElement from \"../../base/form-control-element\";\nimport { defaultValue } from \"../../utils/defaultvalue\";\nimport { SgdsFormControl } from \"../../utils/formSubmitController\";\nimport { SgdsFormValidatorMixin } from \"../../utils/validatorMixin\";\nimport { watch } from \"../../utils/watch\";\nimport { HasSlotController } from \"../../utils/slot\";\nimport checkboxStyle from \"./checkbox.css\";\nimport formCheckStyles from \"../../styles/form-check.css\";\n\n/**\n * @summary Checkbox component is used when you require users to select multiple items from a list.\n *\n * @slot default - The label of checkbox.\n *\n * @event sgds-change - Emitted when the checked state changes.\n * @event sgds-blur - Emitted when input is not in focus.\n * @event sgds-focus - Emitted when input is in focus.\n * @event sgds-check - Emitted when checkbox is checked\n * @event sgds-uncheck - Emitted when checkbox is unchecked\n * @event sgds-invalid - Emitted when the checkbox's invalid state is set to true.\n * @event sgds-valid - Emitted when the checkbox's invalid state is set to false.\n */\nexport class SgdsCheckbox extends SgdsFormValidatorMixin(FormControlElement) implements SgdsFormControl {\n static styles = [...FormControlElement.styles, formCheckStyles, checkboxStyle];\n\n private readonly hasSlotController = new HasSlotController(this, \"[default]\");\n\n /**@internal */\n static dependencies = {\n \"sgds-icon\": SgdsIcon\n };\n\n /** Value of the HTML form control. Primarily used to differentiate a list of related checkboxes that have the same name. */\n @property({ type: String, reflect: true }) value: string;\n\n /** Draws the checkbox in a checked state. */\n @property({ type: Boolean, reflect: true }) checked = false;\n\n /** Allows invalidFeedback, invalid and valid styles to be visible with the input */\n @property({ type: String, reflect: true }) hasFeedback: \"style\" | \"text\" | \"both\";\n\n /** @internal Gets or sets the default value used to reset this element. The initial value corresponds to the one originally specified in the HTML that created this element. */\n @defaultValue(\"checked\")\n defaultChecked = false;\n\n /** Marks the checkbox input as indeterminate , with indeterminate logo */\n @property({ type: Boolean, reflect: true }) indeterminate = false;\n\n /** Makes the checkbox a required field. */\n @property({ type: Boolean, reflect: true }) required = false;\n\n /** Disables native and sgds validation for the checkbox. */\n @property({ type: Boolean, reflect: true }) noValidate = false;\n\n /** Accessible label forwarded to the internal input's aria-label. Use when no visible label slot is used. */\n @property({ type: String }) ariaLabel = \"\";\n\n /**Feedback text for error state when validated */\n @property({ type: String, reflect: true }) invalidFeedback = \"\";\n\n @state() private _isTouched = false;\n\n /** Simulates a click on the checkbox. */\n public click() {\n this.input.click();\n }\n /** Sets focus on the checkbox. */\n public focus(options?: FocusOptions) {\n this.input.focus(options);\n }\n\n /** Removes focus from the checkbox. */\n public blur() {\n this.input.blur();\n }\n\n private _handleChange(e: Event) {\n if (this.indeterminate) {\n this.indeterminate = !this.indeterminate;\n }\n\n this.checked = !this.checked;\n super._mixinHandleChange(e);\n this.emit(\"sgds-change\", { detail: { checked: this.checked, value: this.value } });\n\n this.checked\n ? this.emit(\"sgds-check\", { detail: { value: this.value } })\n : this.emit(\"sgds-uncheck\", { detail: { value: this.value } });\n }\n\n private _handleKeyDown(event: KeyboardEvent) {\n const hasModifier = event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;\n if (event.key === \"Enter\" && !hasModifier) {\n this.click();\n }\n }\n\n private _handleBlur() {\n this._isTouched = true;\n this.emit(\"sgds-blur\");\n }\n\n private _handleFocus() {\n this.emit(\"sgds-focus\");\n }\n\n private _handleInvalid(e: Event) {\n e.preventDefault();\n this.invalid = true;\n }\n\n /** @internal */\n @watch(\"disabled\", { waitUntilFirstUpdate: true })\n _handleDisabledChange() {\n // Disabled form controls are always valid, so we need to recheck validity when the state changes\n this.setInvalid(false);\n }\n\n @watch(\"_isTouched\", { waitUntilFirstUpdate: true })\n _handleIsTouched() {\n if (this._mixinShouldSkipSgdsValidation()) return;\n if (this._isTouched) {\n this.invalid = !this.input.checkValidity();\n }\n }\n\n private _mixinResetFormControl() {\n this._isTouched = false;\n this.checked = this.input.checked = this.defaultChecked;\n this.input.dispatchEvent(new InputEvent(\"reset\"));\n this._mixinResetValidity(this.input);\n }\n /**\n * Checks for validity. Under the hood, HTMLFormElement's reportValidity method calls this method to check for component's validity state\n * Note that the native error popup is prevented for SGDS form components by default. Instead the validation message shows up in the feedback container of SgdsInput\n */\n public reportValidity(): boolean {\n return this._mixinReportValidity();\n }\n /**\n * Checks for validity without any native error popup message\n */\n public checkValidity(): boolean {\n return this._mixinCheckValidity();\n }\n /**\n * Returns the ValidityState object\n */\n public get validity(): ValidityState {\n return this._mixinGetValidity();\n }\n /**\n * Returns the validation message based on the ValidityState\n */\n public get validationMessage() {\n return this._mixinGetValidationMessage();\n }\n\n firstUpdated(_changedProperties) {\n super.firstUpdated(_changedProperties);\n this.checked && this.emit(\"sgds-check\", { detail: { value: this.value } });\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n this.addEventListener(\"click\", this._handleHostClick);\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.removeEventListener(\"click\", this._handleHostClick);\n }\n\n // Delegates host-targeted clicks to the internal input so that clicking anywhere\n // on the sgds-checkbox element (e.g. expanded padding inside sgds-dropdown-item) toggles\n // the checkbox. Clicks already originating from inside the shadow DOM are left alone.\n private _handleHostClick = (e: Event) => {\n if (e.composedPath()[0] === this) {\n e.stopPropagation();\n this.input.click();\n }\n };\n render() {\n const displayFeedbackStyle = this.hasFeedback === \"both\" || this.hasFeedback === \"style\";\n const displayFeedbackText = this.hasFeedback === \"both\" || this.hasFeedback === \"text\";\n const hasDefaultSlot = this.hasSlotController.test(\"[default]\");\n\n return html`\n <div class=\"form-check\">\n <input\n class=${classMap({\n \"form-check-input\": true,\n \"is-invalid\": displayFeedbackStyle && this.invalid\n })}\n type=\"checkbox\"\n id=${this._controlId}\n aria-invalid=${this.invalid ? \"true\" : \"false\"}\n aria-label=${ifDefined(this.ariaLabel || undefined)}\n name=${ifDefined(this.name)}\n ?indeterminate=${this.indeterminate}\n ?required=${this.required}\n aria-disabled=${this.disabled ? \"true\" : \"false\"}\n aria-checked=${this.checked ? \"true\" : \"false\"}\n @change=${(e: Event) => this._handleChange(e)}\n @keydown=${this._handleKeyDown}\n @invalid=${(e: Event) => this._handleInvalid(e)}\n ?checked=${live(this.checked)}\n .disabled=${this.disabled}\n .required=${this.required}\n @blur=${this._handleBlur}\n @focus=${this._handleFocus}\n />\n ${hasDefaultSlot\n ? html`<label for=\"${this._controlId}\" class=\"form-check-label\" id=\"${this._labelId}\"><slot></slot></label>`\n : nothing}\n </div>\n ${displayFeedbackText && this.invalid\n ? html`\n <div class=\"invalid-feedback-container\">\n <slot name=\"invalidIcon\">\n <sgds-icon name=\"exclamation-circle-fill\" size=\"md\"></sgds-icon>\n </slot>\n <div id=\"checkbox-feedback\" tabindex=\"0\" class=\"invalid-feedback\">\n ${this.invalidFeedback ? this.invalidFeedback : this.input.validationMessage}\n </div>\n </div>\n `\n : nothing}\n `;\n }\n}\n\nexport default SgdsCheckbox;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,IAAa,eAAb,cAAkCA,uBAAAA,uBAAuBC,6BAAAA,OAAkB,CAAC,CAA4B;;;EAGjE,KAAA,oBAAA,IAAIC,aAAAA,kBAAkB,MAAM,WAAW;EAWtB,KAAA,UAAA;EAOrC,KAAA,iBAAA;EAG2C,KAAA,gBAAA;EAGL,KAAA,WAAA;EAGE,KAAA,aAAA;EAGjB,KAAA,YAAA;EAGqB,KAAA,kBAAA;EAE/B,KAAA,aAAA;EAoHF,KAAA,oBAAA,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AAAK,CAAC,CAAA,GAAA,aAAA,WAAA,YAAA,KAAA,CAAA;AAGzCA,iBAAAA,QAAAA,EAAAA,GAAAA,kBAAAA,SAAAA,CAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,aAAA,WAAA,cAAA,KAAA,CAAA;AAGzCA,iBAAAA,QAAAA,EAAAA,GAAAA,kBAAAA,SAAAA,CAAS,EAAE,MAAM,OAAO,CAAC,CAAA,GAAA,aAAA,WAAA,aAAA,KAAA,CAAA;AAGzBA,iBAAAA,QAAAA,EAAAA,GAAAA,kBAAAA,SAAAA,CAAS;CAAE,MAAM;CAAQ,SAAS;AAAK,CAAC,CAAA,GAAA,aAAA,WAAA,mBAAA,KAAA,CAAA;AAExCE,iBAAAA,QAAAA,EAAAA,GAAAA,kBAAAA,MAAAA,CAAM,CAAA,GAAA,aAAA,WAAA,cAAA,KAAA,CAAA;AAoDNC,iBAAAA,QAAAA,CAAAA,cAAAA,MAAM,YAAY,EAAE,sBAAsB,KAAK,CAAC,CAAA,GAAA,aAAA,WAAA,yBAAA,IAAA;AAMhDA,iBAAAA,QAAAA,CAAAA,cAAAA,MAAM,cAAc,EAAE,sBAAsB,KAAK,CAAC,CAAA,GAAA,aAAA,WAAA,oBAAA,IAAA"}
1
+ {"version":3,"file":"sgds-checkbox.cjs.js","names":["SgdsFormValidatorMixin","FormControlElement","HasSlotController","formCheckStyles","checkboxStyle","SgdsIcon","classMap","ifDefined","live","nothing","property","defaultValue","state","watch"],"sources":["../../../../src/components/Checkbox/sgds-checkbox.ts"],"sourcesContent":["import { html, nothing } from \"lit\";\nimport { property, state } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport { ifDefined } from \"lit/directives/if-defined.js\";\nimport { live } from \"lit/directives/live.js\";\nimport SgdsIcon from \"../Icon/sgds-icon\";\nimport FormControlElement from \"../../base/form-control-element\";\nimport { defaultValue } from \"../../utils/defaultvalue\";\nimport { SgdsFormControl } from \"../../utils/formSubmitController\";\nimport { SgdsFormValidatorMixin } from \"../../utils/validatorMixin\";\nimport { watch } from \"../../utils/watch\";\nimport { HasSlotController } from \"../../utils/slot\";\nimport checkboxStyle from \"./checkbox.css\";\nimport formCheckStyles from \"../../styles/form-check.css\";\n\n/**\n * @summary Checkbox component is used when you require users to select multiple items from a list.\n *\n * @slot default - The label of checkbox.\n *\n * @event sgds-change - Emitted when the checked state changes.\n * @event sgds-blur - Emitted when input is not in focus.\n * @event sgds-focus - Emitted when input is in focus.\n * @event sgds-check - Emitted when checkbox is checked\n * @event sgds-uncheck - Emitted when checkbox is unchecked\n * @event sgds-invalid - Emitted when the checkbox's invalid state is set to true.\n * @event sgds-valid - Emitted when the checkbox's invalid state is set to false.\n */\nexport class SgdsCheckbox extends SgdsFormValidatorMixin(FormControlElement) implements SgdsFormControl {\n static styles = [...FormControlElement.styles, formCheckStyles, checkboxStyle];\n\n private readonly hasSlotController = new HasSlotController(this, \"[default]\");\n\n /**@internal */\n static dependencies = {\n \"sgds-icon\": SgdsIcon\n };\n\n /** Value submitted in FormData when the checkbox is checked. Defaults to `\"on\"` when not set, matching native checkbox behaviour. When unchecked, the key is absent from FormData. */\n @property({ type: String, reflect: true }) value: string;\n\n /** Draws the checkbox in a checked state. */\n @property({ type: Boolean, reflect: true }) checked = false;\n\n /** Allows invalidFeedback, invalid and valid styles to be visible with the input */\n @property({ type: String, reflect: true }) hasFeedback: \"style\" | \"text\" | \"both\";\n\n /** @internal Gets or sets the default value used to reset this element. The initial value corresponds to the one originally specified in the HTML that created this element. */\n @defaultValue(\"checked\")\n defaultChecked = false;\n\n /** Marks the checkbox input as indeterminate , with indeterminate logo */\n @property({ type: Boolean, reflect: true }) indeterminate = false;\n\n /** Makes the checkbox a required field. */\n @property({ type: Boolean, reflect: true }) required = false;\n\n /** Disables native and sgds validation for the checkbox. */\n @property({ type: Boolean, reflect: true }) noValidate = false;\n\n /** Accessible label forwarded to the internal input's aria-label. Use when no visible label slot is used. */\n @property({ type: String }) ariaLabel = \"\";\n\n /**Feedback text for error state when validated */\n @property({ type: String, reflect: true }) invalidFeedback = \"\";\n\n @state() private _isTouched = false;\n\n /** Simulates a click on the checkbox. */\n public click() {\n this.input.click();\n }\n /** Sets focus on the checkbox. */\n public focus(options?: FocusOptions) {\n this.input.focus(options);\n }\n\n /** Removes focus from the checkbox. */\n public blur() {\n this.input.blur();\n }\n\n private _handleChange(e: Event) {\n if (this.indeterminate) {\n this.indeterminate = !this.indeterminate;\n }\n\n this.checked = !this.checked;\n super._mixinHandleChange(e);\n this.emit(\"sgds-change\", { detail: { checked: this.checked, value: this.value } });\n\n this.checked\n ? this.emit(\"sgds-check\", { detail: { value: this.value } })\n : this.emit(\"sgds-uncheck\", { detail: { value: this.value } });\n }\n\n private _handleKeyDown(event: KeyboardEvent) {\n const hasModifier = event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;\n if (event.key === \"Enter\" && !hasModifier) {\n this.click();\n }\n }\n\n private _handleBlur() {\n this._isTouched = true;\n this.emit(\"sgds-blur\");\n }\n\n private _handleFocus() {\n this.emit(\"sgds-focus\");\n }\n\n private _handleInvalid(e: Event) {\n e.preventDefault();\n this.invalid = true;\n }\n\n /** Override mixin to match native checkbox: send value only when checked, default to \"on\". */\n private _mixinSetFormValue() {\n super._mixinSetFormValue(this.checked ? this.value ?? \"on\" : null);\n }\n\n /** @internal */\n @watch(\"checked\", { waitUntilFirstUpdate: true })\n _handleCheckedChange() {\n this._mixinSetFormValue();\n }\n\n /** @internal */\n @watch(\"value\", { waitUntilFirstUpdate: true })\n _handleValueChange() {\n this._mixinSetFormValue();\n }\n\n /** @internal */\n @watch(\"disabled\", { waitUntilFirstUpdate: true })\n _handleDisabledChange() {\n // Disabled form controls are always valid, so we need to recheck validity when the state changes\n this.setInvalid(false);\n }\n\n @watch(\"_isTouched\", { waitUntilFirstUpdate: true })\n _handleIsTouched() {\n if (this._mixinShouldSkipSgdsValidation()) return;\n if (this._isTouched) {\n this.invalid = !this.input.checkValidity();\n }\n }\n\n private _mixinResetFormControl() {\n this._isTouched = false;\n this.checked = this.input.checked = this.defaultChecked;\n this.input.dispatchEvent(new InputEvent(\"reset\"));\n this._mixinResetValidity(this.input);\n }\n /**\n * Checks for validity. Under the hood, HTMLFormElement's reportValidity method calls this method to check for component's validity state\n * Note that the native error popup is prevented for SGDS form components by default. Instead the validation message shows up in the feedback container of SgdsInput\n */\n public reportValidity(): boolean {\n return this._mixinReportValidity();\n }\n /**\n * Checks for validity without any native error popup message\n */\n public checkValidity(): boolean {\n return this._mixinCheckValidity();\n }\n /**\n * Returns the ValidityState object\n */\n public get validity(): ValidityState {\n return this._mixinGetValidity();\n }\n /**\n * Returns the validation message based on the ValidityState\n */\n public get validationMessage() {\n return this._mixinGetValidationMessage();\n }\n\n firstUpdated(_changedProperties) {\n super.firstUpdated(_changedProperties);\n this.checked && this.emit(\"sgds-check\", { detail: { value: this.value } });\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n this.addEventListener(\"click\", this._handleHostClick);\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.removeEventListener(\"click\", this._handleHostClick);\n }\n\n // Delegates host-targeted clicks to the internal input so that clicking anywhere\n // on the sgds-checkbox element (e.g. expanded padding inside sgds-dropdown-item) toggles\n // the checkbox. Clicks already originating from inside the shadow DOM are left alone.\n private _handleHostClick = (e: Event) => {\n if (e.composedPath()[0] === this) {\n e.stopPropagation();\n this.input.click();\n }\n };\n render() {\n const displayFeedbackStyle = this.hasFeedback === \"both\" || this.hasFeedback === \"style\";\n const displayFeedbackText = this.hasFeedback === \"both\" || this.hasFeedback === \"text\";\n const hasDefaultSlot = this.hasSlotController.test(\"[default]\");\n\n return html`\n <div class=\"form-check\">\n <input\n class=${classMap({\n \"form-check-input\": true,\n \"is-invalid\": displayFeedbackStyle && this.invalid\n })}\n type=\"checkbox\"\n id=${this._controlId}\n aria-invalid=${this.invalid ? \"true\" : \"false\"}\n aria-label=${ifDefined(this.ariaLabel || undefined)}\n name=${ifDefined(this.name)}\n ?indeterminate=${this.indeterminate}\n ?required=${this.required}\n aria-disabled=${this.disabled ? \"true\" : \"false\"}\n aria-checked=${this.checked ? \"true\" : \"false\"}\n @change=${(e: Event) => this._handleChange(e)}\n @keydown=${this._handleKeyDown}\n @invalid=${(e: Event) => this._handleInvalid(e)}\n ?checked=${live(this.checked)}\n .disabled=${this.disabled}\n .required=${this.required}\n @blur=${this._handleBlur}\n @focus=${this._handleFocus}\n />\n ${hasDefaultSlot\n ? html`<label for=\"${this._controlId}\" class=\"form-check-label\" id=\"${this._labelId}\"><slot></slot></label>`\n : nothing}\n </div>\n ${displayFeedbackText && this.invalid\n ? html`\n <div class=\"invalid-feedback-container\">\n <slot name=\"invalidIcon\">\n <sgds-icon name=\"exclamation-circle-fill\" size=\"md\"></sgds-icon>\n </slot>\n <div id=\"checkbox-feedback\" tabindex=\"0\" class=\"invalid-feedback\">\n ${this.invalidFeedback ? this.invalidFeedback : this.input.validationMessage}\n </div>\n </div>\n `\n : nothing}\n `;\n }\n}\n\nexport default SgdsCheckbox;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,IAAa,eAAb,cAAkCA,uBAAAA,uBAAuBC,6BAAAA,OAAkB,CAAC,CAA4B;;;EAGjE,KAAA,oBAAA,IAAIC,aAAAA,kBAAkB,MAAM,WAAW;EAWtB,KAAA,UAAA;EAOrC,KAAA,iBAAA;EAG2C,KAAA,gBAAA;EAGL,KAAA,WAAA;EAGE,KAAA,aAAA;EAGjB,KAAA,YAAA;EAGqB,KAAA,kBAAA;EAE/B,KAAA,aAAA;EAqIF,KAAA,oBAAA,MAAa;GACvC,IAAI,EAAE,aAAa,CAAC,CAAC,OAAO,MAAM;IAChC,EAAE,gBAAgB;IAClB,KAAK,MAAM,MAAM;GACnB;EACF;;;EA/KgB,KAAA,SAAA;GAAC,GAAGD,6BAAAA,QAAmB;GAAQE,mBAAAA;GAAiBC,iBAAAA;EAAa;;;EAKvD,KAAA,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AA;AAGzCA,iBAAAA,QAAAA,EAAAA,GAAAA,kBAAAA,SAAAA,CAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,aAAA,WAAA,cAAA,KAAA,CAAA;AAGzCA,iBAAAA,QAAAA,EAAAA,GAAAA,kBAAAA,SAAAA,CAAS,EAAE,MAAM,OAAO,CAAC,CAAA,GAAA,aAAA,WAAA,aAAA,KAAA,CAAA;AAGzBA,iBAAAA,QAAAA,EAAAA,GAAAA,kBAAAA,SAAAA,CAAS;CAAE,MAAM;CAAQ,SAAS;AAAK,CAAC,CAAA,GAAA,aAAA,WAAA,mBAAA,KAAA,CAAA;AAExCE,iBAAAA,QAAAA,EAAAA,GAAAA,kBAAAA,MAAAA,CAAM,CAAA,GAAA,aAAA,WAAA,cAAA,KAAA,CAAA;AAyDNC,iBAAAA,QAAAA,CAAAA,cAAAA,MAAM,WAAW,EAAE,sBAAsB,KAAK,CAAC,CAAA,GAAA,aAAA,WAAA,wBAAA,IAAA;AAM/CA,iBAAAA,QAAAA,CAAAA,cAAAA,MAAM,SAAS,EAAE,sBAAsB,KAAK,CAAC,CAAA,GAAA,aAAA,WAAA,sBAAA,IAAA;AAM7CA,iBAAAA,QAAAA,CAAAA,cAAAA,MAAM,YAAY,EAAE,sBAAsB,KAAK,CAAC,CAAA,GAAA,aAAA,WAAA,yBAAA,IAAA;AAMhDA,iBAAAA,QAAAA,CAAAA,cAAAA,MAAM,cAAc,EAAE,sBAAsB,KAAK,CAAC,CAAA,GAAA,aAAA,WAAA,oBAAA,IAAA"}
@@ -93,6 +93,18 @@ var SgdsCheckbox = class extends SgdsFormValidatorMixin(FormControlElement) {
93
93
  e.preventDefault();
94
94
  this.invalid = true;
95
95
  }
96
+ /** Override mixin to match native checkbox: send value only when checked, default to "on". */
97
+ _mixinSetFormValue() {
98
+ super._mixinSetFormValue(this.checked ? this.value ?? "on" : null);
99
+ }
100
+ /** @internal */
101
+ _handleCheckedChange() {
102
+ this._mixinSetFormValue();
103
+ }
104
+ /** @internal */
105
+ _handleValueChange() {
106
+ this._mixinSetFormValue();
107
+ }
96
108
  /** @internal */
97
109
  _handleDisabledChange() {
98
110
  this.setInvalid(false);
@@ -219,6 +231,8 @@ __decorate([property({
219
231
  reflect: true
220
232
  })], SgdsCheckbox.prototype, "invalidFeedback", void 0);
221
233
  __decorate([state()], SgdsCheckbox.prototype, "_isTouched", void 0);
234
+ __decorate([watch("checked", { waitUntilFirstUpdate: true })], SgdsCheckbox.prototype, "_handleCheckedChange", null);
235
+ __decorate([watch("value", { waitUntilFirstUpdate: true })], SgdsCheckbox.prototype, "_handleValueChange", null);
222
236
  __decorate([watch("disabled", { waitUntilFirstUpdate: true })], SgdsCheckbox.prototype, "_handleDisabledChange", null);
223
237
  __decorate([watch("_isTouched", { waitUntilFirstUpdate: true })], SgdsCheckbox.prototype, "_handleIsTouched", null);
224
238
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"sgds-checkbox.js","names":["formCheckStyles","checkboxStyle"],"sources":["../../../../src/components/Checkbox/sgds-checkbox.ts"],"sourcesContent":["import { html, nothing } from \"lit\";\nimport { property, state } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport { ifDefined } from \"lit/directives/if-defined.js\";\nimport { live } from \"lit/directives/live.js\";\nimport SgdsIcon from \"../Icon/sgds-icon\";\nimport FormControlElement from \"../../base/form-control-element\";\nimport { defaultValue } from \"../../utils/defaultvalue\";\nimport { SgdsFormControl } from \"../../utils/formSubmitController\";\nimport { SgdsFormValidatorMixin } from \"../../utils/validatorMixin\";\nimport { watch } from \"../../utils/watch\";\nimport { HasSlotController } from \"../../utils/slot\";\nimport checkboxStyle from \"./checkbox.css\";\nimport formCheckStyles from \"../../styles/form-check.css\";\n\n/**\n * @summary Checkbox component is used when you require users to select multiple items from a list.\n *\n * @slot default - The label of checkbox.\n *\n * @event sgds-change - Emitted when the checked state changes.\n * @event sgds-blur - Emitted when input is not in focus.\n * @event sgds-focus - Emitted when input is in focus.\n * @event sgds-check - Emitted when checkbox is checked\n * @event sgds-uncheck - Emitted when checkbox is unchecked\n * @event sgds-invalid - Emitted when the checkbox's invalid state is set to true.\n * @event sgds-valid - Emitted when the checkbox's invalid state is set to false.\n */\nexport class SgdsCheckbox extends SgdsFormValidatorMixin(FormControlElement) implements SgdsFormControl {\n static styles = [...FormControlElement.styles, formCheckStyles, checkboxStyle];\n\n private readonly hasSlotController = new HasSlotController(this, \"[default]\");\n\n /**@internal */\n static dependencies = {\n \"sgds-icon\": SgdsIcon\n };\n\n /** Value of the HTML form control. Primarily used to differentiate a list of related checkboxes that have the same name. */\n @property({ type: String, reflect: true }) value: string;\n\n /** Draws the checkbox in a checked state. */\n @property({ type: Boolean, reflect: true }) checked = false;\n\n /** Allows invalidFeedback, invalid and valid styles to be visible with the input */\n @property({ type: String, reflect: true }) hasFeedback: \"style\" | \"text\" | \"both\";\n\n /** @internal Gets or sets the default value used to reset this element. The initial value corresponds to the one originally specified in the HTML that created this element. */\n @defaultValue(\"checked\")\n defaultChecked = false;\n\n /** Marks the checkbox input as indeterminate , with indeterminate logo */\n @property({ type: Boolean, reflect: true }) indeterminate = false;\n\n /** Makes the checkbox a required field. */\n @property({ type: Boolean, reflect: true }) required = false;\n\n /** Disables native and sgds validation for the checkbox. */\n @property({ type: Boolean, reflect: true }) noValidate = false;\n\n /** Accessible label forwarded to the internal input's aria-label. Use when no visible label slot is used. */\n @property({ type: String }) ariaLabel = \"\";\n\n /**Feedback text for error state when validated */\n @property({ type: String, reflect: true }) invalidFeedback = \"\";\n\n @state() private _isTouched = false;\n\n /** Simulates a click on the checkbox. */\n public click() {\n this.input.click();\n }\n /** Sets focus on the checkbox. */\n public focus(options?: FocusOptions) {\n this.input.focus(options);\n }\n\n /** Removes focus from the checkbox. */\n public blur() {\n this.input.blur();\n }\n\n private _handleChange(e: Event) {\n if (this.indeterminate) {\n this.indeterminate = !this.indeterminate;\n }\n\n this.checked = !this.checked;\n super._mixinHandleChange(e);\n this.emit(\"sgds-change\", { detail: { checked: this.checked, value: this.value } });\n\n this.checked\n ? this.emit(\"sgds-check\", { detail: { value: this.value } })\n : this.emit(\"sgds-uncheck\", { detail: { value: this.value } });\n }\n\n private _handleKeyDown(event: KeyboardEvent) {\n const hasModifier = event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;\n if (event.key === \"Enter\" && !hasModifier) {\n this.click();\n }\n }\n\n private _handleBlur() {\n this._isTouched = true;\n this.emit(\"sgds-blur\");\n }\n\n private _handleFocus() {\n this.emit(\"sgds-focus\");\n }\n\n private _handleInvalid(e: Event) {\n e.preventDefault();\n this.invalid = true;\n }\n\n /** @internal */\n @watch(\"disabled\", { waitUntilFirstUpdate: true })\n _handleDisabledChange() {\n // Disabled form controls are always valid, so we need to recheck validity when the state changes\n this.setInvalid(false);\n }\n\n @watch(\"_isTouched\", { waitUntilFirstUpdate: true })\n _handleIsTouched() {\n if (this._mixinShouldSkipSgdsValidation()) return;\n if (this._isTouched) {\n this.invalid = !this.input.checkValidity();\n }\n }\n\n private _mixinResetFormControl() {\n this._isTouched = false;\n this.checked = this.input.checked = this.defaultChecked;\n this.input.dispatchEvent(new InputEvent(\"reset\"));\n this._mixinResetValidity(this.input);\n }\n /**\n * Checks for validity. Under the hood, HTMLFormElement's reportValidity method calls this method to check for component's validity state\n * Note that the native error popup is prevented for SGDS form components by default. Instead the validation message shows up in the feedback container of SgdsInput\n */\n public reportValidity(): boolean {\n return this._mixinReportValidity();\n }\n /**\n * Checks for validity without any native error popup message\n */\n public checkValidity(): boolean {\n return this._mixinCheckValidity();\n }\n /**\n * Returns the ValidityState object\n */\n public get validity(): ValidityState {\n return this._mixinGetValidity();\n }\n /**\n * Returns the validation message based on the ValidityState\n */\n public get validationMessage() {\n return this._mixinGetValidationMessage();\n }\n\n firstUpdated(_changedProperties) {\n super.firstUpdated(_changedProperties);\n this.checked && this.emit(\"sgds-check\", { detail: { value: this.value } });\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n this.addEventListener(\"click\", this._handleHostClick);\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.removeEventListener(\"click\", this._handleHostClick);\n }\n\n // Delegates host-targeted clicks to the internal input so that clicking anywhere\n // on the sgds-checkbox element (e.g. expanded padding inside sgds-dropdown-item) toggles\n // the checkbox. Clicks already originating from inside the shadow DOM are left alone.\n private _handleHostClick = (e: Event) => {\n if (e.composedPath()[0] === this) {\n e.stopPropagation();\n this.input.click();\n }\n };\n render() {\n const displayFeedbackStyle = this.hasFeedback === \"both\" || this.hasFeedback === \"style\";\n const displayFeedbackText = this.hasFeedback === \"both\" || this.hasFeedback === \"text\";\n const hasDefaultSlot = this.hasSlotController.test(\"[default]\");\n\n return html`\n <div class=\"form-check\">\n <input\n class=${classMap({\n \"form-check-input\": true,\n \"is-invalid\": displayFeedbackStyle && this.invalid\n })}\n type=\"checkbox\"\n id=${this._controlId}\n aria-invalid=${this.invalid ? \"true\" : \"false\"}\n aria-label=${ifDefined(this.ariaLabel || undefined)}\n name=${ifDefined(this.name)}\n ?indeterminate=${this.indeterminate}\n ?required=${this.required}\n aria-disabled=${this.disabled ? \"true\" : \"false\"}\n aria-checked=${this.checked ? \"true\" : \"false\"}\n @change=${(e: Event) => this._handleChange(e)}\n @keydown=${this._handleKeyDown}\n @invalid=${(e: Event) => this._handleInvalid(e)}\n ?checked=${live(this.checked)}\n .disabled=${this.disabled}\n .required=${this.required}\n @blur=${this._handleBlur}\n @focus=${this._handleFocus}\n />\n ${hasDefaultSlot\n ? html`<label for=\"${this._controlId}\" class=\"form-check-label\" id=\"${this._labelId}\"><slot></slot></label>`\n : nothing}\n </div>\n ${displayFeedbackText && this.invalid\n ? html`\n <div class=\"invalid-feedback-container\">\n <slot name=\"invalidIcon\">\n <sgds-icon name=\"exclamation-circle-fill\" size=\"md\"></sgds-icon>\n </slot>\n <div id=\"checkbox-feedback\" tabindex=\"0\" class=\"invalid-feedback\">\n ${this.invalidFeedback ? this.invalidFeedback : this.input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,SAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,aAAA,WAAA,YAAA,KAAA,CAAA;AAGzC,WAAA,CAAA,SAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,aAAA,WAAA,cAAA,KAAA,CAAA;AAGzC,WAAA,CAAA,SAAS,EAAE,MAAM,OAAO,CAAC,CAAA,GAAA,aAAA,WAAA,aAAA,KAAA,CAAA;AAGzB,WAAA,CAAA,SAAS;CAAE,MAAM;CAAQ,SAAS;AAAK,CAAC,CAAA,GAAA,aAAA,WAAA,mBAAA,KAAA,CAAA;AAExC,WAAA,CAAA,MAAM,CAAA,GAAA,aAAA,WAAA,cAAA,KAAA,CAAA;AAoDN,WAAA,CAAA,MAAM,YAAY,EAAE,sBAAsB,KAAK,CAAC,CAAA,GAAA,aAAA,WAAA,yBAAA,IAAA;AAMhD,WAAA,CAAA,MAAM,cAAc,EAAE,sBAAsB,KAAK,CAAC,CAAA,GAAA,aAAA,WAAA,oBAAA,IAAA"}
1
+ {"version":3,"file":"sgds-checkbox.js","names":["formCheckStyles","checkboxStyle"],"sources":["../../../../src/components/Checkbox/sgds-checkbox.ts"],"sourcesContent":["import { html, nothing } from \"lit\";\nimport { property, state } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport { ifDefined } from \"lit/directives/if-defined.js\";\nimport { live } from \"lit/directives/live.js\";\nimport SgdsIcon from \"../Icon/sgds-icon\";\nimport FormControlElement from \"../../base/form-control-element\";\nimport { defaultValue } from \"../../utils/defaultvalue\";\nimport { SgdsFormControl } from \"../../utils/formSubmitController\";\nimport { SgdsFormValidatorMixin } from \"../../utils/validatorMixin\";\nimport { watch } from \"../../utils/watch\";\nimport { HasSlotController } from \"../../utils/slot\";\nimport checkboxStyle from \"./checkbox.css\";\nimport formCheckStyles from \"../../styles/form-check.css\";\n\n/**\n * @summary Checkbox component is used when you require users to select multiple items from a list.\n *\n * @slot default - The label of checkbox.\n *\n * @event sgds-change - Emitted when the checked state changes.\n * @event sgds-blur - Emitted when input is not in focus.\n * @event sgds-focus - Emitted when input is in focus.\n * @event sgds-check - Emitted when checkbox is checked\n * @event sgds-uncheck - Emitted when checkbox is unchecked\n * @event sgds-invalid - Emitted when the checkbox's invalid state is set to true.\n * @event sgds-valid - Emitted when the checkbox's invalid state is set to false.\n */\nexport class SgdsCheckbox extends SgdsFormValidatorMixin(FormControlElement) implements SgdsFormControl {\n static styles = [...FormControlElement.styles, formCheckStyles, checkboxStyle];\n\n private readonly hasSlotController = new HasSlotController(this, \"[default]\");\n\n /**@internal */\n static dependencies = {\n \"sgds-icon\": SgdsIcon\n };\n\n /** Value submitted in FormData when the checkbox is checked. Defaults to `\"on\"` when not set, matching native checkbox behaviour. When unchecked, the key is absent from FormData. */\n @property({ type: String, reflect: true }) value: string;\n\n /** Draws the checkbox in a checked state. */\n @property({ type: Boolean, reflect: true }) checked = false;\n\n /** Allows invalidFeedback, invalid and valid styles to be visible with the input */\n @property({ type: String, reflect: true }) hasFeedback: \"style\" | \"text\" | \"both\";\n\n /** @internal Gets or sets the default value used to reset this element. The initial value corresponds to the one originally specified in the HTML that created this element. */\n @defaultValue(\"checked\")\n defaultChecked = false;\n\n /** Marks the checkbox input as indeterminate , with indeterminate logo */\n @property({ type: Boolean, reflect: true }) indeterminate = false;\n\n /** Makes the checkbox a required field. */\n @property({ type: Boolean, reflect: true }) required = false;\n\n /** Disables native and sgds validation for the checkbox. */\n @property({ type: Boolean, reflect: true }) noValidate = false;\n\n /** Accessible label forwarded to the internal input's aria-label. Use when no visible label slot is used. */\n @property({ type: String }) ariaLabel = \"\";\n\n /**Feedback text for error state when validated */\n @property({ type: String, reflect: true }) invalidFeedback = \"\";\n\n @state() private _isTouched = false;\n\n /** Simulates a click on the checkbox. */\n public click() {\n this.input.click();\n }\n /** Sets focus on the checkbox. */\n public focus(options?: FocusOptions) {\n this.input.focus(options);\n }\n\n /** Removes focus from the checkbox. */\n public blur() {\n this.input.blur();\n }\n\n private _handleChange(e: Event) {\n if (this.indeterminate) {\n this.indeterminate = !this.indeterminate;\n }\n\n this.checked = !this.checked;\n super._mixinHandleChange(e);\n this.emit(\"sgds-change\", { detail: { checked: this.checked, value: this.value } });\n\n this.checked\n ? this.emit(\"sgds-check\", { detail: { value: this.value } })\n : this.emit(\"sgds-uncheck\", { detail: { value: this.value } });\n }\n\n private _handleKeyDown(event: KeyboardEvent) {\n const hasModifier = event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;\n if (event.key === \"Enter\" && !hasModifier) {\n this.click();\n }\n }\n\n private _handleBlur() {\n this._isTouched = true;\n this.emit(\"sgds-blur\");\n }\n\n private _handleFocus() {\n this.emit(\"sgds-focus\");\n }\n\n private _handleInvalid(e: Event) {\n e.preventDefault();\n this.invalid = true;\n }\n\n /** Override mixin to match native checkbox: send value only when checked, default to \"on\". */\n private _mixinSetFormValue() {\n super._mixinSetFormValue(this.checked ? this.value ?? \"on\" : null);\n }\n\n /** @internal */\n @watch(\"checked\", { waitUntilFirstUpdate: true })\n _handleCheckedChange() {\n this._mixinSetFormValue();\n }\n\n /** @internal */\n @watch(\"value\", { waitUntilFirstUpdate: true })\n _handleValueChange() {\n this._mixinSetFormValue();\n }\n\n /** @internal */\n @watch(\"disabled\", { waitUntilFirstUpdate: true })\n _handleDisabledChange() {\n // Disabled form controls are always valid, so we need to recheck validity when the state changes\n this.setInvalid(false);\n }\n\n @watch(\"_isTouched\", { waitUntilFirstUpdate: true })\n _handleIsTouched() {\n if (this._mixinShouldSkipSgdsValidation()) return;\n if (this._isTouched) {\n this.invalid = !this.input.checkValidity();\n }\n }\n\n private _mixinResetFormControl() {\n this._isTouched = false;\n this.checked = this.input.checked = this.defaultChecked;\n this.input.dispatchEvent(new InputEvent(\"reset\"));\n this._mixinResetValidity(this.input);\n }\n /**\n * Checks for validity. Under the hood, HTMLFormElement's reportValidity method calls this method to check for component's validity state\n * Note that the native error popup is prevented for SGDS form components by default. Instead the validation message shows up in the feedback container of SgdsInput\n */\n public reportValidity(): boolean {\n return this._mixinReportValidity();\n }\n /**\n * Checks for validity without any native error popup message\n */\n public checkValidity(): boolean {\n return this._mixinCheckValidity();\n }\n /**\n * Returns the ValidityState object\n */\n public get validity(): ValidityState {\n return this._mixinGetValidity();\n }\n /**\n * Returns the validation message based on the ValidityState\n */\n public get validationMessage() {\n return this._mixinGetValidationMessage();\n }\n\n firstUpdated(_changedProperties) {\n super.firstUpdated(_changedProperties);\n this.checked && this.emit(\"sgds-check\", { detail: { value: this.value } });\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n this.addEventListener(\"click\", this._handleHostClick);\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.removeEventListener(\"click\", this._handleHostClick);\n }\n\n // Delegates host-targeted clicks to the internal input so that clicking anywhere\n // on the sgds-checkbox element (e.g. expanded padding inside sgds-dropdown-item) toggles\n // the checkbox. Clicks already originating from inside the shadow DOM are left alone.\n private _handleHostClick = (e: Event) => {\n if (e.composedPath()[0] === this) {\n e.stopPropagation();\n this.input.click();\n }\n };\n render() {\n const displayFeedbackStyle = this.hasFeedback === \"both\" || this.hasFeedback === \"style\";\n const displayFeedbackText = this.hasFeedback === \"both\" || this.hasFeedback === \"text\";\n const hasDefaultSlot = this.hasSlotController.test(\"[default]\");\n\n return html`\n <div class=\"form-check\">\n <input\n class=${classMap({\n \"form-check-input\": true,\n \"is-invalid\": displayFeedbackStyle && this.invalid\n })}\n type=\"checkbox\"\n id=${this._controlId}\n aria-invalid=${this.invalid ? \"true\" : \"false\"}\n aria-label=${ifDefined(this.ariaLabel || undefined)}\n name=${ifDefined(this.name)}\n ?indeterminate=${this.indeterminate}\n ?required=${this.required}\n aria-disabled=${this.disabled ? \"true\" : \"false\"}\n aria-checked=${this.checked ? \"true\" : \"false\"}\n @change=${(e: Event) => this._handleChange(e)}\n @keydown=${this._handleKeyDown}\n @invalid=${(e: Event) => this._handleInvalid(e)}\n ?checked=${live(this.checked)}\n .disabled=${this.disabled}\n .required=${this.required}\n @blur=${this._handleBlur}\n @focus=${this._handleFocus}\n />\n ${hasDefaultSlot\n ? html`<label for=\"${this._controlId}\" class=\"form-check-label\" id=\"${this._labelId}\"><slot></slot></label>`\n : nothing}\n </div>\n ${displayFeedbackText && this.invalid\n ? html`\n <div class=\"invalid-feedback-container\">\n <slot name=\"invalidIcon\">\n <sgds-icon name=\"exclamation-circle-fill\" size=\"md\"></sgds-icon>\n </slot>\n <div id=\"checkbox-feedback\" tabindex=\"0\" class=\"invalid-feedback\">\n ${this.invalidFeedback ? this.invalidFeedback : this.input.validationMessage}\n </div>\n </div>\n `\n : nothing}\n `;\n }\n}\n\nexport default SgdsCheckbox;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,IAAa,eAAb,cAAkC,uBAAuB,kBAAkB,CAAC,CAA4B;;;EAGjE,KAAA,oBAAA,IAAI,kBAAkB,MAAM,WAAW;EAWtB,KAAA,UAAA;EAOrC,KAAA,iBAAA;EAG2C,KAAA,gBAAA;EAGL,KAAA,WAAA;EAGE,KAAA,aAAA;EAGjB,KAAA,YAAA;EAGqB,KAAA,kBAAA;EAE/B,KAAA,aAAA;EAqIF,KAAA,oBAAA,MAAa;GACvC,IAAI,EAAE,aAAa,CAAC,CAAC,OAAO,MAAM;IAChC,EAAE,gBAAgB;IAClB,KAAK,MAAM,MAAM;GACnB;EACF;;;EA/KgB,KAAA,SAAA;GAAC,GAAG,mBAAmB;GAAQA;GAAiBC;EAAa;;;EAKvD,KAAA,eAAA,EACpB,aAAa,SACf;;;CAiCA,QAAe;EACb,KAAK,MAAM,MAAM;CACnB;;CAEA,MAAa,SAAwB;EACnC,KAAK,MAAM,MAAM,OAAO;CAC1B;;CAGA,OAAc;EACZ,KAAK,MAAM,KAAK;CAClB;CAEA,cAAsB,GAAU;EAC9B,IAAI,KAAK,eACP,KAAK,gBAAgB,CAAC,KAAK;EAG7B,KAAK,UAAU,CAAC,KAAK;EACrB,MAAM,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,CAAA,GAAA,aAAA,WAAA,yBAAA,IAAA;AAMhD,WAAA,CAAA,MAAM,cAAc,EAAE,sBAAsB,KAAK,CAAC,CAAA,GAAA,aAAA,WAAA,oBAAA,IAAA"}
@@ -84,9 +84,8 @@ const SgdsFormValidatorMixin = (superClass) => {
84
84
  if (this._mixinShouldSkipSgdsValidation()) return;
85
85
  this.inputValidationController.validateInput(input);
86
86
  }
87
- _mixinSetFormValue() {
88
- const value = this.value;
89
- this._internals.setFormValue(value);
87
+ _mixinSetFormValue(value) {
88
+ this._internals.setFormValue(value !== void 0 ? value : this.value);
90
89
  }
91
90
  _mixinCheckValidity() {
92
91
  if (this._mixinShouldSkipSgdsValidation()) return true;
@@ -1 +1 @@
1
- {"version":3,"file":"validatorMixin.cjs.js","names":["InputValidationController","queryAsync"],"sources":["../../../src/utils/validatorMixin.ts"],"sourcesContent":["import { LitElement, PropertyValueMap } from \"lit\";\nimport { queryAsync } from \"lit/decorators.js\";\nimport { SgdsInput } from \"../components\";\nimport { InputValidationController } from \"./inputValidationController\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Constructor<T> = new (...args: any[]) => T;\n\n/**\n * @summary The FormValidationMixin used by the form components\n * @param superClass\n * @returns\n */\nexport const SgdsFormValidatorMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n class ToBeValidatedElement extends superClass {\n static formAssociated = true;\n inputValidationController: InputValidationController;\n input: HTMLInputElement | SgdsInput | HTMLTextAreaElement;\n private _isTouched = false;\n private _internals: ElementInternals;\n @queryAsync(\"sgds-input\") sgdsInput: Promise<SgdsInput>;\n @queryAsync(\"sgds-datepicker-input\") sgdsDatepickerInput: Promise<SgdsInput>;\n\n // TypeScript requires mixin constructors to have rest parameter of type any[]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(...args);\n this._internals = this.attachInternals();\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n\n /** Idempotency guarantee — always create so reset can clear validity even with noValidate */\n this.inputValidationController ??= new InputValidationController(this);\n }\n async firstUpdated(changedProperties: PropertyValueMap<this>) {\n super.firstUpdated(changedProperties);\n\n /* Either input or sgds-input. For example, quantity-toggle uses sgds-input */\n this.input =\n this.shadowRoot.querySelector(\"input\") ||\n (await this.sgdsInput) ||\n this.shadowRoot.querySelector(\"textarea\") ||\n (await this.sgdsDatepickerInput);\n\n this._mixinSetFormValue();\n\n if (this._mixinShouldSkipSgdsValidation()) return;\n\n this._mixinValidate(this.input);\n }\n\n /**\n * Native lifecycle of Form-Associated Custom Element Callbacks\n */\n formResetCallback() {\n if (this._mixinResetFormControl) {\n this._mixinResetFormControl();\n } else {\n this.value = this.defaultValue;\n this._mixinResetValidity(this.input);\n }\n this._mixinSetFormValue();\n }\n /**\n *\n * Methods use by classes using this mixin\n */\n\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run change handler\n */\n _mixinHandleChange(e: Event): void {\n this._mixinSetFormValue();\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.handleChange(e);\n }\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run input handler\n */\n _mixinHandleInputChange(e: Event): void {\n this._mixinSetFormValue();\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.handleInput(e);\n }\n /**\n * During form resetting,\n * 1. ValidityState is reset (always, regardless of noValidate)\n * 2. invalid reactive prop is updated after the reset (always)\n * 3. Reset touched state to false for a pristine form (always)\n * 4. Revalidates the ValidityState (but do not update invalid prop)\n * to prepare for the next validity check (skipped when noValidate)\n */\n _mixinResetValidity(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n this.inputValidationController.resetValidity();\n this.inputValidationController.updateInvalidState();\n this._isTouched ? (this._isTouched = false) : null;\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.validateInput(input);\n }\n\n _mixinValidate(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.validateInput(input);\n }\n _mixinSetFormValue() {\n const value = this.value as string | FormData | File;\n this._internals.setFormValue(value);\n }\n _mixinCheckValidity(): boolean {\n if (this._mixinShouldSkipSgdsValidation()) return true;\n return this.inputValidationController.checkValidity();\n }\n _mixinReportValidity(): boolean {\n if (this._mixinShouldSkipSgdsValidation()) return true;\n return this.inputValidationController.reportValidity();\n }\n _mixinGetValidity(): ValidityState {\n return this._internals.validity;\n }\n _mixinGetValidationMessage(): string {\n return this._internals.validationMessage;\n }\n _mixinSetValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void {\n if (this._mixinShouldSkipSgdsValidation()) return;\n return this.inputValidationController.setValidity(flags, message, anchor);\n }\n // Only check for noValidate prop\n _mixinShouldSkipSgdsValidation() {\n const form = this.closest(\"form\");\n\n return form?.noValidate || this.noValidate;\n }\n\n /** DECLARED INSTANCE METHODS AND PROPERTIES*/\n\n /**\n * Resets a form control to its initial state\n */\n declare _mixinResetFormControl: () => void;\n declare value: string;\n declare defaultValue: string;\n declare defaultChecked: boolean;\n declare noValidate: boolean;\n }\n\n return ToBeValidatedElement as Constructor<ToBeValidatedElementInterface> & T;\n};\n\nexport declare class ToBeValidatedElementInterface {\n inputValidationController: InputValidationController;\n input: HTMLInputElement;\n _mixinHandleChange(e: Event): void;\n _mixinHandleInputChange(e: Event): void;\n _mixinResetValidity(input: HTMLInputElement | SgdsInput): void;\n _mixinValidate(input: HTMLInputElement | SgdsInput): void;\n _mixinSetFormValue(): void;\n _mixinCheckValidity(): boolean;\n _mixinReportValidity(): boolean;\n _mixinSetValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void;\n _mixinGetValidity(): ValidityState;\n _mixinGetValidationMessage(): string;\n _mixinShouldSkipSgdsValidation(): boolean;\n}\n"],"mappings":";;;;;;;;;;AAaA,MAAa,0BAA6D,eAAkB;CAC1F,MAAM,6BAA6B,WAAW;;GACpB,KAAA,iBAAA;;EAUxB,YAAY,GAAG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AClD,OAAO,KAAK,0BAA0B,cAAc;EACtD;EACA,uBAAgC;GAC9B,IAAI,KAAK,+BAA+B,GAAG,OAAO;GAClD,OAAO,KAAK,0BAA0B,eAAe;EACvD;EACA,oBAAmC;GACjC,OAAO,KAAK,WAAW;EACzB;EACA,6BAAqC;GACnC,OAAO,KAAK,WAAW;EACzB;EACA,kBAAkB,OAA4B,SAAkB,QAA4B;GAC1F,IAAI,KAAK,+BAA+B,GAAG;GAC3C,OAAO,KAAK,0BAA0B,YAAY,OAAO,SAAS,MAAM;EAC1E;EAEA,iCAAiC;GAG/B,OAFa,KAAK,QAAQ,MAEhB,CAAC,EAAE,cAAc,KAAK;EAClC;CAYF;CAjIGC,iBAAAA,QAAAA,EAAAA,GAAAA,kBAAAA,WAAAA,CAAW,YAAY,CAAA,GAAA,qBAAA,WAAA,aAAA,KAAA,CAAA;CACvBA,iBAAAA,QAAAA,EAAAA,GAAAA,kBAAAA,WAAAA,CAAW,uBAAuB,CAAA,GAAA,qBAAA,WAAA,uBAAA,KAAA,CAAA;CAkIrC,OAAO;AACT"}
1
+ {"version":3,"file":"validatorMixin.cjs.js","names":["InputValidationController","queryAsync"],"sources":["../../../src/utils/validatorMixin.ts"],"sourcesContent":["import { LitElement, PropertyValueMap } from \"lit\";\nimport { queryAsync } from \"lit/decorators.js\";\nimport { SgdsInput } from \"../components\";\nimport { InputValidationController } from \"./inputValidationController\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Constructor<T> = new (...args: any[]) => T;\n\n/**\n * @summary The FormValidationMixin used by the form components\n * @param superClass\n * @returns\n */\nexport const SgdsFormValidatorMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n class ToBeValidatedElement extends superClass {\n static formAssociated = true;\n inputValidationController: InputValidationController;\n input: HTMLInputElement | SgdsInput | HTMLTextAreaElement;\n private _isTouched = false;\n private _internals: ElementInternals;\n @queryAsync(\"sgds-input\") sgdsInput: Promise<SgdsInput>;\n @queryAsync(\"sgds-datepicker-input\") sgdsDatepickerInput: Promise<SgdsInput>;\n\n // TypeScript requires mixin constructors to have rest parameter of type any[]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(...args);\n this._internals = this.attachInternals();\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n\n /** Idempotency guarantee — always create so reset can clear validity even with noValidate */\n this.inputValidationController ??= new InputValidationController(this);\n }\n async firstUpdated(changedProperties: PropertyValueMap<this>) {\n super.firstUpdated(changedProperties);\n\n /* Either input or sgds-input. For example, quantity-toggle uses sgds-input */\n this.input =\n this.shadowRoot.querySelector(\"input\") ||\n (await this.sgdsInput) ||\n this.shadowRoot.querySelector(\"textarea\") ||\n (await this.sgdsDatepickerInput);\n\n this._mixinSetFormValue();\n\n if (this._mixinShouldSkipSgdsValidation()) return;\n\n this._mixinValidate(this.input);\n }\n\n /**\n * Native lifecycle of Form-Associated Custom Element Callbacks\n */\n formResetCallback() {\n if (this._mixinResetFormControl) {\n this._mixinResetFormControl();\n } else {\n this.value = this.defaultValue;\n this._mixinResetValidity(this.input);\n }\n this._mixinSetFormValue();\n }\n /**\n *\n * Methods use by classes using this mixin\n */\n\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run change handler\n */\n _mixinHandleChange(e: Event): void {\n this._mixinSetFormValue();\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.handleChange(e);\n }\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run input handler\n */\n _mixinHandleInputChange(e: Event): void {\n this._mixinSetFormValue();\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.handleInput(e);\n }\n /**\n * During form resetting,\n * 1. ValidityState is reset (always, regardless of noValidate)\n * 2. invalid reactive prop is updated after the reset (always)\n * 3. Reset touched state to false for a pristine form (always)\n * 4. Revalidates the ValidityState (but do not update invalid prop)\n * to prepare for the next validity check (skipped when noValidate)\n */\n _mixinResetValidity(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n this.inputValidationController.resetValidity();\n this.inputValidationController.updateInvalidState();\n this._isTouched ? (this._isTouched = false) : null;\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.validateInput(input);\n }\n\n _mixinValidate(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.validateInput(input);\n }\n _mixinSetFormValue(value?: string | FormData | File | null) {\n this._internals.setFormValue(value !== undefined ? value : (this.value as string | FormData | File));\n }\n _mixinCheckValidity(): boolean {\n if (this._mixinShouldSkipSgdsValidation()) return true;\n return this.inputValidationController.checkValidity();\n }\n _mixinReportValidity(): boolean {\n if (this._mixinShouldSkipSgdsValidation()) return true;\n return this.inputValidationController.reportValidity();\n }\n _mixinGetValidity(): ValidityState {\n return this._internals.validity;\n }\n _mixinGetValidationMessage(): string {\n return this._internals.validationMessage;\n }\n _mixinSetValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void {\n if (this._mixinShouldSkipSgdsValidation()) return;\n return this.inputValidationController.setValidity(flags, message, anchor);\n }\n // Only check for noValidate prop\n _mixinShouldSkipSgdsValidation() {\n const form = this.closest(\"form\");\n\n return form?.noValidate || this.noValidate;\n }\n\n /** DECLARED INSTANCE METHODS AND PROPERTIES*/\n\n /**\n * Resets a form control to its initial state\n */\n declare _mixinResetFormControl: () => void;\n declare value: string;\n declare defaultValue: string;\n declare defaultChecked: boolean;\n declare noValidate: boolean;\n }\n\n return ToBeValidatedElement as Constructor<ToBeValidatedElementInterface> & T;\n};\n\nexport declare class ToBeValidatedElementInterface {\n inputValidationController: InputValidationController;\n input: HTMLInputElement;\n _mixinHandleChange(e: Event): void;\n _mixinHandleInputChange(e: Event): void;\n _mixinResetValidity(input: HTMLInputElement | SgdsInput): void;\n _mixinValidate(input: HTMLInputElement | SgdsInput): void;\n _mixinSetFormValue(value?: string | FormData | File | null): void;\n _mixinCheckValidity(): boolean;\n _mixinReportValidity(): boolean;\n _mixinSetValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void;\n _mixinGetValidity(): ValidityState;\n _mixinGetValidationMessage(): string;\n _mixinShouldSkipSgdsValidation(): boolean;\n}\n"],"mappings":";;;;;;;;;;AAaA,MAAa,0BAA6D,eAAkB;CAC1F,MAAM,6BAA6B,WAAW;;GACpB,KAAA,iBAAA;;EAUxB,YAAY,GAAG,MAAa;GAC1B,MAAM,GAAG,IAAI;GARM,KAAA,aAAA;GASnB,KAAK,aAAa,KAAK,gBAAgB;EACzC;EAEA,oBAA0B;GACxB,MAAM,kBAAkB;;GAGxB,KAAK,8BAA8B,IAAIA,kCAAAA,0BAA0B,IAAI;EACvE;EACA,MAAM,aAAa,mBAA2C;GAC5D,MAAM,aAAa,iBAAiB;GAGpC,KAAK,QACH,KAAK,WAAW,cAAc,OAAO,KACpC,MAAM,KAAK,aACZ,KAAK,WAAW,cAAc,UAAU,KACvC,MAAM,KAAK;GAEd,KAAK,mBAAmB;GAExB,IAAI,KAAK,+BAA+B,GAAG;GAE3C,KAAK,eAAe,KAAK,KAAK;EAChC;;;;EAKA,oBAAoB;GAClB,IAAI,KAAK,wBACP,KAAK,uBAAuB;QACvB;IACL,KAAK,QAAQ,KAAK;IAClB,KAAK,oBAAoB,KAAK,KAAK;GACrC;GACA,KAAK,mBAAmB;EAC1B;;;;;;;;;;EAWA,mBAAmB,GAAgB;GACjC,KAAK,mBAAmB;GACxB,IAAI,KAAK,+BAA+B,GAAG;GAC3C,KAAK,0BAA0B,aAAa,CAAC;EAC/C;;;;;;EAMA,wBAAwB,GAAgB;GACtC,KAAK,mBAAmB;GACxB,IAAI,KAAK,+BAA+B,GAAG;GAC3C,KAAK,0BAA0B,YAAY,CAAC;EAC9C;;;;;;;;;EASA,oBAAoB,OAA2D;GAC7E,KAAK,0BAA0B,cAAc;GAC7C,KAAK,0BAA0B,mBAAmB;GAClD,KAAwB,eAAa;GACrC,IAAI,KAAK,+BAA+B,GAAG;GAC3C,KAAK,0BAA0B,cAAc,KAAK;EACpD;EAEA,eAAe,OAA2D;GACxE,IAAI,KAAK,+BAA+B,GAAG;GAC3C,KAAK,0BAA0B,cAAc,KAAK;EACpD;EACA,mBAAmB,OAAyC;GAC1D,KAAK,WAAW,aAAa,UAAU,KAAA,IAAY,QAAS,KAAK,KAAkC;EACrG;EACA,sBAA+B;GAC7B,IAAI,KAAK,+BAA+B,GAAG,OAAO;GAClD,OAAO,KAAK,0BAA0B,cAAc;EACtD;EACA,uBAAgC;GAC9B,IAAI,KAAK,+BAA+B,GAAG,OAAO;GAClD,OAAO,KAAK,0BAA0B,eAAe;EACvD;EACA,oBAAmC;GACjC,OAAO,KAAK,WAAW;EACzB;EACA,6BAAqC;GACnC,OAAO,KAAK,WAAW;EACzB;EACA,kBAAkB,OAA4B,SAAkB,QAA4B;GAC1F,IAAI,KAAK,+BAA+B,GAAG;GAC3C,OAAO,KAAK,0BAA0B,YAAY,OAAO,SAAS,MAAM;EAC1E;EAEA,iCAAiC;GAG/B,OAFa,KAAK,QAAQ,MAEhB,CAAC,EAAE,cAAc,KAAK;EAClC;CAYF;CAhIGC,iBAAAA,QAAAA,EAAAA,GAAAA,kBAAAA,WAAAA,CAAW,YAAY,CAAA,GAAA,qBAAA,WAAA,aAAA,KAAA,CAAA;CACvBA,iBAAAA,QAAAA,EAAAA,GAAAA,kBAAAA,WAAAA,CAAW,uBAAuB,CAAA,GAAA,qBAAA,WAAA,uBAAA,KAAA,CAAA;CAiIrC,OAAO;AACT"}
@@ -84,9 +84,8 @@ const SgdsFormValidatorMixin = (superClass) => {
84
84
  if (this._mixinShouldSkipSgdsValidation()) return;
85
85
  this.inputValidationController.validateInput(input);
86
86
  }
87
- _mixinSetFormValue() {
88
- const value = this.value;
89
- this._internals.setFormValue(value);
87
+ _mixinSetFormValue(value) {
88
+ this._internals.setFormValue(value !== void 0 ? value : this.value);
90
89
  }
91
90
  _mixinCheckValidity() {
92
91
  if (this._mixinShouldSkipSgdsValidation()) return true;
@@ -1 +1 @@
1
- {"version":3,"file":"validatorMixin.js","names":[],"sources":["../../../src/utils/validatorMixin.ts"],"sourcesContent":["import { LitElement, PropertyValueMap } from \"lit\";\nimport { queryAsync } from \"lit/decorators.js\";\nimport { SgdsInput } from \"../components\";\nimport { InputValidationController } from \"./inputValidationController\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Constructor<T> = new (...args: any[]) => T;\n\n/**\n * @summary The FormValidationMixin used by the form components\n * @param superClass\n * @returns\n */\nexport const SgdsFormValidatorMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n class ToBeValidatedElement extends superClass {\n static formAssociated = true;\n inputValidationController: InputValidationController;\n input: HTMLInputElement | SgdsInput | HTMLTextAreaElement;\n private _isTouched = false;\n private _internals: ElementInternals;\n @queryAsync(\"sgds-input\") sgdsInput: Promise<SgdsInput>;\n @queryAsync(\"sgds-datepicker-input\") sgdsDatepickerInput: Promise<SgdsInput>;\n\n // TypeScript requires mixin constructors to have rest parameter of type any[]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(...args);\n this._internals = this.attachInternals();\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n\n /** Idempotency guarantee — always create so reset can clear validity even with noValidate */\n this.inputValidationController ??= new InputValidationController(this);\n }\n async firstUpdated(changedProperties: PropertyValueMap<this>) {\n super.firstUpdated(changedProperties);\n\n /* Either input or sgds-input. For example, quantity-toggle uses sgds-input */\n this.input =\n this.shadowRoot.querySelector(\"input\") ||\n (await this.sgdsInput) ||\n this.shadowRoot.querySelector(\"textarea\") ||\n (await this.sgdsDatepickerInput);\n\n this._mixinSetFormValue();\n\n if (this._mixinShouldSkipSgdsValidation()) return;\n\n this._mixinValidate(this.input);\n }\n\n /**\n * Native lifecycle of Form-Associated Custom Element Callbacks\n */\n formResetCallback() {\n if (this._mixinResetFormControl) {\n this._mixinResetFormControl();\n } else {\n this.value = this.defaultValue;\n this._mixinResetValidity(this.input);\n }\n this._mixinSetFormValue();\n }\n /**\n *\n * Methods use by classes using this mixin\n */\n\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run change handler\n */\n _mixinHandleChange(e: Event): void {\n this._mixinSetFormValue();\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.handleChange(e);\n }\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run input handler\n */\n _mixinHandleInputChange(e: Event): void {\n this._mixinSetFormValue();\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.handleInput(e);\n }\n /**\n * During form resetting,\n * 1. ValidityState is reset (always, regardless of noValidate)\n * 2. invalid reactive prop is updated after the reset (always)\n * 3. Reset touched state to false for a pristine form (always)\n * 4. Revalidates the ValidityState (but do not update invalid prop)\n * to prepare for the next validity check (skipped when noValidate)\n */\n _mixinResetValidity(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n this.inputValidationController.resetValidity();\n this.inputValidationController.updateInvalidState();\n this._isTouched ? (this._isTouched = false) : null;\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.validateInput(input);\n }\n\n _mixinValidate(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.validateInput(input);\n }\n _mixinSetFormValue() {\n const value = this.value as string | FormData | File;\n this._internals.setFormValue(value);\n }\n _mixinCheckValidity(): boolean {\n if (this._mixinShouldSkipSgdsValidation()) return true;\n return this.inputValidationController.checkValidity();\n }\n _mixinReportValidity(): boolean {\n if (this._mixinShouldSkipSgdsValidation()) return true;\n return this.inputValidationController.reportValidity();\n }\n _mixinGetValidity(): ValidityState {\n return this._internals.validity;\n }\n _mixinGetValidationMessage(): string {\n return this._internals.validationMessage;\n }\n _mixinSetValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void {\n if (this._mixinShouldSkipSgdsValidation()) return;\n return this.inputValidationController.setValidity(flags, message, anchor);\n }\n // Only check for noValidate prop\n _mixinShouldSkipSgdsValidation() {\n const form = this.closest(\"form\");\n\n return form?.noValidate || this.noValidate;\n }\n\n /** DECLARED INSTANCE METHODS AND PROPERTIES*/\n\n /**\n * Resets a form control to its initial state\n */\n declare _mixinResetFormControl: () => void;\n declare value: string;\n declare defaultValue: string;\n declare defaultChecked: boolean;\n declare noValidate: boolean;\n }\n\n return ToBeValidatedElement as Constructor<ToBeValidatedElementInterface> & T;\n};\n\nexport declare class ToBeValidatedElementInterface {\n inputValidationController: InputValidationController;\n input: HTMLInputElement;\n _mixinHandleChange(e: Event): void;\n _mixinHandleInputChange(e: Event): void;\n _mixinResetValidity(input: HTMLInputElement | SgdsInput): void;\n _mixinValidate(input: HTMLInputElement | SgdsInput): void;\n _mixinSetFormValue(): void;\n _mixinCheckValidity(): boolean;\n _mixinReportValidity(): boolean;\n _mixinSetValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void;\n _mixinGetValidity(): ValidityState;\n _mixinGetValidationMessage(): string;\n _mixinShouldSkipSgdsValidation(): boolean;\n}\n"],"mappings":";;;;;;;;;;AAaA,MAAa,0BAA6D,eAAkB;CAC1F,MAAM,6BAA6B,WAAW;;GACpB,KAAA,iBAAA;;EAUxB,YAAY,GAAG,MAAa;GAC1B,MAAM,GAAG,IAAI;GARM,KAAA,aAAA;GASnB,KAAK,aAAa,KAAK,gBAAgB;EACzC;EAEA,oBAA0B;GACxB,MAAM,kBAAkB;;GAGxB,KAAK,8BAA8B,IAAI,0BAA0B,IAAI;EACvE;EACA,MAAM,aAAa,mBAA2C;GAC5D,MAAM,aAAa,iBAAiB;GAGpC,KAAK,QACH,KAAK,WAAW,cAAc,OAAO,KACpC,MAAM,KAAK,aACZ,KAAK,WAAW,cAAc,UAAU,KACvC,MAAM,KAAK;GAEd,KAAK,mBAAmB;GAExB,IAAI,KAAK,+BAA+B,GAAG;GAE3C,KAAK,eAAe,KAAK,KAAK;EAChC;;;;EAKA,oBAAoB;GAClB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Y,CAAA,GAAA,qBAAA,WAAA,aAAA,KAAA,CAAA;CACvB,WAAA,CAAA,WAAW,uBAAuB,CAAA,GAAA,qBAAA,WAAA,uBAAA,KAAA,CAAA;CAkIrC,OAAO;AACT"}
1
+ {"version":3,"file":"validatorMixin.js","names":[],"sources":["../../../src/utils/validatorMixin.ts"],"sourcesContent":["import { LitElement, PropertyValueMap } from \"lit\";\nimport { queryAsync } from \"lit/decorators.js\";\nimport { SgdsInput } from \"../components\";\nimport { InputValidationController } from \"./inputValidationController\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Constructor<T> = new (...args: any[]) => T;\n\n/**\n * @summary The FormValidationMixin used by the form components\n * @param superClass\n * @returns\n */\nexport const SgdsFormValidatorMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n class ToBeValidatedElement extends superClass {\n static formAssociated = true;\n inputValidationController: InputValidationController;\n input: HTMLInputElement | SgdsInput | HTMLTextAreaElement;\n private _isTouched = false;\n private _internals: ElementInternals;\n @queryAsync(\"sgds-input\") sgdsInput: Promise<SgdsInput>;\n @queryAsync(\"sgds-datepicker-input\") sgdsDatepickerInput: Promise<SgdsInput>;\n\n // TypeScript requires mixin constructors to have rest parameter of type any[]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(...args);\n this._internals = this.attachInternals();\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n\n /** Idempotency guarantee — always create so reset can clear validity even with noValidate */\n this.inputValidationController ??= new InputValidationController(this);\n }\n async firstUpdated(changedProperties: PropertyValueMap<this>) {\n super.firstUpdated(changedProperties);\n\n /* Either input or sgds-input. For example, quantity-toggle uses sgds-input */\n this.input =\n this.shadowRoot.querySelector(\"input\") ||\n (await this.sgdsInput) ||\n this.shadowRoot.querySelector(\"textarea\") ||\n (await this.sgdsDatepickerInput);\n\n this._mixinSetFormValue();\n\n if (this._mixinShouldSkipSgdsValidation()) return;\n\n this._mixinValidate(this.input);\n }\n\n /**\n * Native lifecycle of Form-Associated Custom Element Callbacks\n */\n formResetCallback() {\n if (this._mixinResetFormControl) {\n this._mixinResetFormControl();\n } else {\n this.value = this.defaultValue;\n this._mixinResetValidity(this.input);\n }\n this._mixinSetFormValue();\n }\n /**\n *\n * Methods use by classes using this mixin\n */\n\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run change handler\n */\n _mixinHandleChange(e: Event): void {\n this._mixinSetFormValue();\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.handleChange(e);\n }\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run input handler\n */\n _mixinHandleInputChange(e: Event): void {\n this._mixinSetFormValue();\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.handleInput(e);\n }\n /**\n * During form resetting,\n * 1. ValidityState is reset (always, regardless of noValidate)\n * 2. invalid reactive prop is updated after the reset (always)\n * 3. Reset touched state to false for a pristine form (always)\n * 4. Revalidates the ValidityState (but do not update invalid prop)\n * to prepare for the next validity check (skipped when noValidate)\n */\n _mixinResetValidity(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n this.inputValidationController.resetValidity();\n this.inputValidationController.updateInvalidState();\n this._isTouched ? (this._isTouched = false) : null;\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.validateInput(input);\n }\n\n _mixinValidate(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.validateInput(input);\n }\n _mixinSetFormValue(value?: string | FormData | File | null) {\n this._internals.setFormValue(value !== undefined ? value : (this.value as string | FormData | File));\n }\n _mixinCheckValidity(): boolean {\n if (this._mixinShouldSkipSgdsValidation()) return true;\n return this.inputValidationController.checkValidity();\n }\n _mixinReportValidity(): boolean {\n if (this._mixinShouldSkipSgdsValidation()) return true;\n return this.inputValidationController.reportValidity();\n }\n _mixinGetValidity(): ValidityState {\n return this._internals.validity;\n }\n _mixinGetValidationMessage(): string {\n return this._internals.validationMessage;\n }\n _mixinSetValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void {\n if (this._mixinShouldSkipSgdsValidation()) return;\n return this.inputValidationController.setValidity(flags, message, anchor);\n }\n // Only check for noValidate prop\n _mixinShouldSkipSgdsValidation() {\n const form = this.closest(\"form\");\n\n return form?.noValidate || this.noValidate;\n }\n\n /** DECLARED INSTANCE METHODS AND PROPERTIES*/\n\n /**\n * Resets a form control to its initial state\n */\n declare _mixinResetFormControl: () => void;\n declare value: string;\n declare defaultValue: string;\n declare defaultChecked: boolean;\n declare noValidate: boolean;\n }\n\n return ToBeValidatedElement as Constructor<ToBeValidatedElementInterface> & T;\n};\n\nexport declare class ToBeValidatedElementInterface {\n inputValidationController: InputValidationController;\n input: HTMLInputElement;\n _mixinHandleChange(e: Event): void;\n _mixinHandleInputChange(e: Event): void;\n _mixinResetValidity(input: HTMLInputElement | SgdsInput): void;\n _mixinValidate(input: HTMLInputElement | SgdsInput): void;\n _mixinSetFormValue(value?: string | FormData | File | null): void;\n _mixinCheckValidity(): boolean;\n _mixinReportValidity(): boolean;\n _mixinSetValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void;\n _mixinGetValidity(): ValidityState;\n _mixinGetValidationMessage(): string;\n _mixinShouldSkipSgdsValidation(): boolean;\n}\n"],"mappings":";;;;;;;;;;AAaA,MAAa,0BAA6D,eAAkB;CAC1F,MAAM,6BAA6B,WAAW;;GACpB,KAAA,iBAAA;;EAUxB,YAAY,GAAG,MAAa;GAC1B,MAAM,GAAG,IAAI;GARM,KAAA,aAAA;GASnB,KAAK,aAAa,KAAK,gBAAgB;EACzC;EAEA,oBAA0B;GACxB,MAAM,kBAAkB;;GAGxB,KAAK,8BAA8B,IAAI,0BAA0B,IAAI;EACvE;EACA,MAAM,aAAa,mBAA2C;GAC5D,MAAM,aAAa,iBAAiB;GAGpC,KAAK,QACH,KAAK,WAAW,cAAc,OAAO,KACpC,MAAM,KAAK,aACZ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GAC3C,OAAO,KAAK,0BAA0B,YAAY,OAAO,SAAS,MAAM;EAC1E;EAEA,iCAAiC;GAG/B,OAFa,KAAK,QAAQ,MAEhB,CAAC,EAAE,cAAc,KAAK;EAClC;CAYF;CAhIG,WAAA,CAAA,WAAW,YAAY,CAAA,GAAA,qBAAA,WAAA,aAAA,KAAA,CAAA;CACvB,WAAA,CAAA,WAAW,uBAAuB,CAAA,GAAA,qBAAA,WAAA,uBAAA,KAAA,CAAA;CAiIrC,OAAO;AACT"}
package/types/react.d.ts CHANGED
@@ -375,7 +375,7 @@ export interface SgdsCheckboxGroupProps extends SgdsBaseProps {
375
375
  // ── Checkbox ─────────────────────────────────────────────────────────────
376
376
 
377
377
  export interface SgdsCheckboxProps extends SgdsBaseProps {
378
- /** Value of the HTML form control. Primarily used to differentiate a list of related checkboxes that have the same name. */
378
+ /** Value submitted in FormData when the checkbox is checked. Defaults to `"on"` when not set, matching native checkbox behaviour. When unchecked, the key is absent from FormData. */
379
379
  value?: string;
380
380
  /** Draws the checkbox in a checked state. */
381
381
  checked?: boolean;
@@ -15,7 +15,7 @@ export declare class ToBeValidatedElementInterface {
15
15
  _mixinHandleInputChange(e: Event): void;
16
16
  _mixinResetValidity(input: HTMLInputElement | SgdsInput): void;
17
17
  _mixinValidate(input: HTMLInputElement | SgdsInput): void;
18
- _mixinSetFormValue(): void;
18
+ _mixinSetFormValue(value?: string | FormData | File | null): void;
19
19
  _mixinCheckValidity(): boolean;
20
20
  _mixinReportValidity(): boolean;
21
21
  _mixinSetValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void;
@@ -83,9 +83,8 @@ const SgdsFormValidatorMixin = (superClass) => {
83
83
  if (this._mixinShouldSkipSgdsValidation()) return;
84
84
  this.inputValidationController.validateInput(input);
85
85
  }
86
- _mixinSetFormValue() {
87
- const value = this.value;
88
- this._internals.setFormValue(value);
86
+ _mixinSetFormValue(value) {
87
+ this._internals.setFormValue(value !== void 0 ? value : this.value);
89
88
  }
90
89
  _mixinCheckValidity() {
91
90
  if (this._mixinShouldSkipSgdsValidation()) return true;
@@ -1 +1 @@
1
- {"version":3,"file":"validatorMixin.js","names":[],"sources":["../../src/utils/validatorMixin.ts"],"sourcesContent":["import { LitElement, PropertyValueMap } from \"lit\";\nimport { queryAsync } from \"lit/decorators.js\";\nimport { SgdsInput } from \"../components\";\nimport { InputValidationController } from \"./inputValidationController\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Constructor<T> = new (...args: any[]) => T;\n\n/**\n * @summary The FormValidationMixin used by the form components\n * @param superClass\n * @returns\n */\nexport const SgdsFormValidatorMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n class ToBeValidatedElement extends superClass {\n static formAssociated = true;\n inputValidationController: InputValidationController;\n input: HTMLInputElement | SgdsInput | HTMLTextAreaElement;\n private _isTouched = false;\n private _internals: ElementInternals;\n @queryAsync(\"sgds-input\") sgdsInput: Promise<SgdsInput>;\n @queryAsync(\"sgds-datepicker-input\") sgdsDatepickerInput: Promise<SgdsInput>;\n\n // TypeScript requires mixin constructors to have rest parameter of type any[]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(...args);\n this._internals = this.attachInternals();\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n\n /** Idempotency guarantee — always create so reset can clear validity even with noValidate */\n this.inputValidationController ??= new InputValidationController(this);\n }\n async firstUpdated(changedProperties: PropertyValueMap<this>) {\n super.firstUpdated(changedProperties);\n\n /* Either input or sgds-input. For example, quantity-toggle uses sgds-input */\n this.input =\n this.shadowRoot.querySelector(\"input\") ||\n (await this.sgdsInput) ||\n this.shadowRoot.querySelector(\"textarea\") ||\n (await this.sgdsDatepickerInput);\n\n this._mixinSetFormValue();\n\n if (this._mixinShouldSkipSgdsValidation()) return;\n\n this._mixinValidate(this.input);\n }\n\n /**\n * Native lifecycle of Form-Associated Custom Element Callbacks\n */\n formResetCallback() {\n if (this._mixinResetFormControl) {\n this._mixinResetFormControl();\n } else {\n this.value = this.defaultValue;\n this._mixinResetValidity(this.input);\n }\n this._mixinSetFormValue();\n }\n /**\n *\n * Methods use by classes using this mixin\n */\n\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run change handler\n */\n _mixinHandleChange(e: Event): void {\n this._mixinSetFormValue();\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.handleChange(e);\n }\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run input handler\n */\n _mixinHandleInputChange(e: Event): void {\n this._mixinSetFormValue();\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.handleInput(e);\n }\n /**\n * During form resetting,\n * 1. ValidityState is reset (always, regardless of noValidate)\n * 2. invalid reactive prop is updated after the reset (always)\n * 3. Reset touched state to false for a pristine form (always)\n * 4. Revalidates the ValidityState (but do not update invalid prop)\n * to prepare for the next validity check (skipped when noValidate)\n */\n _mixinResetValidity(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n this.inputValidationController.resetValidity();\n this.inputValidationController.updateInvalidState();\n this._isTouched ? (this._isTouched = false) : null;\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.validateInput(input);\n }\n\n _mixinValidate(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.validateInput(input);\n }\n _mixinSetFormValue() {\n const value = this.value as string | FormData | File;\n this._internals.setFormValue(value);\n }\n _mixinCheckValidity(): boolean {\n if (this._mixinShouldSkipSgdsValidation()) return true;\n return this.inputValidationController.checkValidity();\n }\n _mixinReportValidity(): boolean {\n if (this._mixinShouldSkipSgdsValidation()) return true;\n return this.inputValidationController.reportValidity();\n }\n _mixinGetValidity(): ValidityState {\n return this._internals.validity;\n }\n _mixinGetValidationMessage(): string {\n return this._internals.validationMessage;\n }\n _mixinSetValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void {\n if (this._mixinShouldSkipSgdsValidation()) return;\n return this.inputValidationController.setValidity(flags, message, anchor);\n }\n // Only check for noValidate prop\n _mixinShouldSkipSgdsValidation() {\n const form = this.closest(\"form\");\n\n return form?.noValidate || this.noValidate;\n }\n\n /** DECLARED INSTANCE METHODS AND PROPERTIES*/\n\n /**\n * Resets a form control to its initial state\n */\n declare _mixinResetFormControl: () => void;\n declare value: string;\n declare defaultValue: string;\n declare defaultChecked: boolean;\n declare noValidate: boolean;\n }\n\n return ToBeValidatedElement as Constructor<ToBeValidatedElementInterface> & T;\n};\n\nexport declare class ToBeValidatedElementInterface {\n inputValidationController: InputValidationController;\n input: HTMLInputElement;\n _mixinHandleChange(e: Event): void;\n _mixinHandleInputChange(e: Event): void;\n _mixinResetValidity(input: HTMLInputElement | SgdsInput): void;\n _mixinValidate(input: HTMLInputElement | SgdsInput): void;\n _mixinSetFormValue(): void;\n _mixinCheckValidity(): boolean;\n _mixinReportValidity(): boolean;\n _mixinSetValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void;\n _mixinGetValidity(): ValidityState;\n _mixinGetValidationMessage(): string;\n _mixinShouldSkipSgdsValidation(): boolean;\n}\n"],"mappings":";;;;;;;;;AAaA,MAAa,0BAA6D,eAAkB;CAC1F,MAAM,6BAA6B,WAAW;;GACpB,KAAA,iBAAA;;EAUxB,YAAY,GAAG,MAAa;GAC1B,MAAM,GAAG,IAAI;GARM,KAAA,aAAA;GASnB,KAAK,aAAa,KAAK,gBAAgB;EACzC;EAEA,oBAA0B;GACxB,MAAM,kBAAkB;;GAGxB,KAAK,8BAA8B,IAAI,0BAA0B,IAAI;EACvE;EACA,MAAM,aAAa,mBAA2C;GAC5D,MAAM,aAAa,iBAAiB;GAGpC,KAAK,QACH,KAAK,WAAW,cAAc,OAAO,KACpC,MAAM,KAAK,aACZ,KAAK,WAAW,cAAc,UAAU,KACvC,MAAM,KAAK;GAEd,KAAK,mBAAmB;GAExB,IAAI,KAAK,+BAA+B,GAAG;GAE3C,KAAK,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KAAK;EAClC;CAYF;CAjIG,WAAA,CAAA,WAAW,YAAY,CAAA,GAAA,qBAAA,WAAA,aAAA,KAAA,CAAA;CACvB,WAAA,CAAA,WAAW,uBAAuB,CAAA,GAAA,qBAAA,WAAA,uBAAA,KAAA,CAAA;CAkIrC,OAAO;AACT"}
1
+ {"version":3,"file":"validatorMixin.js","names":[],"sources":["../../src/utils/validatorMixin.ts"],"sourcesContent":["import { LitElement, PropertyValueMap } from \"lit\";\nimport { queryAsync } from \"lit/decorators.js\";\nimport { SgdsInput } from \"../components\";\nimport { InputValidationController } from \"./inputValidationController\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Constructor<T> = new (...args: any[]) => T;\n\n/**\n * @summary The FormValidationMixin used by the form components\n * @param superClass\n * @returns\n */\nexport const SgdsFormValidatorMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n class ToBeValidatedElement extends superClass {\n static formAssociated = true;\n inputValidationController: InputValidationController;\n input: HTMLInputElement | SgdsInput | HTMLTextAreaElement;\n private _isTouched = false;\n private _internals: ElementInternals;\n @queryAsync(\"sgds-input\") sgdsInput: Promise<SgdsInput>;\n @queryAsync(\"sgds-datepicker-input\") sgdsDatepickerInput: Promise<SgdsInput>;\n\n // TypeScript requires mixin constructors to have rest parameter of type any[]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(...args);\n this._internals = this.attachInternals();\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n\n /** Idempotency guarantee — always create so reset can clear validity even with noValidate */\n this.inputValidationController ??= new InputValidationController(this);\n }\n async firstUpdated(changedProperties: PropertyValueMap<this>) {\n super.firstUpdated(changedProperties);\n\n /* Either input or sgds-input. For example, quantity-toggle uses sgds-input */\n this.input =\n this.shadowRoot.querySelector(\"input\") ||\n (await this.sgdsInput) ||\n this.shadowRoot.querySelector(\"textarea\") ||\n (await this.sgdsDatepickerInput);\n\n this._mixinSetFormValue();\n\n if (this._mixinShouldSkipSgdsValidation()) return;\n\n this._mixinValidate(this.input);\n }\n\n /**\n * Native lifecycle of Form-Associated Custom Element Callbacks\n */\n formResetCallback() {\n if (this._mixinResetFormControl) {\n this._mixinResetFormControl();\n } else {\n this.value = this.defaultValue;\n this._mixinResetValidity(this.input);\n }\n this._mixinSetFormValue();\n }\n /**\n *\n * Methods use by classes using this mixin\n */\n\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run change handler\n */\n _mixinHandleChange(e: Event): void {\n this._mixinSetFormValue();\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.handleChange(e);\n }\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run input handler\n */\n _mixinHandleInputChange(e: Event): void {\n this._mixinSetFormValue();\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.handleInput(e);\n }\n /**\n * During form resetting,\n * 1. ValidityState is reset (always, regardless of noValidate)\n * 2. invalid reactive prop is updated after the reset (always)\n * 3. Reset touched state to false for a pristine form (always)\n * 4. Revalidates the ValidityState (but do not update invalid prop)\n * to prepare for the next validity check (skipped when noValidate)\n */\n _mixinResetValidity(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n this.inputValidationController.resetValidity();\n this.inputValidationController.updateInvalidState();\n this._isTouched ? (this._isTouched = false) : null;\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.validateInput(input);\n }\n\n _mixinValidate(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.validateInput(input);\n }\n _mixinSetFormValue(value?: string | FormData | File | null) {\n this._internals.setFormValue(value !== undefined ? value : (this.value as string | FormData | File));\n }\n _mixinCheckValidity(): boolean {\n if (this._mixinShouldSkipSgdsValidation()) return true;\n return this.inputValidationController.checkValidity();\n }\n _mixinReportValidity(): boolean {\n if (this._mixinShouldSkipSgdsValidation()) return true;\n return this.inputValidationController.reportValidity();\n }\n _mixinGetValidity(): ValidityState {\n return this._internals.validity;\n }\n _mixinGetValidationMessage(): string {\n return this._internals.validationMessage;\n }\n _mixinSetValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void {\n if (this._mixinShouldSkipSgdsValidation()) return;\n return this.inputValidationController.setValidity(flags, message, anchor);\n }\n // Only check for noValidate prop\n _mixinShouldSkipSgdsValidation() {\n const form = this.closest(\"form\");\n\n return form?.noValidate || this.noValidate;\n }\n\n /** DECLARED INSTANCE METHODS AND PROPERTIES*/\n\n /**\n * Resets a form control to its initial state\n */\n declare _mixinResetFormControl: () => void;\n declare value: string;\n declare defaultValue: string;\n declare defaultChecked: boolean;\n declare noValidate: boolean;\n }\n\n return ToBeValidatedElement as Constructor<ToBeValidatedElementInterface> & T;\n};\n\nexport declare class ToBeValidatedElementInterface {\n inputValidationController: InputValidationController;\n input: HTMLInputElement;\n _mixinHandleChange(e: Event): void;\n _mixinHandleInputChange(e: Event): void;\n _mixinResetValidity(input: HTMLInputElement | SgdsInput): void;\n _mixinValidate(input: HTMLInputElement | SgdsInput): void;\n _mixinSetFormValue(value?: string | FormData | File | null): void;\n _mixinCheckValidity(): boolean;\n _mixinReportValidity(): boolean;\n _mixinSetValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void;\n _mixinGetValidity(): ValidityState;\n _mixinGetValidationMessage(): string;\n _mixinShouldSkipSgdsValidation(): boolean;\n}\n"],"mappings":";;;;;;;;;AAaA,MAAa,0BAA6D,eAAkB;CAC1F,MAAM,6BAA6B,WAAW;;GACpB,KAAA,iBAAA;;EAUxB,YAAY,GAAG,MAAa;GAC1B,MAAM,GAAG,IAAI;GARM,KAAA,aAAA;GASnB,KAAK,aAAa,KAAK,gBAAgB;EACzC;EAEA,oBAA0B;GACxB,MAAM,kBAAkB;;GAGxB,KAAK,8BAA8B,IAAI,0BAA0B,IAAI;EACvE;EACA,MAAM,aAAa,mBAA2C;GAC5D,MAAM,aAAa,iBAAiB;GAGpC,KAAK,QACH,K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