@devschile/chucao 1.8.0 → 2.0.0

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 (128) hide show
  1. package/README.md +1 -0
  2. package/dist/chucao/chucao.esm.js +1 -1
  3. package/dist/chucao/p-10658dc9.entry.js +2 -0
  4. package/dist/chucao/p-10658dc9.entry.js.map +1 -0
  5. package/dist/chucao/p-19dde4f9.entry.js +2 -0
  6. package/dist/chucao/p-19dde4f9.entry.js.map +1 -0
  7. package/dist/chucao/p-2e20c7a1.entry.js +2 -0
  8. package/dist/chucao/p-2e20c7a1.entry.js.map +1 -0
  9. package/dist/chucao/{p-2d7e81b2.entry.js → p-66dce533.entry.js} +2 -2
  10. package/dist/chucao/p-75184fe1.entry.js +2 -0
  11. package/dist/chucao/p-75184fe1.entry.js.map +1 -0
  12. package/dist/chucao/{p-cbb2b478.entry.js → p-96c852f5.entry.js} +2 -2
  13. package/dist/chucao/p-BaKXvAYc.js +3 -0
  14. package/dist/chucao/p-BaKXvAYc.js.map +1 -0
  15. package/dist/chucao/{p-e8fe65bb.entry.js → p-a0ec231a.entry.js} +2 -2
  16. package/dist/chucao/{p-df73f786.entry.js → p-e48912c7.entry.js} +2 -2
  17. package/dist/chucao/{p-cfb6db53.entry.js → p-f04d2f75.entry.js} +2 -2
  18. package/dist/chucao/{p-1cc7042e.entry.js → p-f62e1da2.entry.js} +2 -2
  19. package/dist/cjs/ch-accordion.cjs.entry.js +1 -1
  20. package/dist/cjs/ch-alert_8.cjs.entry.js +184 -7
  21. package/dist/cjs/ch-alert_8.cjs.entry.js.map +1 -1
  22. package/dist/cjs/ch-checkbox.cjs.entry.js +62 -3
  23. package/dist/cjs/ch-checkbox.cjs.entry.js.map +1 -1
  24. package/dist/cjs/ch-divider.cjs.entry.js +1 -1
  25. package/dist/cjs/ch-link.cjs.entry.js +1 -1
  26. package/dist/cjs/ch-modal.cjs.entry.js +1 -1
  27. package/dist/cjs/ch-radio.cjs.entry.js +62 -3
  28. package/dist/cjs/ch-radio.cjs.entry.js.map +1 -1
  29. package/dist/cjs/ch-tabs.cjs.entry.js +1 -1
  30. package/dist/cjs/ch-textarea.cjs.entry.js +62 -3
  31. package/dist/cjs/ch-textarea.cjs.entry.js.map +1 -1
  32. package/dist/cjs/ch-tooltip.cjs.entry.js +1 -1
  33. package/dist/cjs/chucao.cjs.js +2 -2
  34. package/dist/cjs/{index-DMeDkSQU.js → index-C9Abf0td.js} +58 -6
  35. package/dist/cjs/index-C9Abf0td.js.map +1 -0
  36. package/dist/cjs/loader.cjs.js +2 -2
  37. package/dist/collection/components/ch-checkbox/ch-checkbox.css +10 -0
  38. package/dist/collection/components/ch-checkbox/ch-checkbox.js +64 -4
  39. package/dist/collection/components/ch-checkbox/ch-checkbox.js.map +1 -1
  40. package/dist/collection/components/ch-input/ch-input.css +11 -0
  41. package/dist/collection/components/ch-input/ch-input.js +64 -4
  42. package/dist/collection/components/ch-input/ch-input.js.map +1 -1
  43. package/dist/collection/components/ch-radio/ch-radio.css +10 -0
  44. package/dist/collection/components/ch-radio/ch-radio.js +64 -4
  45. package/dist/collection/components/ch-radio/ch-radio.js.map +1 -1
  46. package/dist/collection/components/ch-select/ch-select.css +11 -0
  47. package/dist/collection/components/ch-select/ch-select.js +64 -4
  48. package/dist/collection/components/ch-select/ch-select.js.map +1 -1
  49. package/dist/collection/components/ch-switch/ch-switch.css +10 -0
  50. package/dist/collection/components/ch-switch/ch-switch.js +64 -4
  51. package/dist/collection/components/ch-switch/ch-switch.js.map +1 -1
  52. package/dist/collection/components/ch-textarea/ch-textarea.css +11 -0
  53. package/dist/collection/components/ch-textarea/ch-textarea.js +64 -4
  54. package/dist/collection/components/ch-textarea/ch-textarea.js.map +1 -1
  55. package/dist/components/ch-accordion.js +1 -1
  56. package/dist/components/ch-alert.js +1 -1
  57. package/dist/components/ch-badge.js +1 -1
  58. package/dist/components/ch-button.js +1 -1
  59. package/dist/components/ch-card.js +1 -1
  60. package/dist/components/ch-checkbox.js +1 -1
  61. package/dist/components/ch-checkbox.js.map +1 -1
  62. package/dist/components/ch-divider.js +1 -1
  63. package/dist/components/ch-input.js +1 -1
  64. package/dist/components/ch-input.js.map +1 -1
  65. package/dist/components/ch-link.js +1 -1
  66. package/dist/components/ch-modal.js +1 -1
  67. package/dist/components/ch-radio.js +1 -1
  68. package/dist/components/ch-radio.js.map +1 -1
  69. package/dist/components/ch-select.js +1 -1
  70. package/dist/components/ch-select.js.map +1 -1
  71. package/dist/components/ch-spinner.js +1 -1
  72. package/dist/components/ch-switch.js +1 -1
  73. package/dist/components/ch-switch.js.map +1 -1
  74. package/dist/components/ch-tabs.js +1 -1
  75. package/dist/components/ch-textarea.js +1 -1
  76. package/dist/components/ch-textarea.js.map +1 -1
  77. package/dist/components/ch-tooltip.js +1 -1
  78. package/dist/components/index.js +1 -1
  79. package/dist/components/p-DL-bL54o.js +2 -0
  80. package/dist/components/p-DL-bL54o.js.map +1 -0
  81. package/dist/esm/ch-accordion.entry.js +1 -1
  82. package/dist/esm/ch-alert_8.entry.js +184 -7
  83. package/dist/esm/ch-alert_8.entry.js.map +1 -1
  84. package/dist/esm/ch-checkbox.entry.js +62 -3
  85. package/dist/esm/ch-checkbox.entry.js.map +1 -1
  86. package/dist/esm/ch-divider.entry.js +1 -1
  87. package/dist/esm/ch-link.entry.js +1 -1
  88. package/dist/esm/ch-modal.entry.js +1 -1
  89. package/dist/esm/ch-radio.entry.js +62 -3
  90. package/dist/esm/ch-radio.entry.js.map +1 -1
  91. package/dist/esm/ch-tabs.entry.js +1 -1
  92. package/dist/esm/ch-textarea.entry.js +62 -3
  93. package/dist/esm/ch-textarea.entry.js.map +1 -1
  94. package/dist/esm/ch-tooltip.entry.js +1 -1
  95. package/dist/esm/chucao.js +3 -3
  96. package/dist/esm/{index-Bvah_WQV.js → index-BaKXvAYc.js} +58 -6
  97. package/dist/esm/index-BaKXvAYc.js.map +1 -0
  98. package/dist/esm/loader.js +3 -3
  99. package/dist/types/components/ch-checkbox/ch-checkbox.d.ts +9 -0
  100. package/dist/types/components/ch-input/ch-input.d.ts +9 -0
  101. package/dist/types/components/ch-radio/ch-radio.d.ts +9 -0
  102. package/dist/types/components/ch-select/ch-select.d.ts +9 -0
  103. package/dist/types/components/ch-switch/ch-switch.d.ts +9 -0
  104. package/dist/types/components/ch-textarea/ch-textarea.d.ts +9 -0
  105. package/dist/types/components.d.ts +24 -0
  106. package/hydrate/index.js +426 -52
  107. package/hydrate/index.mjs +426 -52
  108. package/package.json +4 -1
  109. package/dist/chucao/p-13ab5f9a.entry.js +0 -2
  110. package/dist/chucao/p-13ab5f9a.entry.js.map +0 -1
  111. package/dist/chucao/p-23c5220b.entry.js +0 -2
  112. package/dist/chucao/p-23c5220b.entry.js.map +0 -1
  113. package/dist/chucao/p-421cda05.entry.js +0 -2
  114. package/dist/chucao/p-421cda05.entry.js.map +0 -1
  115. package/dist/chucao/p-Bvah_WQV.js +0 -3
  116. package/dist/chucao/p-Bvah_WQV.js.map +0 -1
  117. package/dist/chucao/p-c16b18b7.entry.js +0 -2
  118. package/dist/chucao/p-c16b18b7.entry.js.map +0 -1
  119. package/dist/cjs/index-DMeDkSQU.js.map +0 -1
  120. package/dist/components/p-hyy-cLgi.js +0 -2
  121. package/dist/components/p-hyy-cLgi.js.map +0 -1
  122. package/dist/esm/index-Bvah_WQV.js.map +0 -1
  123. /package/dist/chucao/{p-2d7e81b2.entry.js.map → p-66dce533.entry.js.map} +0 -0
  124. /package/dist/chucao/{p-cbb2b478.entry.js.map → p-96c852f5.entry.js.map} +0 -0
  125. /package/dist/chucao/{p-e8fe65bb.entry.js.map → p-a0ec231a.entry.js.map} +0 -0
  126. /package/dist/chucao/{p-df73f786.entry.js.map → p-e48912c7.entry.js.map} +0 -0
  127. /package/dist/chucao/{p-cfb6db53.entry.js.map → p-f04d2f75.entry.js.map} +0 -0
  128. /package/dist/chucao/{p-1cc7042e.entry.js.map → p-f62e1da2.entry.js.map} +0 -0
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-DMeDkSQU.js');
3
+ var index = require('./index-C9Abf0td.js');
4
4
 
