@italia/globals 0.1.0-alpha.2 → 1.0.0-alpha.5

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 (32) hide show
  1. package/custom-elements.json +348 -8
  2. package/dist/src/base-component/base-component.d.ts +19 -7
  3. package/dist/src/base-component/base-component.d.ts.map +1 -1
  4. package/dist/src/controllers/focus-trap-controller.d.ts +72 -0
  5. package/dist/src/controllers/focus-trap-controller.d.ts.map +1 -0
  6. package/dist/src/controllers/focus-trap-controller.js +271 -0
  7. package/dist/src/controllers/focus-trap-controller.js.map +1 -0
  8. package/dist/src/form/form-control.d.ts +2 -1
  9. package/dist/src/form/form-control.d.ts.map +1 -1
  10. package/dist/src/form/form-control.js +15 -7
  11. package/dist/src/form/form-control.js.map +1 -1
  12. package/dist/src/form/form-controller.d.ts +2 -0
  13. package/dist/src/form/form-controller.d.ts.map +1 -1
  14. package/dist/src/form/form-controller.js +35 -1
  15. package/dist/src/form/form-controller.js.map +1 -1
  16. package/dist/src/form/locales/it.d.ts.map +1 -1
  17. package/dist/src/form/locales/it.js +1 -0
  18. package/dist/src/form/locales/it.js.map +1 -1
  19. package/dist/src/index.d.ts +8 -0
  20. package/dist/src/index.d.ts.map +1 -1
  21. package/dist/src/index.js +8 -0
  22. package/dist/src/index.js.map +1 -1
  23. package/dist/src/mixins/validity.d.ts +18 -6
  24. package/dist/src/mixins/validity.d.ts.map +1 -1
  25. package/dist/src/stories/formControlReusableStories.d.ts.map +1 -1
  26. package/dist/src/stories/formControlReusableStories.js +5 -4
  27. package/dist/src/stories/formControlReusableStories.js.map +1 -1
  28. package/dist/src/window-manager.d.ts +13 -0
  29. package/dist/src/window-manager.d.ts.map +1 -1
  30. package/dist/src/window-manager.js +31 -0
  31. package/dist/src/window-manager.js.map +1 -1
  32. package/package.json +2 -2