5
5
  const defineCustomElements = async (win, options) => {
6
6
  if (typeof window === 'undefined') return undefined;
7
7
  await index.globalScripts();
8
- return index.bootstrapLazy([["ch-alert_8.cjs",[[769,"ch-alert",{"variant":[1],"dismissLabel":[1,"dismiss-label"]}],[769,"ch-badge",{"variant":[1]}],[769,"ch-button",{"variant":[1],"disabled":[4],"label":[1]}],[257,"ch-card"],[513,"ch-input",{"label":[1],"type":[1],"value":[1025],"placeholder":[1],"name":[1],"disabled":[4],"required":[4],"hint":[1],"errorMessage":[1,"error-message"],"invalid":[4]}],[513,"ch-select",{"label":[1],"options":[16],"value":[1025],"placeholder":[1],"name":[1],"disabled":[4],"required":[4],"hint":[1],"errorMessage":[1,"error-message"],"invalid":[4]}],[513,"ch-spinner",{"size":[1],"label":[1]}],[513,"ch-switch",{"label":[1],"name":[1],"value":[1],"checked":[1028],"disabled":[4],"required":[4],"hint":[1],"errorMessage":[1,"error-message"],"invalid":[4]}]]],["ch-accordion.cjs",[[769,"ch-accordion",{"items":[16],"value":[1025]}]]],["ch-checkbox.cjs",[[513,"ch-checkbox",{"label":[1],"name":[1],"value":[1],"checked":[1028],"disabled":[4],"required":[4],"hint":[1],"errorMessage":[1,"error-message"],"invalid":[4]}]]],["ch-divider.cjs",[[513,"ch-divider",{"orientation":[1]}]]],["ch-link.cjs",[[769,"ch-link",{"href":[1],"target":[1],"variant":[1],"disabled":[4]}]]],["ch-modal.cjs",[[769,"ch-modal",{"open":[1028],"label":[1],"closeLabel":[1,"close-label"]},null,{"open":[{"handleOpenChange":0}]}]]],["ch-radio.cjs",[[513,"ch-radio",{"label":[1],"options":[16],"value":[1025],"name":[1],"disabled":[4],"required":[4],"hint":[1],"errorMessage":[1,"error-message"],"invalid":[4]}]]],["ch-tabs.cjs",[[769,"ch-tabs",{"tabs":[16],"value":[1025],"label":[1]}]]],["ch-textarea.cjs",[[513,"ch-textarea",{"label":[1],"value":[1025],"placeholder":[1],"rows":[2],"name":[1],"disabled":[4],"required":[4],"hint":[1],"errorMessage":[1,"error-message"],"invalid":[4]}]]],["ch-tooltip.cjs",[[769,"ch-tooltip",{"placement":[1],"hovered":[32],"focused":[32],"dismissed":[32]},[[1,"mouseenter","handleMouseEnter"],[1,"mouseleave","handleMouseLeave"],[0,"focusin","handleFocusIn"],[0,"focusout","handleFocusOut"],[4,"keydown","handleKeyDown"]]]]]], options);
8
+ return index.bootstrapLazy([["ch-alert_8.cjs",[[769,"ch-alert",{"variant":[1],"dismissLabel":[1,"dismiss-label"]}],[769,"ch-badge",{"variant":[1]}],[769,"ch-button",{"variant":[1],"disabled":[4],"label":[1]}],[257,"ch-card"],[577,"ch-input",{"label":[1],"type":[1],"value":[1025],"placeholder":[1],"name":[513],"disabled":[516],"required":[516],"hint":[1],"errorMessage":[1,"error-message"],"invalid":[4],"formDisabled":[32]},null,{"value":[{"syncForm":0}],"required":[{"syncForm":0}],"invalid":[{"syncForm":0}],"errorMessage":[{"syncForm":0}]}],[577,"ch-select",{"label":[1],"options":[16],"value":[1025],"placeholder":[1],"name":[513],"disabled":[516],"required":[516],"hint":[1],"errorMessage":[1,"error-message"],"invalid":[4],"formDisabled":[32]},null,{"value":[{"syncForm":0}],"required":[{"syncForm":0}],"invalid":[{"syncForm":0}],"errorMessage":[{"syncForm":0}]}],[513,"ch-spinner",{"size":[1],"label":[1]}],[577,"ch-switch",{"label":[1],"name":[513],"value":[1],"checked":[1028],"disabled":[516],"required":[516],"hint":[1],"errorMessage":[1,"error-message"],"invalid":[4],"formDisabled":[32]},null,{"checked":[{"syncForm":0}],"required":[{"syncForm":0}],"invalid":[{"syncForm":0}],"errorMessage":[{"syncForm":0}]}]]],["ch-accordion.cjs",[[769,"ch-accordion",{"items":[16],"value":[1025]}]]],["ch-checkbox.cjs",[[577,"ch-checkbox",{"label":[1],"name":[513],"value":[1],"checked":[1028],"disabled":[516],"required":[516],"hint":[1],"errorMessage":[1,"error-message"],"invalid":[4],"formDisabled":[32]},null,{"checked":[{"syncForm":0}],"required":[{"syncForm":0}],"invalid":[{"syncForm":0}],"errorMessage":[{"syncForm":0}]}]]],["ch-divider.cjs",[[513,"ch-divider",{"orientation":[1]}]]],["ch-link.cjs",[[769,"ch-link",{"href":[1],"target":[1],"variant":[1],"disabled":[4]}]]],["ch-modal.cjs",[[769,"ch-modal",{"open":[1028],"label":[1],"closeLabel":[1,"close-label"]},null,{"open":[{"handleOpenChange":0}]}]]],["ch-radio.cjs",[[577,"ch-radio",{"label":[1],"options":[16],"value":[1025],"name":[513],"disabled":[516],"required":[516],"hint":[1],"errorMessage":[1,"error-message"],"invalid":[4],"formDisabled":[32]},null,{"value":[{"syncForm":0}],"required":[{"syncForm":0}],"invalid":[{"syncForm":0}],"errorMessage":[{"syncForm":0}]}]]],["ch-tabs.cjs",[[769,"ch-tabs",{"tabs":[16],"value":[1025],"label":[1]}]]],["ch-textarea.cjs",[[577,"ch-textarea",{"label":[1],"value":[1025],"placeholder":[1],"rows":[2],"name":[513],"disabled":[516],"required":[516],"hint":[1],"errorMessage":[1,"error-message"],"invalid":[4],"formDisabled":[32]},null,{"value":[{"syncForm":0}],"required":[{"syncForm":0}],"invalid":[{"syncForm":0}],"errorMessage":[{"syncForm":0}]}]]],["ch-tooltip.cjs",[[769,"ch-tooltip",{"placement":[1],"hovered":[32],"focused":[32],"dismissed":[32]},[[1,"mouseenter","handleMouseEnter"],[1,"mouseleave","handleMouseLeave"],[0,"focusin","handleFocusIn"],[0,"focusout","handleFocusOut"],[4,"keydown","handleKeyDown"]]]]]], options);
9
9
  };
10
10
 
11
11
  exports.setNonce = index.setNonce;
@@ -63,6 +63,16 @@
63
63
  outline-color: var(--color-status-warning);
64
64
  }
65
65
 
66
+ :host([data-touched]:invalid) .input,
67
+ :host(:user-invalid) .input {
68
+ border-color: var(--color-status-warning);
69
+ }
70
+
71
+ :host([data-touched]:invalid) .input:focus-visible,
72
+ :host(:user-invalid) .input:focus-visible {
73
+ outline-color: var(--color-status-warning);
74
+ }
75
+
66
76
  .label-text {
67
77
  color: var(--text);
68
78
  }
@@ -4,6 +4,10 @@ export class ChCheckbox {
4
4
  checkboxId = `ch-checkbox-${++checkboxIds}`;
5
5
  hintId = `${this.checkboxId}-hint`;
6
6
  errorId = `${this.checkboxId}-error`;
7
+ initialChecked = false;
8
+ internals;
9
+ formDisabled = false;
10
+ host;
7
11
  /**
8
12
  * Visible label rendered next to the checkbox, associated with it via
9
13
  * `for`/`id`, so assistive technology announces the checkbox's purpose.
@@ -50,6 +54,39 @@ export class ChCheckbox {
50
54
  this.checked = ev.target.checked;
51
55
  this.chChange.emit(this.checked);
52
56
  };
57
+ syncForm() {
58
+ const internals = this.internals;
59
+ if (typeof internals?.setFormValue !== 'function') {
60
+ return;
61
+ }
62
+ internals.setFormValue(this.checked ? this.value : null);
63
+ const flags = {};
64
+ let message;
65
+ if (this.required && !this.checked) {
66
+ flags.valueMissing = true;
67
+ }
68
+ if (this.invalid && this.errorMessage) {
69
+ flags.customError = true;
70
+ }
71
+ message = this.errorMessage ?? (flags.valueMissing ? 'Please fill out this field.' : undefined);
72
+ internals.setValidity(flags, message);
73
+ }
74
+ componentDidLoad() {
75
+ this.initialChecked = this.checked;
76
+ this.syncForm();
77
+ this.host.addEventListener('change', this.markTouched);
78
+ this.host.addEventListener('focusout', this.markTouched);
79
+ this.host.addEventListener('invalid', this.markTouched);
80
+ }
81
+ markTouched = () => {
82
+ this.host.setAttribute('data-touched', '');
83
+ };
84
+ formResetCallback() {
85
+ this.checked = this.initialChecked;
86
+ }
87
+ formDisabledCallback(isDisabled) {
88
+ this.formDisabled = isDisabled;
89
+ }
53
90
  get describedBy() {
54
91
  if (this.invalid && this.errorMessage) {
55
92
  return this.errorId;
@@ -60,10 +97,11 @@ export class ChCheckbox {
60
97
  return undefined;
61
98
  }
62
99
  render() {
63
- return (h(Host, { key: '130d1bf88ae8c73befe7ac288a0d4b7113fd73f7' }, h("label", { key: '6a3dd5bd889a9b41dda934b7c804de3ff2a63584', class: { 'control': true, 'control--disabled': this.disabled }, htmlFor: this.checkboxId }, h("input", { key: '9978d057782e3cf31a2fa7b4042b5d070e015be0', id: this.checkboxId, class: { 'input': true, 'input--invalid': this.invalid }, type: "checkbox", name: this.name, value: this.value, checked: this.checked, disabled: this.disabled, required: this.required, "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onChange: this.handleChange }), this.label && h("span", { key: '8b12d266d0693b6ad710c5a72df4b3c138435ef1', class: "label-text" }, this.label)), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: '7aa3b14ccdfb216d8bc831c820e5438e166dab1c', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: 'aeacbc8e1f98162182149e55fde0d8d588c97fa4', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
100
+ return (h(Host, { key: 'ca6c6f1297434052eeee68fd76cf21d6a7b99aae' }, h("label", { key: '1f3538da6eb2ce91a75cf73044e2103ba472d4ed', class: { 'control': true, 'control--disabled': this.disabled || this.formDisabled }, htmlFor: this.checkboxId }, h("input", { key: '7ed674616bc70af42b025a2b945378192ce48a58', id: this.checkboxId, class: { 'input': true, 'input--invalid': this.invalid }, type: "checkbox", name: this.name, value: this.value, checked: this.checked, disabled: this.disabled || this.formDisabled, required: this.required, "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onChange: this.handleChange }), this.label && h("span", { key: '4f5ccc7b28d95d012aa5cd87ec2411be34672d9e', class: "label-text" }, this.label)), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: 'b7d2b09c54ed61907e4e7110af867b2a0592924c', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '2340791705a5fce22b810a3a32377a7b1ccef852', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
64
101
  }
65
102
  static get is() { return "ch-checkbox"; }
66
103
  static get encapsulation() { return "shadow"; }
104
+ static get formAssociated() { return true; }
67
105
  static get originalStyleUrls() {
68
106
  return {
69
107
  "$": ["ch-checkbox.css"]
@@ -111,7 +149,7 @@ export class ChCheckbox {
111
149
  },
112
150
  "getter": false,
113
151
  "setter": false,
114
- "reflect": false,
152
+ "reflect": true,
115
153
  "attribute": "name"
116
154
  },
117
155
  "value": {
@@ -170,7 +208,7 @@ export class ChCheckbox {
170
208
  },
171
209
  "getter": false,
172
210
  "setter": false,
173
- "reflect": false,
211
+ "reflect": true,
174
212
  "attribute": "disabled",
175
213
  "defaultValue": "false"
176
214
  },
@@ -190,7 +228,7 @@ export class ChCheckbox {
190
228
  },
191
229
  "getter": false,
192
230
  "setter": false,
193
- "reflect": false,
231
+ "reflect": true,
194
232
  "attribute": "required",
195
233
  "defaultValue": "false"
196
234
  },
@@ -254,6 +292,11 @@ export class ChCheckbox {
254
292
  }
255
293
  };
256
294
  }
295
+ static get states() {
296
+ return {
297
+ "formDisabled": {}
298
+ };
299
+ }
257
300
  static get events() {
258
301
  return [{
259
302
  "method": "chChange",
@@ -272,5 +315,22 @@ export class ChCheckbox {
272
315
  }
273
316
  }];
274
317
  }
318
+ static get elementRef() { return "host"; }
319
+ static get watchers() {
320
+ return [{
321
+ "propName": "checked",
322
+ "methodName": "syncForm"
323
+ }, {
324
+ "propName": "required",
325
+ "methodName": "syncForm"
326
+ }, {
327
+ "propName": "invalid",
328
+ "methodName": "syncForm"
329
+ }, {
330
+ "propName": "errorMessage",
331
+ "methodName": "syncForm"
332
+ }];
333
+ }
334
+ static get attachInternalsMemberName() { return "internals"; }
275
335
  }
276
336
  //# sourceMappingURL=ch-checkbox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ch-checkbox.js","sourceRoot":"","sources":["../../../../src/components/ch-checkbox/ch-checkbox.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,eAAe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cesContent":["import { Component, Event, type EventEmitter, Host, Prop, h } from '@stencil/core';\n\nlet checkboxIds = 0;\n\n@Component({\n tag: 'ch-checkbox',\n styleUrl: 'ch-checkbox.css',\n shadow: true,\n})\nexport class ChCheckbox {\n private readonly checkboxId = `ch-checkbox-${++checkboxIds}`;\n private readonly hintId = `${this.checkboxId}-hint`;\n private readonly errorId = `${this.checkboxId}-error`;\n\n /**\n * Visible label rendered next to the checkbox, associated with it via\n * `for`/`id`, so assistive technology announces the checkbox's purpose.\n */\n @Prop() label?: string;\n\n /**\n * The name of the checkbox, submitted with form data.\n */\n @Prop() name?: string;\n\n /**\n * The value of the checkbox, submitted with form data.\n */\n @Prop() value = 'on';\n\n /**\n * Whether the checkbox is checked.\n */\n @Prop({ mutable: true }) checked = false;\n\n /**\n * Whether the checkbox is disabled.\n */\n @Prop() disabled = false;\n\n /**\n * Whether the checkbox is required.\n */\n @Prop() required = false;\n\n /**\n * Helper text rendered below the checkbox, associated via `aria-describedby`.\n * Replaced by `errorMessage` when the checkbox is invalid.\n */\n @Prop() hint?: string;\n\n /**\n * Error message rendered below the checkbox when it is invalid.\n */\n @Prop() errorMessage?: string;\n\n /**\n * Whether the checkbox is in an invalid state; toggles `aria-invalid` and error styling.\n */\n @Prop() invalid = false;\n\n /**\n * Emitted when the checked state changes, with the new checked value.\n */\n @Event() chChange: EventEmitter<boolean>;\n\n private handleChange = (ev: Event) => {\n this.checked = (ev.target as HTMLInputElement).checked;\n this.chChange.emit(this.checked);\n };\n\n private get describedBy(): string | undefined {\n if (this.invalid && this.errorMessage) {\n return this.errorId;\n }\n if (this.hint) {\n return this.hintId;\n }\n return undefined;\n }\n\n render() {\n return (\n <Host>\n <label class={{ 'control': true, 'control--disabled': this.disabled }} htmlFor={this.checkboxId}>\n <input\n id={this.checkboxId}\n class={{ 'input': true, 'input--invalid': this.invalid }}\n type=\"checkbox\"\n name={this.name}\n value={this.value}\n checked={this.checked}\n disabled={this.disabled}\n required={this.required}\n aria-invalid={this.invalid ? 'true' : undefined}\n aria-describedby={this.describedBy}\n onChange={this.handleChange}\n />\n {this.label && <span class=\"label-text\">{this.label}</span>}\n </label>\n {this.hint && !(this.invalid && this.errorMessage) && (\n <p class=\"hint\" id={this.hintId}>\n {this.hint}\n </p>\n )}\n {this.invalid && this.errorMessage && (\n <p class=\"error\" id={this.errorId} role=\"alert\">\n {this.errorMessage}\n </p>\n )}\n </Host>\n );\n }\n}\n"]}
1
+ {"version":3,"file":"ch-checkbox.js","sourceRoot":"","sources":["../../../../src/components/ch-checkbox/ch-checkbox.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAE3H,IAAI,WAAW,GAAG,CAAC,CAAC;AAQpB,MAAM,OAAO,UAAU;IACJ,UAAU,GAAG,eAAe,EAAE,WAAW,EAAE,CAAC;IAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,OAAO,CAAC;IACnC,OAAO,GAAG,GAAG,IAAI,CAAC,UAAU,QAAQ,CAAC;IAC9C,cAAc,GAAG,KAAK,CAAC;IAEZ,SAAS,CAAoB;IACvC,YAAY,GAAG,KAAK,CAAC;IACX,IAAI,CAAe;IAEtC;;;OAGG;IACK,KAAK,CAAU;IAEvB;;OAEG;IACsB,IAAI,CAAU;IAEvC;;OAEG;IACK,KAAK,GAAG,IAAI,CAAC;IAErB;;OAEG;IACsB,OAAO,GAAG,KAAK,CAAC;IAEzC;;OAEG;IACsB,QAAQ,GAAG,KAAK,CAAC;IAE1C;;OAEG;IACsB,QAAQ,GAAG,KAAK,CAAC;IAE1C;;;OAGG;IACK,IAAI,CAAU;IAEtB;;OAEG;IACK,YAAY,CAAU;IAE9B;;OAEG;IACK,OAAO,GAAG,KAAK,CAAC;IAExB;;OAEG;IACM,QAAQ,CAAwB;IAEjC,YAAY,GA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AAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,sBAC7B,IAAI,CAAC,WAAW,EAClC,QAAQ,EAAE,IAAI,CAAC,YAAY,GAC3B;gBACD,IAAI,CAAC,KAAK,IAAI,6DAAM,KAAK,EAAC,YAAY,IAAE,IAAI,CAAC,KAAK,CAAQ,CACrD;YACP,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,CACpD,0DAAG,KAAK,EAAC,MAAM,EAAC,EAAE,EAAE,IAAI,CAAC,MAAM,IAC5B,IAAI,CAAC,IAAI,CACR,CACL;YACA,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,IAAI,CACpC,0DAAG,KAAK,EAAC,OAAO,EAAC,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAC,OAAO,IAC5C,IAAI,CAAC,YAAY,CAChB,CACL,CACI,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { AttachInternals, Component, Element, Event, type EventEmitter, Host, Prop, State, Watch, h } from '@stencil/core';\n\nlet checkboxIds = 0;\n\n@Component({\n tag: 'ch-checkbox',\n styleUrl: 'ch-checkbox.css',\n shadow: true,\n formAssociated: true,\n})\nexport class ChCheckbox {\n private readonly checkboxId = `ch-checkbox-${++checkboxIds}`;\n private readonly hintId = `${this.checkboxId}-hint`;\n private readonly errorId = `${this.checkboxId}-error`;\n private initialChecked = false;\n\n @AttachInternals() internals!: ElementInternals;\n @State() formDisabled = false;\n @Element() private host!: HTMLElement;\n\n /**\n * Visible label rendered next to the checkbox, associated with it via\n * `for`/`id`, so assistive technology announces the checkbox's purpose.\n */\n @Prop() label?: string;\n\n /**\n * The name of the checkbox, submitted with form data.\n */\n @Prop({ reflect: true }) name?: string;\n\n /**\n * The value of the checkbox, submitted with form data.\n */\n @Prop() value = 'on';\n\n /**\n * Whether the checkbox is checked.\n */\n @Prop({ mutable: true }) checked = false;\n\n /**\n * Whether the checkbox is disabled.\n */\n @Prop({ reflect: true }) disabled = false;\n\n /**\n * Whether the checkbox is required.\n */\n @Prop({ reflect: true }) required = false;\n\n /**\n * Helper text rendered below the checkbox, associated via `aria-describedby`.\n * Replaced by `errorMessage` when the checkbox is invalid.\n */\n @Prop() hint?: string;\n\n /**\n * Error message rendered below the checkbox when it is invalid.\n */\n @Prop() errorMessage?: string;\n\n /**\n * Whether the checkbox is in an invalid state; toggles `aria-invalid` and error styling.\n */\n @Prop() invalid = false;\n\n /**\n * Emitted when the checked state changes, with the new checked value.\n */\n @Event() chChange: EventEmitter<boolean>;\n\n private handleChange = (ev: Event) => {\n this.checked = (ev.target as HTMLInputElement).checked;\n this.chChange.emit(this.checked);\n };\n\n @Watch('checked')\n @Watch('required')\n @Watch('invalid')\n @Watch('errorMessage')\n protected syncForm(): void {\n const internals = this.internals;\n if (typeof internals?.setFormValue !== 'function') {\n return;\n }\n internals.setFormValue(this.checked ? this.value : null);\n const flags: ValidityStateFlags = {};\n let message: string | undefined;\n if (this.required && !this.checked) {\n flags.valueMissing = true;\n }\n if (this.invalid && this.errorMessage) {\n flags.customError = true;\n }\n message = this.errorMessage ?? (flags.valueMissing ? 'Please fill out this field.' : undefined);\n internals.setValidity(flags, message);\n }\n\n componentDidLoad() {\n this.initialChecked = this.checked;\n this.syncForm();\n this.host.addEventListener('change', this.markTouched);\n this.host.addEventListener('focusout', this.markTouched);\n this.host.addEventListener('invalid', this.markTouched);\n }\n\n private markTouched = (): void => {\n this.host.setAttribute('data-touched', '');\n };\n\n formResetCallback(): void {\n this.checked = this.initialChecked;\n }\n\n formDisabledCallback(isDisabled: boolean): void {\n this.formDisabled = isDisabled;\n }\n\n private get describedBy(): string | undefined {\n if (this.invalid && this.errorMessage) {\n return this.errorId;\n }\n if (this.hint) {\n return this.hintId;\n }\n return undefined;\n }\n\n render() {\n return (\n <Host>\n <label class={{ 'control': true, 'control--disabled': this.disabled || this.formDisabled }} htmlFor={this.checkboxId}>\n <input\n id={this.checkboxId}\n class={{ 'input': true, 'input--invalid': this.invalid }}\n type=\"checkbox\"\n name={this.name}\n value={this.value}\n checked={this.checked}\n disabled={this.disabled || this.formDisabled}\n required={this.required}\n aria-invalid={this.invalid ? 'true' : undefined}\n aria-describedby={this.describedBy}\n onChange={this.handleChange}\n />\n {this.label && <span class=\"label-text\">{this.label}</span>}\n </label>\n {this.hint && !(this.invalid && this.errorMessage) && (\n <p class=\"hint\" id={this.hintId}>\n {this.hint}\n </p>\n )}\n {this.invalid && this.errorMessage && (\n <p class=\"error\" id={this.errorId} role=\"alert\">\n {this.errorMessage}\n </p>\n )}\n </Host>\n );\n }\n}\n"]}
@@ -46,6 +46,17 @@
46
46
  box-shadow: 0 0 0 3px var(--color-status-warning-background);
47
47
  }