@@ -0,0 +1,271 @@
1
+ /**
2
+ * Controller per gestire il focus trap all'interno di un elemento.
3
+ * Implementa le linee guida WAI-ARIA per i dialog modali.
4
+ *
5
+
6
+ * ```
7
+ */
8
+ export class FocusTrapController {
9
+ /**
10
+ * Verifica se un elemento è effettivamente focusabile e tabbabile.
11
+ * Elementi con tabindex="-1" sono focusabili programmaticamente ma non tabbabili.
12
+ */
13
+ static isFocusable(el) {
14
+ if (typeof el.focus !== 'function')
15
+ return false;
16
+ // Escludi elementi disabilitati
17
+ if (el.hasAttribute('disabled'))
18
+ return false;
19
+ // Escludi elementi con tabindex negativo (focusabili programmaticamente ma non tabbabili)
20
+ const tabindex = el.getAttribute('tabindex');
21
+ if (tabindex && parseInt(tabindex, 10) < 0) {
22
+ return false;
23
+ }
24
+ // Per custom elements (it-*), controlla anche il loro tabindex
25
+ if (el.tagName.toLowerCase().startsWith('it-')) {
26
+ // Se ha tabindex esplicito negativo, non è tabbabile
27
+ if (tabindex && parseInt(tabindex, 10) < 0) {
28
+ return false;
29
+ }
30
+ return true;
31
+ }
32
+ // Per elementi standard, controlliamo anche visibilità in modo robusto.
33
+ // Alcuni elementi (es. inline anchors, elementi dentro container positionati) possono
34
+ // avere offsetParent === null pur essendo visibili/focusabili. Usiamo quindi getClientRects
35
+ // e computedStyle come controllo più affidabile.
36
+ try {
37
+ // Se non ci sono bounding rects, probabilmente non è visibile
38
+ if (el.getClientRects()?.length === 0)
39
+ return false;
40
+ const style = window.getComputedStyle(el);
41
+ if (!style)
42
+ return false;
43
+ if (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0')
44
+ return false;
45
+ // Altrimenti consideriamo l'elemento focusabile
46
+ return true;
47
+ }
48
+ catch (e) {
49
+ return false;
50
+ }
51
+ }
52
+ constructor(host, config) {
53
+ this.observer = null;
54
+ this._isActive = false;
55
+ this._previousActiveElement = null;
56
+ this._focusableElements = [];
57
+ this._handleKeyDown = (event) => {
58
+ if (!this._isActive)
59
+ return;
60
+ switch (event.key) {
61
+ case 'Escape':
62
+ if (!this.config.disableEscape && this.config.onEscape) {
63
+ event.preventDefault();
64
+ this.config.onEscape();
65
+ }
66
+ break;
67
+ case 'Tab':
68
+ this._handleTab(event);
69
+ break;
70
+ default:
71
+ break;
72
+ }
73
+ };
74
+ this.host = host;
75
+ this.config = config;
76
+ this.host.addController(this);
77
+ }
78
+ // eslint-disable-next-line class-methods-use-this
79
+ hostConnected() {
80
+ // Controller ready
81
+ // Set up our MutationObserver
82
+ const observerOptions = {
83
+ childList: true,
84
+ attributes: true,
85
+ subtree: true,
86
+ };
87
+ this.observer = new MutationObserver(this.updateFocusableElements.bind(this));
88
+ this.observer.observe(this.host, observerOptions);
89
+ }
90
+ hostDisconnected() {
91
+ this.deactivate();
92
+ if (this.observer) {
93
+ this.observer.disconnect();
94
+ this.observer = null;
95
+ }
96
+ }
97
+ /** Indica se il focus trap è attivo */
98
+ get isActive() {
99
+ return this._isActive;
100
+ }
101
+ /**
102
+ * Attiva il focus trap.
103
+ * Salva l'elemento attivo corrente e attiva i listener.
104
+ * NOTA: chiamare updateFocusableElements() e focusFirst() separatamente quando necessario.
105
+ */
106
+ activate() {
107
+ if (this._isActive)
108
+ return;
109
+ this._isActive = true;
110
+ this._previousActiveElement = FocusTrapController.getActiveElement();
111
+ this.host.addEventListener('keydown', this._handleKeyDown);
112
+ this.updateFocusableElements();
113
+ if (typeof this.focusInitial === 'function')
114
+ this.focusInitial();
115
+ else
116
+ this.focusFirst();
117
+ }
118
+ /**
119
+ * Disattiva il focus trap.
120
+ * Ripristina il focus all'elemento precedentemente attivo.
121
+ */
122
+ deactivate() {
123
+ if (!this._isActive)
124
+ return;
125
+ this._isActive = false;
126
+ this.host.removeEventListener('keydown', this._handleKeyDown);
127
+ this._restoreFocus();
128
+ }
129
+ /**
130
+ * Aggiorna la lista degli elementi focusabili.
131
+ * Chiamare dopo modifiche al DOM.
132
+ */
133
+ updateFocusableElements() {
134
+ const container = this.config.getContainer();
135
+ const trigger = this.config.getTrigger();
136
+ if (!container) {
137
+ this._focusableElements = [];
138
+ this._first = undefined;
139
+ this._last = undefined;
140
+ return;
141
+ }
142
+ const candidates = [];
143
+ // Tutti gli elementi focusable direttamente nel container
144
+ const direct = Array.from(container.querySelectorAll(FocusTrapController.FOCUSABLE_SELECTORS));
145
+ candidates.push(...direct);
146
+ // Tutti gli elementi slottati
147
+ const slots = Array.from(container.querySelectorAll('slot'));
148
+ slots.forEach((slot) => {
149
+ slot.assignedElements({ flatten: true }).forEach((el) => {
150
+ if (!(el instanceof HTMLElement))
151
+ return;
152
+ if (el === trigger) {
153
+ return;
154
+ }
155
+ // focusable diretto
156
+ if (el.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {
157
+ candidates.push(el);
158
+ }
159
+ // nested focusable dentro l'elemento assegnato
160
+ Array.from(el.querySelectorAll(FocusTrapController.FOCUSABLE_SELECTORS)).forEach((nested) => candidates.push(nested));
161
+ });
162
+ });
163
+ // Filtra solo elementi veramente focusabili e rimuovi duplicati
164
+ this._focusableElements = Array.from(new Set(candidates)).filter((el) => {
165
+ // Escludi esplicitamente il container/dialog stesso
166
+ if (el === this.config.getContainer())
167
+ return false;
168
+ return FocusTrapController.isFocusable(el);
169
+ });
170
+ // Aggiorna primo/ultimo
171
+ this._first = this._focusableElements?.[0];
172
+ this._last = this._focusableElements[this._focusableElements.length - 1];
173
+ }
174
+ /** Sposta il focus sul primo elemento focusabile */
175
+ focusFirst() {
176
+ if (this._first) {
177
+ this._first.focus();
178
+ }
179
+ }
180
+ /** Sposta il focus sull'ultimo elemento focusabile */
181
+ focusLast() {
182
+ if (this._last) {
183
+ this._last.focus();
184
+ }
185
+ }
186
+ /** Ritorna l'elemento attivo corrente, attraversando shadow DOM e slot */
187
+ static getActiveElement() {
188
+ let active = document.activeElement;
189
+ while (active && active.shadowRoot && active.shadowRoot.activeElement) {
190
+ active = active.shadowRoot.activeElement;
191
+ }
192
+ return active;
193
+ }
194
+ /**
195
+ * Metti a fuoco l'elemento iniziale specificato nella config, se presente.
196
+ * Se non è fornito, fallback sul primo elemento tabbabile.
197
+ */
198
+ focusInitial() {
199
+ if (this.config.initialFocus) {
200
+ const el = this.config.initialFocus();
201
+ if (el && typeof el.focus === 'function') {
202
+ el.focus();
203
+ return;
204
+ }
205
+ }
206
+ this.focusFirst();
207
+ }
208
+ _handleTab(event) {
209
+ if (this._focusableElements.length === 0) {
210
+ event.preventDefault();
211
+ return;
212
+ }
213
+ // SEMPRE previeni il default - gestiamo noi la navigazione
214
+ event.preventDefault();
215
+ const firstElement = this._first;
216
+ const lastElement = this._last;
217
+ const activeElement = FocusTrapController.getActiveElement();
218
+ // Trova l'indice dell'elemento attivo
219
+ // Se activeElement è dentro uno shadow DOM di un custom element,
220
+ // cerca il custom element host nella lista
221
+ let currentIndex = this._focusableElements.indexOf(activeElement);
222
+ // Se non trovato, potrebbe essere un elemento interno ad un custom element
223
+ if (currentIndex === -1 && activeElement) {
224
+ // Risali attraverso gli shadow host
225
+ let parent = activeElement.getRootNode()?.host;
226
+ while (parent && currentIndex === -1) {
227
+ currentIndex = this._focusableElements.indexOf(parent);
228
+ if (currentIndex === -1) {
229
+ parent = parent.getRootNode()?.host;
230
+ }
231
+ }
232
+ }
233
+ if (event.shiftKey) {
234
+ // Shift + Tab: vai al precedente
235
+ if (currentIndex <= 0) {
236
+ // Se sei sul primo o non sei nella lista, vai all'ultimo
237
+ lastElement?.focus();
238
+ }
239
+ else {
240
+ // Vai al precedente
241
+ this._focusableElements[currentIndex - 1]?.focus();
242
+ }
243
+ }
244
+ else if (currentIndex === -1 || currentIndex >= this._focusableElements.length - 1) {
245
+ // Tab: se non sei nella lista o sei sull'ultimo, vai al primo
246
+ firstElement?.focus();
247
+ }
248
+ else {
249
+ // Vai al successivo
250
+ this._focusableElements[currentIndex + 1]?.focus();
251
+ }
252
+ }
253
+ _restoreFocus() {
254
+ if (this._previousActiveElement && typeof this._previousActiveElement.focus === 'function') {
255
+ this._previousActiveElement.focus();
256
+ }
257
+ this._previousActiveElement = null;
258
+ }
259
+ }
260
+ FocusTrapController.FOCUSABLE_SELECTORS = [
261
+ 'a[href]',
262
+ 'button:not([disabled])',
263
+ 'textarea:not([disabled])',
264
+ 'input:not([disabled]):not([type="hidden"])',
265
+ 'select:not([disabled])',
266
+ '[tabindex]',
267
+ // '[role="dialog"]',
268
+ // Custom elements focusabili
269
+ 'it-button:not([disabled])',
270
+ ].join(',');
271
+ //# sourceMappingURL=focus-trap-controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus-trap-controller.js","sourceRoot":"","sources":["../../../src/controllers/focus-trap-controller.ts"],"names":[],"mappings":"AAeA;;;;;;GAMG;AACH,MAAM,OAAO,mBAAmB;IA6B9B;;;OAGG;IACK,MAAM,CAAC,WAAW,CAAC,EAAe;QACxC,IAAI,OAAO,EAAE,CAAC,KAAK,KAAK,UAAU;YAAE,OAAO,KAAK,CAAC;QAEjD,gCAAgC;QAChC,IAAI,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC;YAAE,OAAO,KAAK,CAAC;QAE9C,0FAA0F;QAC1F,MAAM,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QAC7C,IAAI,QAAQ,IAAI,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3C,OAAO,KAAK,CAAC;QACf,CAAC;QAED,+DAA+D;QAC/D,IAAI,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/C,qDAAqD;YACrD,IAAI,QAAQ,IAAI,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC3C,OAAO,KAAK,CAAC;YACf,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,wEAAwE;QACxE,sFAAsF;QACtF,4FAA4F;QAC5F,iDAAiD;QACjD,IAAI,CAAC;YACH,8DAA8D;YAC9D,IAAI,EAAE,CAAC,cAAc,EAAE,EAAE,MAAM,KAAK,CAAC;gBAAE,OAAO,KAAK,CAA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from 'lit';\n\nexport interface FocusTrapConfig {\n /** Funzione che ritorna l'elemento contenitore del trap */\n getContainer: () => HTMLElement | ShadowRoot | null;\n /** Funzione che ritorna l'elemento trigger che ha attivato il focus trap */\n getTrigger: () => HTMLElement | ShadowRoot | null;\n /** Opzionale: funzione che ritorna l'elemento da mettere a fuoco all'apertura (può essere tabindex -1) */\n initialFocus?: () => HTMLElement | null;\n /** Callback quando viene premuto Escape */\n onEscape?: () => void;\n /** Se true, non chiude con Escape */\n disableEscape?: boolean;\n}\n\n/**\n * Controller per gestire il focus trap all'interno di un elemento.\n * Implementa le linee guida WAI-ARIA per i dialog modali.\n *\n\n * ```\n */\nexport class FocusTrapController implements ReactiveController {\n private host: ReactiveControllerHost & HTMLElement;\n\n private config: FocusTrapConfig;\n\n private observer: MutationObserver | null = null;\n\n private _isActive = false;\n\n private _previousActiveElement: HTMLElement | null = null;\n\n private _focusableElements: any[] = [];\n\n private _first: any;\n\n private _last: any;\n\n private static readonly FOCUSABLE_SELECTORS = [\n 'a[href]',\n 'button:not([disabled])',\n 'textarea:not([disabled])',\n 'input:not([disabled]):not([type=\"hidden\"])',\n 'select:not([disabled])',\n '[tabindex]',\n // '[role=\"dialog\"]',\n // Custom elements focusabili\n 'it-button:not([disabled])',\n ].join(',');\n\n /**\n * Verifica se un elemento è effettivamente focusabile e tabbabile.\n * Elementi con tabindex=\"-1\" sono focusabili programmaticamente ma non tabbabili.\n */\n private static isFocusable(el: HTMLElement): boolean {\n if (typeof el.focus !== 'function') return false;\n\n // Escludi elementi disabilitati\n if (el.hasAttribute('disabled')) return false;\n\n // Escludi elementi con tabindex negativo (focusabili programmaticamente ma non tabbabili)\n const tabindex = el.getAttribute('tabindex');\n if (tabindex && parseInt(tabindex, 10) < 0) {\n return false;\n }\n\n // Per custom elements (it-*), controlla anche il loro tabindex\n if (el.tagName.toLowerCase().startsWith('it-')) {\n // Se ha tabindex esplicito negativo, non è tabbabile\n if (tabindex && parseInt(tabindex, 10) < 0) {\n return false;\n }\n return true;\n }\n\n // Per elementi standard, controlliamo anche visibilità in modo robusto.\n // Alcuni elementi (es. inline anchors, elementi dentro container positionati) possono\n // avere offsetParent === null pur essendo visibili/focusabili. Usiamo quindi getClientRects\n // e computedStyle come controllo più affidabile.\n try {\n // Se non ci sono bounding rects, probabilmente non è visibile\n if (el.getClientRects()?.length === 0) return false;\n\n const style = window.getComputedStyle(el);\n if (!style) return false;\n if (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0') return false;\n\n // Altrimenti consideriamo l'elemento focusabile\n return true;\n } catch (e) {\n return false;\n }\n }\n\n constructor(host: ReactiveControllerHost & HTMLElement, config: FocusTrapConfig) {\n this.host = host;\n this.config = config;\n this.host.addController(this);\n }\n\n // eslint-disable-next-line class-methods-use-this\n hostConnected() {\n // Controller ready\n // Set up our MutationObserver\n const observerOptions = {\n childList: true,\n attributes: true,\n subtree: true,\n };\n this.observer = new MutationObserver(this.updateFocusableElements.bind(this));\n this.observer.observe(this.host, observerOptions);\n }\n\n hostDisconnected() {\n this.deactivate();\n if (this.observer) {\n this.observer.disconnect();\n this.observer = null;\n }\n }\n\n /** Indica se il focus trap è attivo */\n get isActive(): boolean {\n return this._isActive;\n }\n\n /**\n * Attiva il focus trap.\n * Salva l'elemento attivo corrente e attiva i listener.\n * NOTA: chiamare updateFocusableElements() e focusFirst() separatamente quando necessario.\n */\n activate(): void {\n if (this._isActive) return;\n\n this._isActive = true;\n this._previousActiveElement = FocusTrapController.getActiveElement();\n\n this.host.addEventListener('keydown', this._handleKeyDown);\n this.updateFocusableElements();\n if (typeof this.focusInitial === 'function') this.focusInitial();\n else this.focusFirst();\n }\n\n /**\n * Disattiva il focus trap.\n * Ripristina il focus all'elemento precedentemente attivo.\n */\n deactivate(): void {\n if (!this._isActive) return;\n\n this._isActive = false;\n this.host.removeEventListener('keydown', this._handleKeyDown);\n this._restoreFocus();\n }\n\n /**\n * Aggiorna la lista degli elementi focusabili.\n * Chiamare dopo modifiche al DOM.\n */\n updateFocusableElements(): void {\n const container = this.config.getContainer();\n const trigger = this.config.getTrigger();\n if (!container) {\n this._focusableElements = [];\n this._first = undefined;\n this._last = undefined;\n return;\n }\n\n const candidates: HTMLElement[] = [];\n\n // Tutti gli elementi focusable direttamente nel container\n const direct = Array.from(container.querySelectorAll<HTMLElement>(FocusTrapController.FOCUSABLE_SELECTORS));\n candidates.push(...direct);\n\n // Tutti gli elementi slottati\n const slots = Array.from(container.querySelectorAll('slot'));\n slots.forEach((slot) => {\n slot.assignedElements({ flatten: true }).forEach((el) => {\n if (!(el instanceof HTMLElement)) return;\n if (el === trigger) {\n return;\n }\n // focusable diretto\n if (el.matches(FocusTrapController.FOCUSABLE_SELECTORS)) {\n candidates.push(el);\n }\n\n // nested focusable dentro l'elemento assegnato\n Array.from(el.querySelectorAll<HTMLElement>(FocusTrapController.FOCUSABLE_SELECTORS)).forEach((nested) =>\n candidates.push(nested),\n );\n });\n });\n // Filtra solo elementi veramente focusabili e rimuovi duplicati\n this._focusableElements = Array.from(new Set(candidates)).filter((el) => {\n // Escludi esplicitamente il container/dialog stesso\n if (el === this.config.getContainer()) return false;\n return FocusTrapController.isFocusable(el);\n });\n\n // Aggiorna primo/ultimo\n this._first = this._focusableElements?.[0];\n this._last = this._focusableElements[this._focusableElements.length - 1];\n }\n\n /** Sposta il focus sul primo elemento focusabile */\n focusFirst(): void {\n if (this._first) {\n this._first.focus();\n }\n }\n\n /** Sposta il focus sull'ultimo elemento focusabile */\n focusLast(): void {\n if (this._last) {\n this._last.focus();\n }\n }\n\n /** Ritorna l'elemento attivo corrente, attraversando shadow DOM e slot */\n static getActiveElement(): HTMLElement | null {\n let active = document.activeElement;\n while (active && active.shadowRoot && active.shadowRoot.activeElement) {\n active = active.shadowRoot.activeElement;\n }\n return active as HTMLElement | null;\n }\n\n /**\n * Metti a fuoco l'elemento iniziale specificato nella config, se presente.\n * Se non è fornito, fallback sul primo elemento tabbabile.\n */\n focusInitial(): void {\n if (this.config.initialFocus) {\n const el = this.config.initialFocus();\n if (el && typeof el.focus === 'function') {\n el.focus();\n return;\n }\n }\n\n this.focusFirst();\n }\n\n private _handleKeyDown = (event: KeyboardEvent): void => {\n if (!this._isActive) return;\n\n switch (event.key) {\n case 'Escape':\n if (!this.config.disableEscape && this.config.onEscape) {\n event.preventDefault();\n this.config.onEscape();\n }\n break;\n case 'Tab':\n this._handleTab(event);\n break;\n default:\n break;\n }\n };\n\n private _handleTab(event: KeyboardEvent): void {\n if (this._focusableElements.length === 0) {\n event.preventDefault();\n return;\n }\n\n // SEMPRE previeni il default - gestiamo noi la navigazione\n event.preventDefault();\n\n const firstElement = this._first;\n const lastElement = this._last;\n const activeElement = FocusTrapController.getActiveElement();\n\n // Trova l'indice dell'elemento attivo\n // Se activeElement è dentro uno shadow DOM di un custom element,\n // cerca il custom element host nella lista\n let currentIndex = this._focusableElements.indexOf(activeElement as HTMLElement);\n\n // Se non trovato, potrebbe essere un elemento interno ad un custom element\n if (currentIndex === -1 && activeElement) {\n // Risali attraverso gli shadow host\n let parent = (activeElement.getRootNode() as ShadowRoot)?.host;\n while (parent && currentIndex === -1) {\n currentIndex = this._focusableElements.indexOf(parent as HTMLElement);\n if (currentIndex === -1) {\n parent = (parent.getRootNode() as ShadowRoot)?.host;\n }\n }\n }\n\n if (event.shiftKey) {\n // Shift + Tab: vai al precedente\n if (currentIndex <= 0) {\n // Se sei sul primo o non sei nella lista, vai all'ultimo\n lastElement?.focus();\n } else {\n // Vai al precedente\n this._focusableElements[currentIndex - 1]?.focus();\n }\n } else if (currentIndex === -1 || currentIndex >= this._focusableElements.length - 1) {\n // Tab: se non sei nella lista o sei sull'ultimo, vai al primo\n firstElement?.focus();\n } else {\n // Vai al successivo\n this._focusableElements[currentIndex + 1]?.focus();\n }\n }\n\n private _restoreFocus(): void {\n if (this._previousActiveElement && typeof this._previousActiveElement.focus === 'function') {\n this._previousActiveElement.focus();\n }\n this._previousActiveElement = null;\n }\n}\n"]}
@@ -37,12 +37,13 @@ export declare class FormControl extends BaseLocalizedComponent {
37
37
  maxlength: number;
38
38
  /** If the input is required. */
39
39
  required: boolean;
40
+ protected isInGroup: boolean;
40
41
  /** Gets the validity state object */
41
42
  get validity(): ValidityState;
42
43
  validationMessage: string;
43
- checkValidity(): boolean;
44
44
  /** Gets the associated form, if one exists. */
45
45
  getForm(): HTMLFormElement | null;
46
+ checkValidity(): boolean;
46
47
  /** Checks for validity and shows the browser's validation message if the control is invalid. */
47
48
  reportValidity(): boolean;
48
49
  /** Sets a custom validation message. Pass an empty string to restore validity. */
@@ -1 +1 @@
1
- {"version":3,"file":"form-control.d.ts","sourceRoot":"","sources":["../../../src/form/form-control.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAK7D,qBAAa,WAAY,SAAQ,sBAAsB;IACrD,SAAS,CAAC,QAAQ,CAAC,qBAAqB,wBAErC;IASH,QAAQ,UAAS;IAGjB,YAAY,EAAG,gBAAgB,CAAC;IAEhC,4EAA4E;IAE5E,IAAI,SAAM;IAEV,qFAAqF;IAErF,KAAK,SAAM;IAEX,gCAAgC;IAEhC,QAAQ,UAAS;IAEjB;;;;OAIG;IACwC,IAAI,SAAM;IAErD,0FAA0F;IAE1F,gBAAgB,UAAS;IAEzB,uGAAuG;IAEvG,cAAc,EAAE,MAAM,CAAM;IAE5B,iDAAiD;IAEjD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,8EAA8E;IAE9E,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAExC,8EAA8E;IAE9E,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAExC;;;OAGG;IAEH,IAAI,EAAE,MAAM,GAAG,KAAK,CAAS;IAE7B,kCAAkC;IAElC,SAAS,SAAM;IAEf,kCAAkC;IAElC,SAAS,SAAM;IAE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,cAAc,EAAE,MAAM,CAAM;IAE5B,iDAAiD;IAEjD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,8EAA8E;IAE9E,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAExC,8EAA8E;IAE9E,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAExC;;;OAGG;IAEH,IAAI,EAAE,MAAM,GAAG,KAAK,CAAS;IAE7B,kCAAkC;IAElC,SAAS,SAAM;IAEf,kCAAkC;IAElC,SAAS,SAAM;IAEf,gCAAgC;IAEhC,QAAQ,UAAS;IAIjB,SAAS,CAAC,SAAS,UAAS;IAE5B,qCAAqC;IACrC,IAAW,QAAQ,IAAI,aAAa,CAEnC;IAGM,iBAAiB,SAAM;IAE9B,+CAA+C;IACxC,OAAO,IAAI,eAAe,GAAG,IAAI;IAKjC,aAAa,IAAI,OAAO;IAK/B,gGAAgG;IACzF,cAAc;IAOrB,kFAAkF;IAC3E,iBAAiB,CAAC,OAAO,EAAE,MAAM;IAOxC,SAAS,CAAC,YAAY;IAOtB,SAAS,CAAC,YAAY,CAAC,CAAC,EAAE,KAAK;IAY/B,SAAS,CAAC,WAAW,CAAC,CAAC,EAAE,KAAK;IAO9B,SAAS,CAAC,YAAY,CAAC,CAAC,EAAE,KAAK;IAK/B,SAAS,CAAC,YAAY,CAAC,CAAC,EAAE,KAAK;IAO/B,SAAS,CAAC,wBAAwB;IAmClC,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK;IAKrC,SAAS,CAAC,aAAa,CAAC,CAAC,EAAE,KAAK;IAoCvB,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC;CAS3E"}
@@ -43,24 +43,27 @@ export class FormControl extends BaseLocalizedComponent {
43
43
  this.maxlength = -1;
44
44
  /** If the input is required. */
45
45
  this.required = false;
46
+ /* For grouped input, like checkbox-group */
47
+ this.isInGroup = false;
46
48
  this.validationMessage = '';
47
49
  }
48
50
  /** Gets the validity state object */
49
51
  get validity() {
50
52
  return this.inputElement?.validity;
51
53
  }
54
+ /** Gets the associated form, if one exists. */
55
+ getForm() {
56
+ return this.formControlController.getForm();
57
+ }
52
58
  // Form validation methods
53
59
  checkValidity() {
54
60
  const inputValid = this.inputElement?.checkValidity() ?? true; // this.inputElement.checkValidity() è la validazione del browser
55
61
  return inputValid;
56
62
  }
57
- /** Gets the associated form, if one exists. */
58
- getForm() {
59
- return this.formControlController.getForm();
60
- }
61
63
  /** Checks for validity and shows the browser's validation message if the control is invalid. */
62
64
  reportValidity() {
63
- const ret = this.inputElement.checkValidity();
65
+ // const ret = this.inputElement.checkValidity();
66
+ const ret = this.checkValidity(); // chiama la checkValidity, che se è stata overridata chiama quella
64
67
  this.handleValidationMessages();
65
68
  return ret; // this.inputElement.reportValidity();
66
69
  }
@@ -105,7 +108,8 @@ export class FormControl extends BaseLocalizedComponent {
105
108
  handleValidationMessages() {
106
109
  if (!this.customValidation) {
107
110
  const _v = this.inputElement.validity;
108
- if (_v.valueMissing) {
111
+ const isRequiredHandledByGroup = this.isInGroup === true;
112
+ if (_v.valueMissing && !isRequiredHandledByGroup) {
109
113
  this.setCustomValidity(this.$t('validityRequired'));
110
114
  }
111
115
  else if (_v.patternMismatch) {
@@ -176,7 +180,7 @@ export class FormControl extends BaseLocalizedComponent {
176
180
  if (this.customValidation) {
177
181
  this.setCustomValidity(this.validationText ?? '');
178
182
  }
179
- else {
183
+ else if (this.formControlController.userInteracted()) {
180
184
  this.formControlController.updateValidity();
181
185
  }
182
186
  }
@@ -244,6 +248,10 @@ __decorate([
244
248
  ,
245
249
  __metadata("design:type", Object)
246
250
  ], FormControl.prototype, "required", void 0);
251
+ __decorate([
252
+ property({ type: Boolean }),
253
+ __metadata("design:type", Object)
254
+ ], FormControl.prototype, "isInGroup", void 0);
247
255
  __decorate([
248
256
  state(),
249
257
  __metadata("design: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;;;yCACpD;AAIV;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;0CACjB;AAIX;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,mBAAmB;;;6CAC9C;AAO0B;IAA1C,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;yCAAW;AAIrD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,mBAAmB,EAAE,CAAC;;qDAClD;AAIzB;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;mDAC/B;AAI5B;IADC,QAAQ,EAAE;;4CACM;AAIjB;IADC,QAAQ,EAAE;;wCAC6B;AAIxC;IADC,QAAQ,EAAE;;wCAC6B;AAOxC;IADC,QAAQ,EAAE;;yCACkB;AAI7B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CACZ;AAIf;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CACZ;AAIf;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,mBAAmB;;;6CAC9C;AAQV;IADN,KAAK,EAAE;;sDACsB","sourcesContent":["import { property, query, state } from 'lit/decorators.js';\nimport { registerTranslation } from '@italia/i18n';\nimport { BaseLocalizedComponent } from '../base-component/base-component.js';\nimport { FormControlController } from './form-controller.js';\nimport it from './locales/it.js';\n\nregisterTranslation(it);\n\nexport class FormControl extends BaseLocalizedComponent {\n protected readonly formControlController = new FormControlController(this, {\n assumeInteractionOn: ['it-input', 'it-blur', 'it-change'],\n });\n\n // TODO: verificare se serve davvero con il fatto che usiamo form-controller\n // static formAssociated = true;\n\n // @property()\n // internals = this.attachInternals();\n\n @state()\n _touched = false;\n\n @query('.it-form__control')\n inputElement!: HTMLInputElement; // from FormControl\n\n /** The name of the input, submitted as a name/value pair with form data. */\n @property({ type: String, reflect: true }) // from FormControl\n name = '';\n\n /** The current value of the input, submitted as a name/value pair with form data. */\n @property({ reflect: true })\n value = '';\n\n /** If the input is disabled. */\n @property({ type: Boolean, reflect: true }) // from FormControl\n disabled = false;\n\n /**\n * By default, form controls are associated with the nearest containing `<form>` element. This attribute allows you\n * to place the form control outside of a form and associate it with the form that has this `id`. The form must be in\n * the same document or shadow root for this to work.\n */\n @property({ reflect: true, type: String }) form = '';\n\n /** If you implement your custom validation and you won't to trigger default validation */\n @property({ type: Boolean, reflect: true, attribute: 'custom-validation' })\n customValidation = false;\n\n /** If your input is invalid from your custom validition, set this attribute with message validation */\n @property({ attribute: 'validity-message', reflect: true })\n validationText: string = '';\n\n /** Pattern the `value` must match to be valid */\n @property()\n pattern?: string;\n\n /** The input's minimum value. Only applies to date and number input types. */\n @property()\n min: number | string | Date | undefined;\n\n /** The input's maximum value. Only applies to date and number input types. */\n @property()\n max: number | string | Date | undefined;\n\n /**\n * Specifies the granularity that the value must adhere to, or the special value `any` which means no stepping is\n * implied, allowing any numeric value. Only applies to date and number input types.\n */\n @property()\n step: number | 'any' = 'any';\n\n /** The input's minimum length. */\n @property({ type: Number })\n minlength = -1;\n\n /** The input's maximum length. */\n @property({ type: Number })\n maxlength = -1;\n\n /** If the input is required. */\n @property({ type: Boolean, reflect: true }) // from FormControl\n required = false;\n\n /** Gets the validity state object */\n public get validity(): ValidityState {\n return this.inputElement?.validity;\n }\n\n @state()\n public validationMessage = '';\n\n // Form validation methods\n public checkValidity(): boolean {\n const inputValid = this.inputElement?.checkValidity() ?? true; // this.inputElement.checkValidity() è la validazione del browser\n return inputValid;\n }\n\n /** Gets the associated form, if one exists. */\n public getForm(): HTMLFormElement | null {\n return this.formControlController.getForm();\n }\n\n /** Checks for validity and shows the browser's validation message if the control is invalid. */\n public reportValidity() {\n const ret = this.inputElement.checkValidity();\n this.handleValidationMessages();\n return ret; // this.inputElement.reportValidity();\n }\n\n /** Sets a custom validation message. Pass an empty string to restore validity. */\n public setCustomValidity(message: string) {\n this.inputElement.setCustomValidity(message);\n this.validationMessage = this.inputElement.validationMessage;\n this.formControlController.updateValidity();\n }\n\n // Handlers\n\n protected _handleReady() {\n requestAnimationFrame(() => {\n this.dispatchEvent(new CustomEvent('it-input-ready', { bubbles: true, detail: { el: this.inputElement } }));\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleInput(e: Event) {\n this.handleValidationMessages();\n\n this.dispatchEvent(\n new CustomEvent('it-input', {\n detail: { value: this.inputElement.value, el: this.inputElement },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleBlur(e: Event) {\n this._touched = true;\n this.handleValidationMessages();\n\n this.dispatchEvent(new FocusEvent('it-blur', { bubbles: true, composed: true }));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleFocus(e: Event) {\n this.dispatchEvent(new FocusEvent('it-focus', { bubbles: true, composed: true }));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleClick(e: Event) {\n this.dispatchEvent(new MouseEvent('it-click', { bubbles: true, composed: true }));\n }\n\n /*\n Override default browser validation messages\n */\n protected handleValidationMessages() {\n if (!this.customValidation) {\n const _v = this.inputElement.validity;\n\n if (_v.valueMissing) {\n this.setCustomValidity(this.$t('validityRequired'));\n } else if (_v.patternMismatch) {\n this.setCustomValidity(this.$t('validityPattern'));\n } else if (_v.tooShort) {\n this.setCustomValidity(this.$t('validityMinlength').replace('{minlength}', this.minlength.toString()));\n } else if (_v.tooLong) {\n this.setCustomValidity(this.$t('validityMaxlength').replace('{maxlength}', this.maxlength.toString()));\n } else {\n /* nothing. Usa il messaggio di errore della validazione\n di default del browser per altri errori di validità come:\n - typeMismatch\n - rangeUnderflow\n - rangeOverflow\n - stepMismatch\n - badInput */\n\n const otherConstraintErrors =\n _v.typeMismatch || _v.rangeUnderflow || _v.rangeOverflow || _v.stepMismatch || _v.badInput;\n\n if (!otherConstraintErrors) {\n this.setCustomValidity('');\n }\n }\n }\n\n this.validationMessage = this.inputElement.validationMessage;\n }\n\n protected _handleInvalid(event: Event) {\n this.formControlController.setValidity(false);\n this.formControlController.emitInvalidEvent(event);\n }\n\n protected _handleChange(e: Event) {\n const target = e.target as HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;\n let value: unknown;\n\n if (target instanceof HTMLInputElement) {\n switch (target.type) {\n case 'checkbox':\n case 'radio':\n value = target.checked;\n break;\n case 'file':\n value = target.files; // FileList\n break;\n default:\n value = target.value;\n }\n } else if (target instanceof HTMLSelectElement) {\n if (target.multiple) {\n value = Array.from(target.selectedOptions).map((o) => o.value);\n } else {\n value = target.value;\n }\n } else {\n // textarea o altri input con value\n value = (target as any).value;\n }\n\n this.dispatchEvent(\n new CustomEvent('it-change', {\n detail: { value, el: target },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n override updated(changedProperties: Map<string | number | symbol, unknown>) {\n super.updated?.(changedProperties);\n\n if (this.customValidation) {\n this.setCustomValidity(this.validationText ?? '');\n } else {\n this.formControlController.updateValidity();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"form-control.js","sourceRoot":"","sources":["../../../src/form/form-control.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEjC,mBAAmB,CAAC,EAAE,CAAC,CAAC;AAExB,MAAM,OAAO,WAAY,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,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;yCAAW;AAIrD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,mBAAmB,EAAE,CAAC;;qDAClD;AAIzB;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;mDAC/B;AAI5B;IADC,QAAQ,EAAE;;4CACM;AAIjB;IADC,QAAQ,EAAE;;wCAC6B;AAIxC;IADC,QAAQ,EAAE;;wCAC6B;AAOxC;IADC,QAAQ,EAAE;;yCACkB;AAI7B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CACZ;AAIf;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CACZ;AAIf;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,mBAAmB;;;6CAC9C;AAIP;IADT,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;8CACA;AAQrB;IADN,KAAK,EAAE;;sDACsB","sourcesContent":["import { property, query, state } from 'lit/decorators.js';\nimport { registerTranslation } from '@italia/i18n';\nimport { BaseLocalizedComponent } from '../base-component/base-component.js';\nimport { FormControlController } from './form-controller.js';\nimport it from './locales/it.js';\n\nregisterTranslation(it);\n\nexport class FormControl extends BaseLocalizedComponent {\n protected readonly formControlController = new FormControlController(this, {\n assumeInteractionOn: ['it-input', 'it-blur', 'it-change'],\n });\n\n // TODO: verificare se serve davvero con il fatto che usiamo form-controller\n // static formAssociated = true;\n\n // @property()\n // internals = this.attachInternals();\n\n @state()\n _touched = false;\n\n @query('.it-form__control')\n inputElement!: HTMLInputElement; // from FormControl\n\n /** The name of the input, submitted as a name/value pair with form data. */\n @property({ type: String, reflect: true }) // from FormControl\n name = '';\n\n /** The current value of the input, submitted as a name/value pair with form data. */\n @property({ reflect: true })\n value = '';\n\n /** If the input is disabled. */\n @property({ type: Boolean, reflect: true }) // from FormControl\n disabled = false;\n\n /**\n * By default, form controls are associated with the nearest containing `<form>` element. This attribute allows you\n * to place the form control outside of a form and associate it with the form that has this `id`. The form must be in\n * the same document or shadow root for this to work.\n */\n @property({ reflect: true, type: String }) form = '';\n\n /** If you implement your custom validation and you won't to trigger default validation */\n @property({ type: Boolean, reflect: true, attribute: 'custom-validation' })\n customValidation = false;\n\n /** If your input is invalid from your custom validition, set this attribute with message validation */\n @property({ attribute: 'validity-message', reflect: true })\n validationText: string = '';\n\n /** Pattern the `value` must match to be valid */\n @property()\n pattern?: string;\n\n /** The input's minimum value. Only applies to date and number input types. */\n @property()\n min: number | string | Date | undefined;\n\n /** The input's maximum value. Only applies to date and number input types. */\n @property()\n max: number | string | Date | undefined;\n\n /**\n * Specifies the granularity that the value must adhere to, or the special value `any` which means no stepping is\n * implied, allowing any numeric value. Only applies to date and number input types.\n */\n @property()\n step: number | 'any' = 'any';\n\n /** The input's minimum length. */\n @property({ type: Number })\n minlength = -1;\n\n /** The input's maximum length. */\n @property({ type: Number })\n maxlength = -1;\n\n /** If the input is required. */\n @property({ type: Boolean, reflect: true }) // from FormControl\n required = false;\n\n /* For grouped input, like checkbox-group */\n @property({ type: Boolean })\n protected isInGroup = false;\n\n /** Gets the validity state object */\n public get validity(): ValidityState {\n return this.inputElement?.validity;\n }\n\n @state()\n public validationMessage = '';\n\n /** Gets the associated form, if one exists. */\n public getForm(): HTMLFormElement | null {\n return this.formControlController.getForm();\n }\n\n // Form validation methods\n public checkValidity(): boolean {\n const inputValid = this.inputElement?.checkValidity() ?? true; // this.inputElement.checkValidity() è la validazione del browser\n return inputValid;\n }\n\n /** Checks for validity and shows the browser's validation message if the control is invalid. */\n public reportValidity() {\n // const ret = this.inputElement.checkValidity();\n const ret = this.checkValidity(); // chiama la checkValidity, che se è stata overridata chiama quella\n this.handleValidationMessages();\n return ret; // this.inputElement.reportValidity();\n }\n\n /** Sets a custom validation message. Pass an empty string to restore validity. */\n public setCustomValidity(message: string) {\n this.inputElement.setCustomValidity(message);\n this.validationMessage = this.inputElement.validationMessage;\n this.formControlController.updateValidity();\n }\n\n // Handlers\n protected _handleReady() {\n requestAnimationFrame(() => {\n this.dispatchEvent(new CustomEvent('it-input-ready', { bubbles: true, detail: { el: this.inputElement } }));\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleInput(e: Event) {\n this.handleValidationMessages();\n this.dispatchEvent(\n new CustomEvent('it-input', {\n detail: { value: this.inputElement.value, el: this.inputElement },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleBlur(e: Event) {\n this._touched = true;\n this.handleValidationMessages();\n this.dispatchEvent(new FocusEvent('it-blur', { bubbles: true, composed: true }));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleFocus(e: Event) {\n this.dispatchEvent(new FocusEvent('it-focus', { bubbles: true, composed: true }));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleClick(e: Event) {\n this.dispatchEvent(new MouseEvent('it-click', { bubbles: true, composed: true }));\n }\n\n /*\n Override default browser validation messages\n */\n protected handleValidationMessages() {\n if (!this.customValidation) {\n const _v = this.inputElement.validity;\n\n const isRequiredHandledByGroup = this.isInGroup === true;\n\n if (_v.valueMissing && !isRequiredHandledByGroup) {\n this.setCustomValidity(this.$t('validityRequired'));\n } else if (_v.patternMismatch) {\n this.setCustomValidity(this.$t('validityPattern'));\n } else if (_v.tooShort) {\n this.setCustomValidity(this.$t('validityMinlength').replace('{minlength}', this.minlength.toString()));\n } else if (_v.tooLong) {\n this.setCustomValidity(this.$t('validityMaxlength').replace('{maxlength}', this.maxlength.toString()));\n } else {\n /* nothing. Usa il messaggio di errore della validazione\n di default del browser per altri errori di validità come:\n - typeMismatch\n - rangeUnderflow\n - rangeOverflow\n - stepMismatch\n - badInput */\n\n const otherConstraintErrors =\n _v.typeMismatch || _v.rangeUnderflow || _v.rangeOverflow || _v.stepMismatch || _v.badInput;\n\n if (!otherConstraintErrors) {\n this.setCustomValidity('');\n }\n }\n }\n\n this.validationMessage = this.inputElement.validationMessage;\n }\n\n protected _handleInvalid(event: Event) {\n this.formControlController.setValidity(false);\n this.formControlController.emitInvalidEvent(event);\n }\n\n protected _handleChange(e: Event) {\n const target = e.target as HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;\n let value: unknown;\n\n if (target instanceof HTMLInputElement) {\n switch (target.type) {\n case 'checkbox':\n case 'radio':\n value = target.checked;\n break;\n case 'file':\n value = target.files; // FileList\n break;\n default:\n value = target.value;\n }\n } else if (target instanceof HTMLSelectElement) {\n if (target.multiple) {\n value = Array.from(target.selectedOptions).map((o) => o.value);\n } else {\n value = target.value;\n }\n } else {\n // textarea o altri input con value\n value = (target as any).value;\n }\n\n this.dispatchEvent(\n new CustomEvent('it-change', {\n detail: { value, el: target },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n override updated(changedProperties: Map<string | number | symbol, unknown>) {\n super.updated?.(changedProperties);\n\n if (this.customValidation) {\n this.setCustomValidity(this.validationText ?? '');\n } else if (this.formControlController.userInteracted()) {\n this.formControlController.updateValidity();\n }\n }\n}\n"]}
@@ -24,6 +24,7 @@ export declare class FormControlController implements ReactiveController {
24
24
  host: FormControl & ReactiveControllerHost;
25
25
  form?: HTMLFormElement | null;
26
26
  options: FormControlControllerOptions;
27
+ submittedOnce: boolean;
27
28
  constructor(host: ReactiveControllerHost & FormControl, options?: Partial<FormControlControllerOptions>);
28
29
  hostConnected(): void;
29
30
  hostDisconnected(): void;
@@ -49,6 +50,7 @@ export declare class FormControlController implements ReactiveController {
49
50
  * the host element immediately, i.e. before Lit updates the component in the next update.
50
51
  */
51
52
  setValidity(isValid: boolean): void;
53
+ userInteracted(): boolean;
52
54
  /**
53
55
  * Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything
54
56
  * that affects constraint validation changes so the component receives the correct validity states.
@@ -1 +1 @@
1
- {"version":3,"file":"form-controller.d.ts","sourceRoot":"","sources":["../../../src/form/form-controller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,KAAK,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOhD,eAAO,MAAM,eAAe,EAAE,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,WAAW,CAAC,CAAiB,CAAC;AAoBzF,MAAM,WAAW,4BAA4B;IAC3C,oEAAoE;IACpE,IAAI,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,eAAe,GAAG,IAAI,CAAC;IACrD,mGAAmG;IACnG,IAAI,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,CAAC;IACrC,gEAAgE;IAChE,KAAK,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,GAAG,OAAO,EAAE,CAAC;IACnD,oHAAoH;IACpH,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IAK1C,cAAc,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IAMhD,aAAa,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IAC/C,oDAAoD;IACpD,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACvD;;qFAEiF;IACjF,mBAAmB,EAAE,MAAM,EAAE,CAAC;CAC/B;AAED,uGAAuG;AACvG,qBAAa,qBAAsB,YAAW,kBAAkB;IAC9D,IAAI,EAAE,WAAW,GAAG,sBAAsB,CAAC;IAE3C,IAAI,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAE9B,OAAO,EAAE,4BAA4B,CAAC;gBAE1B,IAAI,EAAE,sBAAsB,GAAG,WAAW,EAAE,OAAO,CAAC,E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MzC;;;OAGG;IACH,WAAW,CAAC,OAAO,EAAE,OAAO;IAmB5B,cAAc;IAMd;;;OAGG;IACH,cAAc;IAKd;;;;;;OAMG;IACH,gBAAgB,CAAC,oBAAoB,CAAC,EAAE,KAAK;CAgB9C"}
@@ -22,6 +22,7 @@ const interactions = new WeakMap();
22
22
  /** A reactive controller to allow form controls to participate in form submission, validation, etc. */
23
23
  export class FormControlController {
24
24
  constructor(host, options) {
25
+ this.submittedOnce = false;
25
26
  this.handleFormData = (event) => {
26
27
  // console.log('handleFormData');
27
28
  const disabled = this.options.disabled(this.host);
@@ -43,6 +44,17 @@ export class FormControlController {
43
44
  event.formData.append(name, value);
44
45
  }
45
46
  break;
47
+ case 'it-checkbox':
48
+ if (this.host.checked) {
49
+ if (event.formData.getAll(name).indexOf(value) < 0) {
50
+ // handle group checkbox
51
+ event.formData.append(name, value);
52
+ }
53
+ }
54
+ break;
55
+ case 'it-checkbox-group':
56
+ // non settare valori in formData, perchè ogni singola checkbox setta il suo valore
57
+ break;
46
58
  default:
47
59
  if (Array.isArray(value)) {
48
60
  value.forEach((val) => {
@@ -64,13 +76,30 @@ export class FormControlController {
64
76
  this.setUserInteracted(control, true);
65
77
  });
66
78
  }
67
- if (this.form && !this.form.noValidate && !disabled && !reportValidity(this.host)) {
79
+ const resReportValidity = reportValidity(this.host);
80
+ if (this.form && !this.form.noValidate && !disabled && !resReportValidity) {
68
81
  event.preventDefault();
69
82
  // event.stopImmediatePropagation(); // se lo attiviamo, valida un campo alla volta
83
+ // Scroll al primo controllo non valido
84
+ const formControls = formCollections.get(this.form);
85
+ if (formControls) {
86
+ for (const control of formControls) {
87
+ if (!control.validity?.valid) {
88
+ // Scroll smooth verso il controllo non valido
89
+ control.scrollIntoView({
90
+ behavior: 'smooth',
91
+ block: 'center',
92
+ });
93
+ break;
94
+ }
95
+ }
96
+ }
70
97
  }
98
+ this.submittedOnce = true;
71
99
  };
72
100
  this.handleFormReset = () => {
73
101
  this.options.setValue(this.host, '');
102
+ this.submittedOnce = false;
74
103
  this.setUserInteracted(this.host, false);
75
104
  interactions.set(this.host, []);
76
105
  };
@@ -235,6 +264,7 @@ export class FormControlController {
235
264
  if (!formCollection) {
236
265
  return;
237
266
  }
267
+ this.submittedOnce = false;
238
268
  // Remove this host from the form's collection
239
269
  formCollection.delete(this.host);
240
270
  // Check to make sure there's no other form controls in the collection. If we do this
@@ -331,6 +361,10 @@ export class FormControlController {
331
361
  host.toggleAttribute('data-user-invalid', !isValid && hasInteracted);
332
362
  host.toggleAttribute('data-user-valid', isValid && hasInteracted);
333
363
  }
364
+ userInteracted() {
365
+ const hasInteracted = Boolean(userInteractedControls.has(this.host));
366
+ return hasInteracted;
367
+ }
334
368
  /**
335
369
  * Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything
336
370
  * that affects constraint validation changes so the component receives the correct validity states.