48
48
 
49
+ :host([data-touched]:invalid) .input,
50
+ :host(:user-invalid) .input {
51
+ border-color: var(--color-status-warning);
52
+ }
53
+
54
+ :host([data-touched]:invalid) .input:focus,
55
+ :host(:user-invalid) .input:focus {
56
+ border-color: var(--color-status-warning);
57
+ box-shadow: 0 0 0 3px var(--color-status-warning-background);
58
+ }
59
+
49
60
  .input:disabled {
50
61
  opacity: var(--opacity-disabled);
51
62
  cursor: not-allowed;
@@ -4,6 +4,10 @@ export class ChInput {
4
4
  inputId = `ch-input-${++inputIds}`;
5
5
  hintId = `${this.inputId}-hint`;
6
6
  errorId = `${this.inputId}-error`;
7
+ initialValue = '';
8
+ internals;
9
+ formDisabled = false;
10
+ host;
7
11
  /**
8
12
  * Visible label rendered above the input and associated with it via
9
13
  * `for`/`id`, so assistive technology announces the input's purpose.
@@ -62,6 +66,39 @@ export class ChInput {
62
66
  this.value = ev.target.value;
63
67
  this.chChange.emit(this.value);
64
68
  };
69
+ syncForm() {
70
+ const internals = this.internals;
71
+ if (typeof internals?.setFormValue !== 'function') {
72
+ return;
73
+ }
74
+ internals.setFormValue(this.value);
75
+ const flags = {};
76
+ let message;
77
+ if (this.required && this.value === '') {
78
+ flags.valueMissing = true;
79
+ }
80
+ if (this.invalid && this.errorMessage) {
81
+ flags.customError = true;
82
+ }
83
+ message = this.errorMessage ?? (flags.valueMissing ? 'Please fill out this field.' : undefined);
84
+ internals.setValidity(flags, message);
85
+ }
86
+ componentDidLoad() {
87
+ this.initialValue = this.value;
88
+ this.syncForm();
89
+ this.host.addEventListener('change', this.markTouched);
90
+ this.host.addEventListener('focusout', this.markTouched);
91
+ this.host.addEventListener('invalid', this.markTouched);
92
+ }
93
+ markTouched = () => {
94
+ this.host.setAttribute('data-touched', '');
95
+ };
96
+ formResetCallback() {
97
+ this.value = this.initialValue;
98
+ }
99
+ formDisabledCallback(isDisabled) {
100
+ this.formDisabled = isDisabled;
101
+ }
65
102
  get describedBy() {
66
103
  if (this.invalid && this.errorMessage) {
67
104
  return this.errorId;
@@ -72,10 +109,11 @@ export class ChInput {
72
109
  return undefined;
73
110
  }
74
111
  render() {
75
- return (h(Host, { key: '56ef5eab354235c89214be28263cde91168f5dee' }, this.label && (h("label", { key: '745fe11f607591d1c571dcf7d9429d834dfa4f2b', class: "label", htmlFor: this.inputId }, this.label)), h("input", { key: '18739cebe47aa1130b55fa5aaf184a1f3fad88d2', id: this.label ? this.inputId : undefined, class: { 'input': true, 'input--invalid': this.invalid }, type: this.type, name: this.name, placeholder: this.placeholder, disabled: this.disabled, required: this.required, value: this.value, "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onInput: this.handleInput, onChange: this.handleChange }), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: '60a43287f6329db3f4b27ad882300fced0925645', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: 'ea18e90000f1a244cbe51126441b5d260562e07a', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
112
+ return (h(Host, { key: '8ac09d33deda0e98464108b77ef5e79ca1696e3f' }, this.label && (h("label", { key: 'e66ab373c5234c2fdacf6bbb796b42ed212c3fd8', class: "label", htmlFor: this.inputId }, this.label)), h("input", { key: 'ae23f4e30970287927f418aebd3b1f83be6d7738', id: this.label ? this.inputId : undefined, class: { 'input': true, 'input--invalid': this.invalid }, type: this.type, name: this.name, placeholder: this.placeholder, disabled: this.disabled || this.formDisabled, required: this.required, value: this.value, "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onInput: this.handleInput, onChange: this.handleChange }), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: '8a6ff789e40a0b3595a34c1e94c3d779d4169bf0', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: 'aa4c0d89748ad91d91f6483fcf9b3641b44ee864', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
76
113
  }
77
114
  static get is() { return "ch-input"; }
78
115
  static get encapsulation() { return "shadow"; }
116
+ static get formAssociated() { return true; }
79
117
  static get originalStyleUrls() {
80
118
  return {
81
119
  "$": ["ch-input.css"]
@@ -182,7 +220,7 @@ export class ChInput {
182
220
  },
183
221
  "getter": false,
184
222
  "setter": false,
185
- "reflect": false,
223
+ "reflect": true,
186
224
  "attribute": "name"
187
225
  },
188
226
  "disabled": {
@@ -201,7 +239,7 @@ export class ChInput {
201
239
  },
202
240
  "getter": false,
203
241
  "setter": false,
204
- "reflect": false,
242
+ "reflect": true,
205
243
  "attribute": "disabled",
206
244
  "defaultValue": "false"
207
245
  },
@@ -221,7 +259,7 @@ export class ChInput {
221
259
  },
222
260
  "getter": false,
223
261
  "setter": false,
224
- "reflect": false,
262
+ "reflect": true,
225
263
  "attribute": "required",
226
264
  "defaultValue": "false"
227
265
  },
@@ -285,6 +323,11 @@ export class ChInput {
285
323
  }
286
324
  };
287
325
  }
326
+ static get states() {
327
+ return {
328
+ "formDisabled": {}
329
+ };
330
+ }
288
331
  static get events() {
289
332
  return [{
290
333
  "method": "chInput",
@@ -318,5 +361,22 @@ export class ChInput {
318
361
  }
319
362
  }];
320
363
  }
364
+ static get elementRef() { return "host"; }
365
+ static get watchers() {
366
+ return [{
367
+ "propName": "value",
368
+ "methodName": "syncForm"
369
+ }, {
370
+ "propName": "required",
371
+ "methodName": "syncForm"
372
+ }, {
373
+ "propName": "invalid",
374
+ "methodName": "syncForm"
375
+ }, {
376
+ "propName": "errorMessage",
377
+ "methodName": "syncForm"
378
+ }];
379
+ }
380
+ static get attachInternalsMemberName() { return "internals"; }
321
381
  }
322
382
  //# sourceMappingURL=ch-input.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ch-input.js","sourceRoot":"","sources":["../../../../src/components/ch-input/ch-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAEnF,IAAI,QAAQ,GAAG,CAAC,CAAC;AAOjB,MAAM,OAAO,OAAO;IACD,OAAO,GAAG,YAAY,EAAE,QAAQ,EAAE,CAAC;IACnC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,OAAO,CAAC;IAChC,OAAO,GAAG,GAAG,IAAI,CAAC,OAAO,QAAQ,CAAC;IAEnD;;;OAGG;IACK,KAAK,CAAU;IAEvB;;OAEG;IACK,IAAI,GAAG,MAAM,CAAC;IAEtB;;OAEG;IACsB,KAAK,GAAG,EAAE,CAAC;IAEpC;;OAEG;IACK,WAAW,CAAU;IAE7B;;OAEG;IACK,IAAI,CAAU;IAEtB;;OAEG;IACK,QAAQ,GAAG,KAAK,CAAC;IAEzB;;OAEG;IACK,QAAQ,GAAG,KAAK,CAAC;IAEzB;;;OAGG;IACK,IAAI,CAAU;IAEt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AE,IAAI,CAAC,WAAW,EAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,KAAK,EAAE,IAAI,CAAC,KAAK,kBACH,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,sBAC7B,IAAI,CAAC,WAAW,EAClC,OAAO,EAAE,IAAI,CAAC,WAAW,EACzB,QAAQ,EAAE,IAAI,CAAC,YAAY,GAC3B;YACD,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,CACpD,0DAAG,KAAK,EAAC,MAAM,EAAC,EAAE,EAAE,IAAI,CAAC,MAAM,IAC5B,IAAI,CAAC,IAAI,CACR,CACL;YACA,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,IAAI,CACpC,0DAAG,KAAK,EAAC,OAAO,EAAC,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAC,OAAO,IAC5C,IAAI,CAAC,YAAY,CAChB,CACL,CACI,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Event, type EventEmitter, Host, Prop, h } from '@stencil/core';\n\nlet inputIds = 0;\n\n@Component({\n tag: 'ch-input',\n styleUrl: 'ch-input.css',\n shadow: true,\n})\nexport class ChInput {\n private readonly inputId = `ch-input-${++inputIds}`;\n private readonly hintId = `${this.inputId}-hint`;\n private readonly errorId = `${this.inputId}-error`;\n\n /**\n * Visible label rendered above the input and associated with it via\n * `for`/`id`, so assistive technology announces the input's purpose.\n */\n @Prop() label?: string;\n\n /**\n * The type of the input, mirroring the native `<input type>` attribute.\n */\n @Prop() type = 'text';\n\n /**\n * The value of the input.\n */\n @Prop({ mutable: true }) value = '';\n\n /**\n * Placeholder text shown when the input is empty.\n */\n @Prop() placeholder?: string;\n\n /**\n * The name of the input, submitted with form data.\n */\n @Prop() name?: string;\n\n /**\n * Whether the input is disabled.\n */\n @Prop() disabled = false;\n\n /**\n * Whether the input is required.\n */\n @Prop() required = false;\n\n /**\n * Helper text rendered below the input, associated via `aria-describedby`.\n * Replaced by `errorMessage` when the input is invalid.\n */\n @Prop() hint?: string;\n\n /**\n * Error message rendered below the input when it is invalid.\n */\n @Prop() errorMessage?: string;\n\n /**\n * Whether the input is in an invalid state; toggles `aria-invalid` and error styling.\n */\n @Prop() invalid = false;\n\n /**\n * Emitted on every keystroke, with the current input value.\n */\n @Event() chInput: EventEmitter<string>;\n\n /**\n * Emitted when the input value is committed (on native `change`).\n */\n @Event() chChange: EventEmitter<string>;\n\n private handleInput = (ev: InputEvent) => {\n this.value = (ev.target as HTMLInputElement).value;\n this.chInput.emit(this.value);\n };\n\n private handleChange = (ev: Event) => {\n this.value = (ev.target as HTMLInputElement).value;\n this.chChange.emit(this.value);\n };\n\n private get describedBy(): string | undefined {\n if (this.invalid && this.errorMessage) {\n return this.errorId;\n }\n if (this.hint) {\n return this.hintId;\n }\n return undefined;\n }\n\n render() {\n return (\n <Host>\n {this.label && (\n <label class=\"label\" htmlFor={this.inputId}>\n {this.label}\n </label>\n )}\n <input\n id={this.label ? this.inputId : undefined}\n class={{ 'input': true, 'input--invalid': this.invalid }}\n type={this.type}\n name={this.name}\n placeholder={this.placeholder}\n disabled={this.disabled}\n required={this.required}\n value={this.value}\n aria-invalid={this.invalid ? 'true' : undefined}\n aria-describedby={this.describedBy}\n onInput={this.handleInput}\n onChange={this.handleChange}\n />\n {this.hint && !(this.invalid && this.errorMessage) && (\n <p class=\"hint\" id={this.hintId}>\n {this.hint}\n </p>\n )}\n {this.invalid && this.errorMessage && (\n <p class=\"error\" id={this.errorId} role=\"alert\">\n {this.errorMessage}\n </p>\n )}\n </Host>\n );\n }\n}\n"]}
1
+ {"version":3,"file":"ch-input.js","sourceRoot":"","sources":["../../../../src/components/ch-input/ch-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAE3H,IAAI,QAAQ,GAAG,CAAC,CAAC;AAQjB,MAAM,OAAO,OAAO;IACD,OAAO,GAAG,YAAY,EAAE,QAAQ,EAAE,CAAC;IACnC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,OAAO,CAAC;IAChC,OAAO,GAAG,GAAG,IAAI,CAAC,OAAO,QAAQ,CAAC;IAC3C,YAAY,GAAG,EAAE,CAAC;IAEP,SAAS,CAAoB;IACvC,YAAY,GAAG,KAAK,CAAC;IACX,IAAI,CAAe;IAEtC;;;OAGG;IACK,KAAK,CAAU;IAEvB;;OAEG;IACK,IAAI,GAAG,MAAM,CAAC;IAEtB;;OAEG;IACsB,KAAK,GAAG,EAAE,CAAC;IAEpC;;OAEG;IACK,WAAW,CAAU;IAE7B;;OAEG;IACsB,IAAI,CAAU;IAEvC;;OAEG;IACsB,QAAQ,GAAG,KAAK,CAAC;IAE1C;;OAEG;IACsB,QAAQ,GAAG,KAAK,CAAC;IAE1C;;;OAGG;IACK,IAAI,CAAU;IAEtB;;OAEG;IACK,YAAY,CAAU;IAE9B;;OAEG;IACK,OAAO,GAAG,KAAK,CAAC;IAExB;;OAEG;IACM,OAAO,CAAuB;IAEvC;;OAEG;IACM,QAAQ,CAAuB;IAEhC,WAAW,GAAG,CAAC,EAAc,EAAE,EAAE;QACvC,IAAI,CAAC,KAAK,GAAI,EA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,IAAI,IAAI,CAAC,YAAY,EAC5C,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,KAAK,EAAE,IAAI,CAAC,KAAK,kBACH,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,sBAC7B,IAAI,CAAC,WAAW,EAClC,OAAO,EAAE,IAAI,CAAC,WAAW,EACzB,QAAQ,EAAE,IAAI,CAAC,YAAY,GAC3B;YACD,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,CACpD,0DAAG,KAAK,EAAC,MAAM,EAAC,EAAE,EAAE,IAAI,CAAC,MAAM,IAC5B,IAAI,CAAC,IAAI,CACR,CACL;YACA,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,IAAI,CACpC,0DAAG,KAAK,EAAC,OAAO,EAAC,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAC,OAAO,IAC5C,IAAI,CAAC,YAAY,CAChB,CACL,CACI,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { AttachInternals, Component, Element, Event, type EventEmitter, Host, Prop, State, Watch, h } from '@stencil/core';\n\nlet inputIds = 0;\n\n@Component({\n tag: 'ch-input',\n styleUrl: 'ch-input.css',\n shadow: true,\n formAssociated: true,\n})\nexport class ChInput {\n private readonly inputId = `ch-input-${++inputIds}`;\n private readonly hintId = `${this.inputId}-hint`;\n private readonly errorId = `${this.inputId}-error`;\n private initialValue = '';\n\n @AttachInternals() internals!: ElementInternals;\n @State() formDisabled = false;\n @Element() private host!: HTMLElement;\n\n /**\n * Visible label rendered above the input and associated with it via\n * `for`/`id`, so assistive technology announces the input's purpose.\n */\n @Prop() label?: string;\n\n /**\n * The type of the input, mirroring the native `<input type>` attribute.\n */\n @Prop() type = 'text';\n\n /**\n * The value of the input.\n */\n @Prop({ mutable: true }) value = '';\n\n /**\n * Placeholder text shown when the input is empty.\n */\n @Prop() placeholder?: string;\n\n /**\n * The name of the input, submitted with form data.\n */\n @Prop({ reflect: true }) name?: string;\n\n /**\n * Whether the input is disabled.\n */\n @Prop({ reflect: true }) disabled = false;\n\n /**\n * Whether the input is required.\n */\n @Prop({ reflect: true }) required = false;\n\n /**\n * Helper text rendered below the input, associated via `aria-describedby`.\n * Replaced by `errorMessage` when the input is invalid.\n */\n @Prop() hint?: string;\n\n /**\n * Error message rendered below the input when it is invalid.\n */\n @Prop() errorMessage?: string;\n\n /**\n * Whether the input is in an invalid state; toggles `aria-invalid` and error styling.\n */\n @Prop() invalid = false;\n\n /**\n * Emitted on every keystroke, with the current input value.\n */\n @Event() chInput: EventEmitter<string>;\n\n /**\n * Emitted when the input value is committed (on native `change`).\n */\n @Event() chChange: EventEmitter<string>;\n\n private handleInput = (ev: InputEvent) => {\n this.value = (ev.target as HTMLInputElement).value;\n this.chInput.emit(this.value);\n };\n\n private handleChange = (ev: Event) => {\n this.value = (ev.target as HTMLInputElement).value;\n this.chChange.emit(this.value);\n };\n\n @Watch('value')\n @Watch('required')\n @Watch('invalid')\n @Watch('errorMessage')\n protected syncForm(): void {\n const internals = this.internals;\n if (typeof internals?.setFormValue !== 'function') {\n return;\n }\n internals.setFormValue(this.value);\n const flags: ValidityStateFlags = {};\n let message: string | undefined;\n if (this.required && this.value === '') {\n flags.valueMissing = true;\n }\n if (this.invalid && this.errorMessage) {\n flags.customError = true;\n }\n message = this.errorMessage ?? (flags.valueMissing ? 'Please fill out this field.' : undefined);\n internals.setValidity(flags, message);\n }\n\n componentDidLoad() {\n this.initialValue = this.value;\n this.syncForm();\n this.host.addEventListener('change', this.markTouched);\n this.host.addEventListener('focusout', this.markTouched);\n this.host.addEventListener('invalid', this.markTouched);\n }\n\n private markTouched = (): void => {\n this.host.setAttribute('data-touched', '');\n };\n\n formResetCallback(): void {\n this.value = this.initialValue;\n }\n\n formDisabledCallback(isDisabled: boolean): void {\n this.formDisabled = isDisabled;\n }\n\n private get describedBy(): string | undefined {\n if (this.invalid && this.errorMessage) {\n return this.errorId;\n }\n if (this.hint) {\n return this.hintId;\n }\n return undefined;\n }\n\n render() {\n return (\n <Host>\n {this.label && (\n <label class=\"label\" htmlFor={this.inputId}>\n {this.label}\n </label>\n )}\n <input\n id={this.label ? this.inputId : undefined}\n class={{ 'input': true, 'input--invalid': this.invalid }}\n type={this.type}\n name={this.name}\n placeholder={this.placeholder}\n disabled={this.disabled || this.formDisabled}\n required={this.required}\n value={this.value}\n aria-invalid={this.invalid ? 'true' : undefined}\n aria-describedby={this.describedBy}\n onInput={this.handleInput}\n onChange={this.handleChange}\n />\n {this.hint && !(this.invalid && this.errorMessage) && (\n <p class=\"hint\" id={this.hintId}>\n {this.hint}\n </p>\n )}\n {this.invalid && this.errorMessage && (\n <p class=\"error\" id={this.errorId} role=\"alert\">\n {this.errorMessage}\n </p>\n )}\n </Host>\n );\n }\n}\n"]}
@@ -73,6 +73,16 @@
73
73
  outline-color: var(--color-status-warning);
74
74
  }
75
75
 
76
+ :host([data-touched]:invalid) .input,
77
+ :host(:user-invalid) .input {
78
+ border-color: var(--color-status-warning);
79
+ }
80
+
81
+ :host([data-touched]:invalid) .input:focus-visible,
82
+ :host(:user-invalid) .input:focus-visible {
83
+ outline-color: var(--color-status-warning);
84
+ }
85
+
76
86
  .label-text {
77
87
  color: var(--text);
78
88
  }
@@ -5,6 +5,10 @@ export class ChRadio {
5
5
  labelId = `${this.groupId}-label`;
6
6
  hintId = `${this.groupId}-hint`;
7
7
  errorId = `${this.groupId}-error`;
8
+ initialValue;
9
+ internals;
10
+ formDisabled = false;
11
+ host;
8
12
  /**
9
13
  * Visible label describing the radio group, associated with it via
10
14
  * `aria-labelledby`.
@@ -52,6 +56,39 @@ export class ChRadio {
52
56
  this.value = ev.target.value;
53
57
  this.chChange.emit(this.value);
54
58
  };
59
+ syncForm() {
60
+ const internals = this.internals;
61
+ if (typeof internals?.setFormValue !== 'function') {
62
+ return;
63
+ }
64
+ internals.setFormValue(this.value ?? null);
65
+ const flags = {};
66
+ let message;
67
+ if (this.required && !this.value) {
68
+ flags.valueMissing = true;
69
+ }
70
+ if (this.invalid && this.errorMessage) {
71
+ flags.customError = true;
72
+ }
73
+ message = this.errorMessage ?? (flags.valueMissing ? 'Please fill out this field.' : undefined);
74
+ internals.setValidity(flags, message);
75
+ }
76
+ componentDidLoad() {
77
+ this.initialValue = this.value;
78
+ this.syncForm();
79
+ this.host.addEventListener('change', this.markTouched);
80
+ this.host.addEventListener('focusout', this.markTouched);
81
+ this.host.addEventListener('invalid', this.markTouched);
82
+ }
83
+ markTouched = () => {
84
+ this.host.setAttribute('data-touched', '');
85
+ };
86
+ formResetCallback() {
87
+ this.value = this.initialValue;
88
+ }
89
+ formDisabledCallback(isDisabled) {
90
+ this.formDisabled = isDisabled;
91
+ }
55
92
  get describedBy() {
56
93
  if (this.invalid && this.errorMessage) {
57
94
  return this.errorId;
@@ -63,10 +100,11 @@ export class ChRadio {
63
100
  }
64
101
  render() {
65
102
  const groupName = this.name || `${this.groupId}-group`;
66
- return (h(Host, { key: '68ce563b4a03669b76ff3822705b1ff92c4c02f2' }, this.label && (h("span", { key: '1887f5b70a5bf9f049495d76588458181d3f7735', class: "group-label", id: this.labelId }, this.label)), h("div", { key: 'c38ee340f9527e16c5587f2309f91ea463bb7cad', class: "radio-group", role: "radiogroup", "aria-labelledby": this.label ? this.labelId : undefined }, this.options.map(option => (h("label", { class: { 'control': true, 'control--disabled': this.disabled || option.disabled } }, h("input", { class: { 'input': true, 'input--invalid': this.invalid }, type: "radio", name: groupName, value: option.value, checked: option.value === this.value, disabled: this.disabled || option.disabled, "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onChange: this.handleChange }), h("span", { class: "mark" }), h("span", { class: "label-text" }, option.label))))), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: 'ad60ce772279809ee334fc30182be1d0350d5586', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '316c911f9e1a29d17cc2d6b0e60ed35755420ae2', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
103
+ return (h(Host, { key: '1a2562301b8daf00c557764c7f4cdfd54e6e11ef' }, this.label && (h("span", { key: '873958acd3422069572031d59be22c06e3e705a6', class: "group-label", id: this.labelId }, this.label)), h("div", { key: '860c71f128b6fb84dce3c14d2086fd77cc1a4a1e', class: "radio-group", role: "radiogroup", "aria-labelledby": this.label ? this.labelId : undefined }, this.options.map(option => (h("label", { class: { 'control': true, 'control--disabled': this.disabled || this.formDisabled || option.disabled } }, h("input", { class: { 'input': true, 'input--invalid': this.invalid }, type: "radio", name: groupName, value: option.value, checked: option.value === this.value, disabled: this.disabled || this.formDisabled || option.disabled, "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onChange: this.handleChange }), h("span", { class: "mark" }), h("span", { class: "label-text" }, option.label))))), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: '2b358f659d1ef21b1e90ecb67c41d6a0054806e3', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '4e60f0303e42668c4532f076143a47daa216dff8', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
67
104
  }
68
105
  static get is() { return "ch-radio"; }
69
106
  static get encapsulation() { return "shadow"; }
107
+ static get formAssociated() { return true; }
70
108
  static get originalStyleUrls() {
71
109
  return {
72
110
  "$": ["ch-radio.css"]
@@ -157,7 +195,7 @@ export class ChRadio {
157
195
  },
158
196
  "getter": false,
159
197
  "setter": false,
160
- "reflect": false,
198
+ "reflect": true,
161
199
  "attribute": "name"
162
200
  },
163
201
  "disabled": {
@@ -176,7 +214,7 @@ export class ChRadio {
176
214
  },
177
215
  "getter": false,
178
216
  "setter": false,
179
- "reflect": false,
217
+ "reflect": true,
180
218
  "attribute": "disabled",
181
219
  "defaultValue": "false"
182
220
  },
@@ -196,7 +234,7 @@ export class ChRadio {
196
234
  },
197
235
  "getter": false,
198
236
  "setter": false,
199
- "reflect": false,
237
+ "reflect": true,
200
238
  "attribute": "required",
201
239
  "defaultValue": "false"
202
240
  },
@@ -260,6 +298,11 @@ export class ChRadio {
260
298
  }
261
299
  };
262
300
  }
301
+ static get states() {
302
+ return {
303
+ "formDisabled": {}
304
+ };
305
+ }
263
306
  static get events() {
264
307
  return [{
265
308
  "method": "chChange",
@@ -278,5 +321,22 @@ export class ChRadio {
278
321
  }
279
322
  }];
280
323
  }
324
+ static get elementRef() { return "host"; }
325
+ static get watchers() {
326
+ return [{
327
+ "propName": "value",
328
+ "methodName": "syncForm"
329
+ }, {
330
+ "propName": "required",
331
+ "methodName": "syncForm"
332
+ }, {
333
+ "propName": "invalid",
334
+ "methodName": "syncForm"
335
+ }, {
336
+ "propName": "errorMessage",
337
+ "methodName": "syncForm"
338
+ }];
339
+ }
340
+ static get attachInternalsMemberName() { return "internals"; }
281
341
  }
282
342
  //# sourceMappingURL=ch-radio.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ch-radio.js","sourceRoot":"","sources":["../../../../src/components/ch-radio/ch-radio.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAQnF,IAAI,QAAQ,GAAG,CAAC,CAAC;AAOjB,MAAM,OAAO,OAAO;IACD,OAAO,GAAG,YAAY,EAAE,QAAQ,EAAE,CAAC;IACnC,OAAO,GAAG,GAAG,IAAI,CAAC,OAAO,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Y,CAChB,CACL,CACI,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Event, type EventEmitter, Host, Prop, h } from '@stencil/core';\n\nexport interface ChRadioOption {\n label: string;\n value: string;\n disabled?: boolean;\n}\n\nlet radioIds = 0;\n\n@Component({\n tag: 'ch-radio',\n styleUrl: 'ch-radio.css',\n shadow: true,\n})\nexport class ChRadio {\n private readonly groupId = `ch-radio-${++radioIds}`;\n private readonly labelId = `${this.groupId}-label`;\n private readonly hintId = `${this.groupId}-hint`;\n private readonly errorId = `${this.groupId}-error`;\n\n /**\n * Visible label describing the radio group, associated with it via\n * `aria-labelledby`.\n */\n @Prop() label?: string;\n\n /**\n * The list of options rendered as radio inputs.\n */\n @Prop() options: ChRadioOption[] = [];\n\n /**\n * The value of the selected option.\n */\n @Prop({ mutable: true }) value?: string;\n\n /**\n * The name shared by all radio inputs in the group. Defaults to an\n * auto-generated group name so options are mutually exclusive out of the box.\n */\n @Prop() name?: string;\n\n /**\n * Whether all radios in the group are disabled.\n */\n @Prop() disabled = false;\n\n /**\n * Whether a value is required.\n */\n @Prop() required = false;\n\n /**\n * Helper text rendered below the radio group, associated via `aria-describedby`.\n * Replaced by `errorMessage` when the group is invalid.\n */\n @Prop() hint?: string;\n\n /**\n * Error message rendered below the radio group when it is invalid.\n */\n @Prop() errorMessage?: string;\n\n /**\n * Whether the radio group is in an invalid state; toggles `aria-invalid` and error styling.\n */\n @Prop() invalid = false;\n\n /**\n * Emitted when a new option is selected, with the selected value.\n */\n @Event() chChange: EventEmitter<string>;\n\n private handleChange = (ev: Event) => {\n this.value = (ev.target as HTMLInputElement).value;\n this.chChange.emit(this.value);\n };\n\n private get describedBy(): string | undefined {\n if (this.invalid && this.errorMessage) {\n return this.errorId;\n }\n if (this.hint) {\n return this.hintId;\n }\n return undefined;\n }\n\n render() {\n const groupName = this.name || `${this.groupId}-group`;\n return (\n <Host>\n {this.label && (\n <span class=\"group-label\" id={this.labelId}>\n {this.label}\n </span>\n )}\n <div class=\"radio-group\" role=\"radiogroup\" aria-labelledby={this.label ? this.labelId : undefined}>\n {this.options.map(option => (\n <label class={{ 'control': true, 'control--disabled': this.disabled || option.disabled }}>\n <input\n class={{ 'input': true, 'input--invalid': this.invalid }}\n type=\"radio\"\n name={groupName}\n value={option.value}\n checked={option.value === this.value}\n disabled={this.disabled || option.disabled}\n aria-invalid={this.invalid ? 'true' : undefined}\n aria-describedby={this.describedBy}\n onChange={this.handleChange}\n />\n <span class=\"mark\"></span>\n <span class=\"label-text\">{option.label}</span>\n </label>\n ))}\n </div>\n {this.hint && !(this.invalid && this.errorMessage) && (\n <p class=\"hint\" id={this.hintId}>\n {this.hint}\n </p>\n )}\n {this.invalid && this.errorMessage && (\n <p class=\"error\" id={this.errorId} role=\"alert\">\n {this.errorMessage}\n </p>\n )}\n </Host>\n );\n }\n}\n"]}
1
+ {"version":3,"file":"ch-radio.js","sourceRoot":"","sources":["../../../../src/components/ch-radio/ch-radio.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAQ3H,IAAI,QAAQ,GAAG,CAAC,CAAC;AAQjB,MAAM,OAAO,OAAO;IACD,OAAO,GAAG,YAAY,EAAE,QAAQ,EAAE,CAAC;IACnC,OAAO,GAAG,GAAG,IAAI,CAAC,OAAO,QAAQ,CAAC;IAClC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,OAAO,CAAC;I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E,EAAE,IAAI,CAAC,MAAM,IAC5B,IAAI,CAAC,IAAI,CACR,CACL;YACA,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,IAAI,CACpC,0DAAG,KAAK,EAAC,OAAO,EAAC,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAC,OAAO,IAC5C,IAAI,CAAC,YAAY,CAChB,CACL,CACI,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { AttachInternals, Component, Element, Event, type EventEmitter, Host, Prop, State, Watch, h } from '@stencil/core';\n\nexport interface ChRadioOption {\n label: string;\n value: string;\n disabled?: boolean;\n}\n\nlet radioIds = 0;\n\n@Component({\n tag: 'ch-radio',\n styleUrl: 'ch-radio.css',\n shadow: true,\n formAssociated: true,\n})\nexport class ChRadio {\n private readonly groupId = `ch-radio-${++radioIds}`;\n private readonly labelId = `${this.groupId}-label`;\n private readonly hintId = `${this.groupId}-hint`;\n private readonly errorId = `${this.groupId}-error`;\n private initialValue: string | undefined;\n\n @AttachInternals() internals!: ElementInternals;\n @State() formDisabled = false;\n @Element() private host!: HTMLElement;\n\n /**\n * Visible label describing the radio group, associated with it via\n * `aria-labelledby`.\n */\n @Prop() label?: string;\n\n /**\n * The list of options rendered as radio inputs.\n */\n @Prop() options: ChRadioOption[] = [];\n\n /**\n * The value of the selected option.\n */\n @Prop({ mutable: true }) value?: string;\n\n /**\n * The name shared by all radio inputs in the group. Defaults to an\n * auto-generated group name so options are mutually exclusive out of the box.\n */\n @Prop({ reflect: true }) name?: string;\n\n /**\n * Whether all radios in the group are disabled.\n */\n @Prop({ reflect: true }) disabled = false;\n\n /**\n * Whether a value is required.\n */\n @Prop({ reflect: true }) required = false;\n\n /**\n * Helper text rendered below the radio group, associated via `aria-describedby`.\n * Replaced by `errorMessage` when the group is invalid.\n */\n @Prop() hint?: string;\n\n /**\n * Error message rendered below the radio group when it is invalid.\n */\n @Prop() errorMessage?: string;\n\n /**\n * Whether the radio group is in an invalid state; toggles `aria-invalid` and error styling.\n */\n @Prop() invalid = false;\n\n /**\n * Emitted when a new option is selected, with the selected value.\n */\n @Event() chChange: EventEmitter<string>;\n\n private handleChange = (ev: Event) => {\n this.value = (ev.target as HTMLInputElement).value;\n this.chChange.emit(this.value);\n };\n\n @Watch('value')\n @Watch('required')\n @Watch('invalid')\n @Watch('errorMessage')\n protected syncForm(): void {\n const internals = this.internals;\n if (typeof internals?.setFormValue !== 'function') {\n return;\n }\n internals.setFormValue(this.value ?? null);\n const flags: ValidityStateFlags = {};\n let message: string | undefined;\n if (this.required && !this.value) {\n flags.valueMissing = true;\n }\n if (this.invalid && this.errorMessage) {\n flags.customError = true;\n }\n message = this.errorMessage ?? (flags.valueMissing ? 'Please fill out this field.' : undefined);\n internals.setValidity(flags, message);\n }\n\n componentDidLoad() {\n this.initialValue = this.value;\n this.syncForm();\n this.host.addEventListener('change', this.markTouched);\n this.host.addEventListener('focusout', this.markTouched);\n this.host.addEventListener('invalid', this.markTouched);\n }\n\n private markTouched = (): void => {\n this.host.setAttribute('data-touched', '');\n };\n\n formResetCallback(): void {\n this.value = this.initialValue;\n }\n\n formDisabledCallback(isDisabled: boolean): void {\n this.formDisabled = isDisabled;\n }\n\n private get describedBy(): string | undefined {\n if (this.invalid && this.errorMessage) {\n return this.errorId;\n }\n if (this.hint) {\n return this.hintId;\n }\n return undefined;\n }\n\n render() {\n const groupName = this.name || `${this.groupId}-group`;\n return (\n <Host>\n {this.label && (\n <span class=\"group-label\" id={this.labelId}>\n {this.label}\n </span>\n )}\n <div class=\"radio-group\" role=\"radiogroup\" aria-labelledby={this.label ? this.labelId : undefined}>\n {this.options.map(option => (\n <label class={{ 'control': true, 'control--disabled': this.disabled || this.formDisabled || option.disabled }}>\n <input\n class={{ 'input': true, 'input--invalid': this.invalid }}\n type=\"radio\"\n name={groupName}\n value={option.value}\n checked={option.value === this.value}\n disabled={this.disabled || this.formDisabled || option.disabled}\n aria-invalid={this.invalid ? 'true' : undefined}\n aria-describedby={this.describedBy}\n onChange={this.handleChange}\n />\n <span class=\"mark\"></span>\n <span class=\"label-text\">{option.label}</span>\n </label>\n ))}\n </div>\n {this.hint && !(this.invalid && this.errorMessage) && (\n <p class=\"hint\" id={this.hintId}>\n {this.hint}\n </p>\n )}\n {this.invalid && this.errorMessage && (\n <p class=\"error\" id={this.errorId} role=\"alert\">\n {this.errorMessage}\n </p>\n )}\n </Host>\n );\n }\n}\n"]}
@@ -43,6 +43,17 @@
43
43
  box-shadow: 0 0 0 3px var(--color-status-warning-background);
44
44
  }
45
45
 
46
+ :host([data-touched]:invalid) .select,
47
+ :host(:user-invalid) .select {
48
+ border-color: var(--color-status-warning);
49
+ }
50
+
51
+ :host([data-touched]:invalid) .select:focus,
52
+ :host(:user-invalid) .select:focus {
53
+ border-color: var(--color-status-warning);
54
+ box-shadow: 0 0 0 3px var(--color-status-warning-background);
55
+ }
56
+
46
57
  .select:disabled {
47
58
  opacity: var(--opacity-disabled);
48
59
  cursor: not-allowed;