@arbetsformedlingen/yrkesvaljaren 2.0.12 → 2.2.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 (98) hide show
  1. package/README.md +52 -21
  2. package/dist/cjs/{af-validation-message-Cy89nVEv.js → af-validation-message-BdR9X_qh.js} +1 -1
  3. package/dist/cjs/core-selector.cjs.entry.js +342 -23
  4. package/dist/cjs/digi-service-job-selector.cjs.entry.js +352 -61
  5. package/dist/cjs/{index-hZgOvC17.js → index-DMQDFAL7.js} +0 -22
  6. package/dist/cjs/index.cjs.js +4 -7
  7. package/dist/cjs/loader.cjs.js +2 -2
  8. package/dist/{esm/fuse-BPnhMTul.js → cjs/types-DdzCbiye.js} +965 -1
  9. package/dist/cjs/yrkesvaljaren.cjs.js +2 -2
  10. package/dist/collection/collection-manifest.json +0 -1
  11. package/dist/collection/components/core-selector/core-selector.css +70 -49
  12. package/dist/collection/components/core-selector/core-selector.js +309 -14
  13. package/dist/collection/components/design-compat/af-icon.js +8 -7
  14. package/dist/collection/components/job-selector/job-selector-controller.js +13 -3
  15. package/dist/collection/components/job-selector/job-selector.css +188 -34
  16. package/dist/collection/components/job-selector/job-selector.js +199 -10
  17. package/dist/components/core-selector2.js +1 -1
  18. package/dist/components/digi-service-job-selector.js +1 -1
  19. package/dist/components/index.js +1 -1
  20. package/dist/components/types.js +1 -1
  21. package/dist/esm/{af-validation-message-BgoGzzBf.js → af-validation-message-DMoOu-0k.js} +1 -1
  22. package/dist/esm/core-selector.entry.js +342 -23
  23. package/dist/esm/digi-service-job-selector.entry.js +310 -19
  24. package/dist/esm/{index-HNd02eQb.js → index-vJ-tamti.js} +1 -22
  25. package/dist/esm/index.js +2 -4
  26. package/dist/esm/loader.js +3 -3
  27. package/dist/{cjs/fuse-BTLNKxuL.js → esm/types-DVos4HHS.js} +948 -2
  28. package/dist/esm/yrkesvaljaren.js +3 -3
  29. package/dist/types/components/core-selector/core-selector.d.ts +68 -0
  30. package/dist/types/components/job-selector/job-selector-controller.d.ts +5 -0
  31. package/dist/types/components/job-selector/job-selector.d.ts +21 -3
  32. package/dist/types/components/job-selector/types.d.ts +12 -0
  33. package/dist/types/components.d.ts +20 -99
  34. package/dist/types/index.d.ts +1 -1
  35. package/dist/vendor/taxonomy-core/af-data-layer.d.ts +16 -0
  36. package/dist/vendor/taxonomy-core/af-data-layer.js +24 -0
  37. package/dist/vendor/taxonomy-core/index.d.ts +1 -1
  38. package/dist/vendor/taxonomy-core/index.js +1 -1
  39. package/dist/vendor/taxonomy-core/pii-sanitizer.d.ts +25 -0
  40. package/dist/vendor/taxonomy-core/pii-sanitizer.js +137 -0
  41. package/dist/vendor/taxonomy-core/selector-navigation.d.ts +9 -1
  42. package/dist/vendor/taxonomy-core/selector-navigation.js +28 -1
  43. package/dist/vendor/taxonomy-core/selector-types.d.ts +12 -0
  44. package/dist/yrkesvaljaren/index.esm.js +1 -1
  45. package/dist/yrkesvaljaren/p-0f19a308.entry.js +1 -0
  46. package/dist/yrkesvaljaren/{p-BUviBbwX.js → p-DHK95AvZ.js} +1 -1
  47. package/dist/yrkesvaljaren/p-DVos4HHS.js +1 -0
  48. package/dist/yrkesvaljaren/p-b81496c8.entry.js +1 -0
  49. package/dist/yrkesvaljaren/p-vJ-tamti.js +3 -0
  50. package/dist/yrkesvaljaren/yrkesvaljaren.esm.js +1 -1
  51. package/package.json +12 -10
  52. package/dist/cjs/geo-valjaren.cjs.entry.js +0 -14910
  53. package/dist/cjs/job-selector-demo.cjs.entry.js +0 -690
  54. package/dist/cjs/neobrutal-search.cjs.entry.js +0 -171
  55. package/dist/cjs/search.engine-D4cpbVzd.js +0 -504
  56. package/dist/cjs/taxonomy-registry-Dzt0SPzT.js +0 -454
  57. package/dist/cjs/types-CtHBl6Ra.js +0 -14
  58. package/dist/collection/components/geovaljaren/geovaljaren.css +0 -21
  59. package/dist/collection/components/geovaljaren/geovaljaren.js +0 -304
  60. package/dist/collection/components/geovaljaren/logic/adapter.utils.js +0 -20
  61. package/dist/collection/components/geovaljaren/logic/data.utils.js +0 -12
  62. package/dist/collection/components/geovaljaren/logic/history-service.js +0 -25
  63. package/dist/collection/components/geovaljaren/logic/search.engine.js +0 -28
  64. package/dist/collection/verkstad/verkstad.js +0 -408
  65. package/dist/components/fuse.js +0 -1
  66. package/dist/components/geo-valjaren.d.ts +0 -11
  67. package/dist/components/geo-valjaren.js +0 -1
  68. package/dist/components/job-selector-demo.d.ts +0 -11
  69. package/dist/components/job-selector-demo.js +0 -1
  70. package/dist/components/job-selector.js +0 -1
  71. package/dist/components/neobrutal-search.d.ts +0 -11
  72. package/dist/components/neobrutal-search.js +0 -1
  73. package/dist/components/search.engine.js +0 -1
  74. package/dist/esm/geo-valjaren.entry.js +0 -14908
  75. package/dist/esm/job-selector-demo.entry.js +0 -688
  76. package/dist/esm/neobrutal-search.entry.js +0 -169
  77. package/dist/esm/search.engine-BaWUTc3r.js +0 -493
  78. package/dist/esm/taxonomy-registry-C-pSh51L.js +0 -449
  79. package/dist/esm/types-DHUftoZJ.js +0 -12
  80. package/dist/types/components/geovaljaren/geovaljaren.d.ts +0 -24
  81. package/dist/types/components/geovaljaren/logic/adapter.utils.d.ts +0 -7
  82. package/dist/types/components/geovaljaren/logic/data.utils.d.ts +0 -7
  83. package/dist/types/components/geovaljaren/logic/history-service.d.ts +0 -6
  84. package/dist/types/components/geovaljaren/logic/search.engine.d.ts +0 -7
  85. package/dist/types/components/job-selector-demo/job-selector-demo.d.ts +0 -65
  86. package/dist/types/components/neobrutal-search/neobrutal-search.d.ts +0 -18
  87. package/dist/types/verkstad/verkstad.d.ts +0 -1
  88. package/dist/types/vitest-globals.d.ts +0 -1
  89. package/dist/yrkesvaljaren/p-5c3a5308.entry.js +0 -1
  90. package/dist/yrkesvaljaren/p-9ecd5177.entry.js +0 -1
  91. package/dist/yrkesvaljaren/p-BPnhMTul.js +0 -1
  92. package/dist/yrkesvaljaren/p-C-pSh51L.js +0 -1
  93. package/dist/yrkesvaljaren/p-CjMoDiZD.js +0 -1
  94. package/dist/yrkesvaljaren/p-DHUftoZJ.js +0 -1
  95. package/dist/yrkesvaljaren/p-HNd02eQb.js +0 -3
  96. package/dist/yrkesvaljaren/p-b6130085.entry.js +0 -1
  97. package/dist/yrkesvaljaren/p-dbbea724.entry.js +0 -1
  98. package/dist/yrkesvaljaren/p-df3fa43b.entry.js +0 -1
@@ -1,12 +1,39 @@
1
1
  // src/components/core-selector/core-selector.tsx
2
2
  import { h } from "@stencil/core";
3
- import { getNextActiveIndex, reconcileActiveIndex, shouldShowManualInput, SELECTOR_INPUT_MAX_LENGTH } from "../../../vendor/taxonomy-core/selector-navigation.js";
3
+ import { describeResultCount, getNextActiveIndex, reconcileActiveIndex, shouldShowManualInput, SELECTOR_INPUT_MAX_LENGTH } from "../../../vendor/taxonomy-core/selector-navigation.js";
4
4
  import { AfIcon, AfLabel, AfTag, AfValidationMessage } from "../design-compat";
5
5
  export class CoreSelector {
6
+ /**
7
+ * Väntetid efter att ett nytt resultat har renderats innan antalet träffar läses upp.
8
+ * Lång nog för att VoiceOver ska ha läst klart det användaren skrev (jfr GOV.UK:s autocomplete).
9
+ */
10
+ static RESULT_ANNOUNCEMENT_DELAY_MS = 1200;
11
+ /** Väntetid innan felet visas när spärren samtidigt stänger listan (skärmläsaren säger "hopfälld"). */
12
+ static ERROR_AFTER_COLLAPSE_DELAY_MS = 400;
13
+ /**
14
+ * När listan expanderas av första piltrycket sätts aria-activedescendant först efter denna
15
+ * väntetid. VoiceOver i Safari tappar annars första raden när aria-expanded ändras samtidigt.
16
+ */
17
+ static ACTIVE_DESCENDANT_DELAY_MS = 75;
18
+ /** Hur länge en live-region står tom innan samma text sätts tillbaka och läses upp igen. */
19
+ static LIVE_REGION_RESTORE_DELAY_MS = 100;
6
20
  historyRequestTimer;
21
+ resultAnnouncementTimer;
22
+ resultRestoreTimer;
23
+ validationRestoreTimer;
24
+ /** Fördröjningen som felets text väntar på just nu; 0 när ingen pågår. */
25
+ validationRestoreDelayMs = 0;
26
+ activeDescendantTimer;
7
27
  disconnectedCallback() {
8
28
  clearTimeout(this.historyRequestTimer);
9
29
  this.historyRequestTimer = undefined;
30
+ this.clearResultAnnouncement();
31
+ clearTimeout(this.validationRestoreTimer);
32
+ this.validationRestoreTimer = undefined;
33
+ this.validationRestoreDelayMs = 0;
34
+ // Annars kan felets text bli kvar dold om elementet flyttas i DOM:en under fördröjningen.
35
+ this.isValidationMessageHidden = false;
36
+ this.clearDeferredActiveDescendant();
10
37
  }
11
38
  static nextId = 0;
12
39
  hostElement;
@@ -39,7 +66,21 @@ export class CoreSelector {
39
66
  activeIndex = -1;
40
67
  isFocusedInternal = false;
41
68
  isNavigatingWithKeyboard = false;
69
+ /** Text i live-regionen som läser upp antalet träffar. */
70
+ resultAnnouncement = '';
71
+ /** Felmeddelandet töms en kort stund så att role="alert" läses upp igen. */
72
+ isValidationMessageHidden = false;
73
+ /** aria-activedescendant väntar tills aria-expanded="true" har hunnit läsas in. */
74
+ isActiveDescendantDeferred = false;
75
+ /** Användaren har skrivit i fältet sedan det fick fokus (inte bara att fältet har text). */
76
+ hasTypedSinceFocus = false;
42
77
  isKeyboardNavigationActive = false;
78
+ /** Användaren har skrivit och antalet träffar ska läsas upp när resultatet har kommit. */
79
+ hasPendingResultAnnouncement = false;
80
+ /** aria-expanded i den senaste renderingen. */
81
+ renderedExpanded = false;
82
+ /** aria-expanded när fritextalternativet valdes; listan kan ha stängts innan spärren kommer. */
83
+ expandedAtManualSelect = false;
43
84
  async setFocus() {
44
85
  if (this.inputRef) {
45
86
  this.inputRef.focus();
@@ -60,6 +101,10 @@ export class CoreSelector {
60
101
  }
61
102
  if (!this.state)
62
103
  return;
104
+ // Tab flyttar fokus (även inom komponenten, t.ex. till rensaknappen); när fokus kommer
105
+ // tillbaka till fältet gäller [10.03] som vid ny fokus.
106
+ if (event.key === 'Tab')
107
+ this.hasTypedSinceFocus = false;
63
108
  if (event.target?.tagName === 'BUTTON')
64
109
  return;
65
110
  if (event.key !== 'ArrowUp' && event.key !== 'ArrowDown' && event.key !== 'Enter' && event.key !== 'Escape') {
@@ -81,9 +126,17 @@ export class CoreSelector {
81
126
  case 'ArrowDown':
82
127
  if (totalOptions > 0) {
83
128
  event.preventDefault();
129
+ // Regionen lämnas orörd: en ändring i den samtidigt som aria-activedescendant
130
+ // pekar ut första alternativet kan få VoiceOver att läsa regionen i stället.
131
+ this.cancelPendingResultAnnouncement();
132
+ const wasExpanded = this.renderedExpanded;
133
+ // Listan kan vara stängd medan fältet har fokus, t.ex. efter en spärrad förslagstext.
134
+ this.isFocusedInternal = true;
84
135
  this.isKeyboardNavigationActive = true;
85
136
  this.isNavigatingWithKeyboard = true;
86
137
  this.activeIndex = getNextActiveIndex('down', this.activeIndex, totalOptions);
138
+ if (!wasExpanded)
139
+ this.deferActiveDescendant();
87
140
  this.scrollToActive();
88
141
  if (this.activeIndex >= suggestions.length - 3) {
89
142
  this.csLoadMore.emit();
@@ -96,15 +149,26 @@ export class CoreSelector {
96
149
  case 'ArrowUp':
97
150
  if (totalOptions > 0) {
98
151
  event.preventDefault();
152
+ // Pil upp i fältet flyttar ingenting och ska inte avbryta någon uppläsning.
153
+ if (this.activeIndex >= 0)
154
+ this.cancelPendingResultAnnouncement();
155
+ const wasExpanded = this.renderedExpanded;
156
+ const previousIndex = this.activeIndex;
157
+ const wasNavigating = this.isNavigatingWithKeyboard;
99
158
  this.isKeyboardNavigationActive = true;
100
159
  this.isNavigatingWithKeyboard = true;
101
160
  this.activeIndex = getNextActiveIndex('up', this.activeIndex, totalOptions);
102
161
  if (this.activeIndex >= 0) {
162
+ if (!wasExpanded)
163
+ this.deferActiveDescendant();
103
164
  this.scrollToActive();
104
165
  }
105
166
  else {
106
167
  this.isKeyboardNavigationActive = false;
107
168
  this.isNavigatingWithKeyboard = false;
169
+ // Bara när en rad var utpekad med tangentbordet (inte t.ex. under musen).
170
+ if (previousIndex >= 0 && wasNavigating)
171
+ this.announceReturnToInput();
108
172
  }
109
173
  }
110
174
  break;
@@ -115,7 +179,13 @@ export class CoreSelector {
115
179
  if (event.key === ' ' && this.activeIndex === -1) {
116
180
  return;
117
181
  }
118
- if (this.activeIndex >= 0 && this.activeIndex < suggestions.length) {
182
+ if (event.key === 'Enter' && this.state.manualInputBlocked
183
+ && !(this.activeIndex >= 0 && this.activeIndex < suggestions.length)) {
184
+ // Nytt försök med spärrad text: läs upp felet igen.
185
+ event.preventDefault();
186
+ this.reannounceValidationMessage();
187
+ }
188
+ else if (this.activeIndex >= 0 && this.activeIndex < suggestions.length) {
119
189
  event.preventDefault();
120
190
  const item = suggestions[this.activeIndex];
121
191
  this.shouldFocusAfterRender = true;
@@ -142,10 +212,146 @@ export class CoreSelector {
142
212
  break;
143
213
  case 'Escape':
144
214
  this.activeIndex = -1;
215
+ this.clearDeferredActiveDescendant();
216
+ this.clearResultAnnouncement();
145
217
  this.csClear.emit();
146
218
  break;
147
219
  }
148
220
  };
221
+ /** En ny inmatning: antalet läses upp först när resultatet för den nya texten har kommit. */
222
+ markResultAnnouncementPending(value) {
223
+ if (value.trim() === '') {
224
+ this.clearResultAnnouncement();
225
+ return;
226
+ }
227
+ clearTimeout(this.resultAnnouncementTimer);
228
+ this.resultAnnouncementTimer = undefined;
229
+ // En pågående återfyllning gäller den gamla texten.
230
+ clearTimeout(this.resultRestoreTimer);
231
+ this.resultRestoreTimer = undefined;
232
+ this.hasPendingResultAnnouncement = true;
233
+ }
234
+ /** Startar fördröjningen när ett nytt resultat för den aktuella texten har renderats. */
235
+ scheduleResultAnnouncement(newState, oldState) {
236
+ if (!this.hasPendingResultAnnouncement || !newState || newState.inputValue.trim() === '')
237
+ return;
238
+ // Ingen uppläsning medan användaren navigerar i listan med tangentbordet. (activeIndex
239
+ // räcker inte: det ligger kvar efter ny inmatning och sätts även när musen är över listan.)
240
+ if (this.isNavigatingWithKeyboard)
241
+ return;
242
+ // Resultatet gäller en äldre söktext (t.ex. medan en asynkron sökning pågår).
243
+ if (newState.resultsQuery !== undefined && newState.resultsQuery !== newState.inputValue)
244
+ return;
245
+ // Värdkomponenterna skapar nya arrayer vid varje rendering; jämför innehållet.
246
+ if (oldState && !CoreSelector.hasNewResult(oldState, newState))
247
+ return;
248
+ clearTimeout(this.resultAnnouncementTimer);
249
+ this.resultAnnouncementTimer = setTimeout(() => {
250
+ this.resultAnnouncementTimer = undefined;
251
+ this.announceResultCount();
252
+ }, CoreSelector.RESULT_ANNOUNCEMENT_DELAY_MS);
253
+ }
254
+ static hasNewResult(oldState, newState) {
255
+ if (oldState.inputValue !== newState.inputValue
256
+ || oldState.resultsQuery !== newState.resultsQuery
257
+ || oldState.hasMoreResults !== newState.hasMoreResults
258
+ || oldState.suggestions.length !== newState.suggestions.length) {
259
+ return true;
260
+ }
261
+ return newState.suggestions.some((suggestion, index) => {
262
+ const old = oldState.suggestions[index];
263
+ return suggestion.id !== old.id || suggestion.label !== old.label || !!suggestion.isSelected !== !!old.isSelected;
264
+ });
265
+ }
266
+ deferActiveDescendant() {
267
+ clearTimeout(this.activeDescendantTimer);
268
+ this.isActiveDescendantDeferred = true;
269
+ this.activeDescendantTimer = setTimeout(() => {
270
+ this.activeDescendantTimer = undefined;
271
+ this.isActiveDescendantDeferred = false;
272
+ }, CoreSelector.ACTIVE_DESCENDANT_DELAY_MS);
273
+ }
274
+ clearDeferredActiveDescendant() {
275
+ clearTimeout(this.activeDescendantTimer);
276
+ this.activeDescendantTimer = undefined;
277
+ this.isActiveDescendantDeferred = false;
278
+ }
279
+ /**
280
+ * Tillbaka i fältet från första raden: aria-activedescendant tas bort, och då läser VoiceOver
281
+ * annars upp raden igen. Fältets etikett och text läses upp i stället.
282
+ */
283
+ announceReturnToInput() {
284
+ this.clearDeferredActiveDescendant();
285
+ const value = this.state.inputValue.trim();
286
+ const text = [this.label, value].filter(Boolean).join(', ');
287
+ if (text)
288
+ this.setResultAnnouncement(text);
289
+ }
290
+ /** Avbryter en väntande uppläsning men låter live-regionen vara. */
291
+ cancelPendingResultAnnouncement() {
292
+ clearTimeout(this.resultAnnouncementTimer);
293
+ this.resultAnnouncementTimer = undefined;
294
+ // En pågående återfyllning av samma text ska inte heller komma under navigeringen.
295
+ clearTimeout(this.resultRestoreTimer);
296
+ this.resultRestoreTimer = undefined;
297
+ this.hasPendingResultAnnouncement = false;
298
+ }
299
+ announceResultCount() {
300
+ this.hasPendingResultAnnouncement = false;
301
+ // Ingen uppläsning när listan är stängd eller användaren redan navigerar i den.
302
+ const isListOpen = !!this.state && this.isFocusedInternal && this.state.status !== 'itemSelected';
303
+ if (!isListOpen || this.isNavigatingWithKeyboard) {
304
+ this.clearResultAnnouncement();
305
+ return;
306
+ }
307
+ this.setResultAnnouncement(describeResultCount(this.state, this.config));
308
+ }
309
+ /** Samma text som förra gången töms först och sätts tillbaka, så att den läses upp igen. */
310
+ setResultAnnouncement(text) {
311
+ clearTimeout(this.resultRestoreTimer);
312
+ this.resultRestoreTimer = undefined;
313
+ if (text !== '' && text === this.resultAnnouncement) {
314
+ this.resultAnnouncement = '';
315
+ this.resultRestoreTimer = setTimeout(() => {
316
+ this.resultRestoreTimer = undefined;
317
+ this.resultAnnouncement = text;
318
+ }, CoreSelector.LIVE_REGION_RESTORE_DELAY_MS);
319
+ return;
320
+ }
321
+ this.resultAnnouncement = text;
322
+ }
323
+ clearResultAnnouncement() {
324
+ clearTimeout(this.resultAnnouncementTimer);
325
+ this.resultAnnouncementTimer = undefined;
326
+ clearTimeout(this.resultRestoreTimer);
327
+ this.resultRestoreTimer = undefined;
328
+ this.hasPendingResultAnnouncement = false;
329
+ this.resultAnnouncement = '';
330
+ }
331
+ /**
332
+ * Läser upp felmeddelandet igen: texten tas ur role="alert" en kort stund och sätts
333
+ * tillbaka. Rutan behåller sin höjd eftersom texten ligger kvar osynligt och aria-hidden.
334
+ */
335
+ reannounceValidationMessage() {
336
+ if (this.state.validation !== 'error' || !this.state.message)
337
+ return;
338
+ this.showValidationMessageAfter(CoreSelector.LIVE_REGION_RESTORE_DELAY_MS);
339
+ }
340
+ /** Felrutan visas direkt, men texten läggs i role="alert" först efter delayMs. */
341
+ showValidationMessageAfter(delayMs) {
342
+ // En pågående längre fördröjning (t.ex. efter "hopfälld") förkortas inte av ett nytt försök;
343
+ // texten är redan dold och kommer tillbaka när den är slut.
344
+ if (this.validationRestoreTimer && delayMs <= this.validationRestoreDelayMs)
345
+ return;
346
+ clearTimeout(this.validationRestoreTimer);
347
+ this.isValidationMessageHidden = true;
348
+ this.validationRestoreDelayMs = delayMs;
349
+ this.validationRestoreTimer = setTimeout(() => {
350
+ this.validationRestoreTimer = undefined;
351
+ this.validationRestoreDelayMs = 0;
352
+ this.isValidationMessageHidden = false;
353
+ }, delayMs);
354
+ }
149
355
  onWrapperFocusIn = () => {
150
356
  if (this.config.disabled)
151
357
  return;
@@ -153,6 +359,10 @@ export class CoreSelector {
153
359
  if (this.state) {
154
360
  this.isFocusedInternal = true;
155
361
  this.activeIndex = -1;
362
+ // Ny fokus: listan ska inte vara expanderad förrän användaren navigerar ([10.03]).
363
+ this.isNavigatingWithKeyboard = false;
364
+ this.isKeyboardNavigationActive = false;
365
+ this.hasTypedSinceFocus = false;
156
366
  this.csFocus.emit();
157
367
  if (this.state.inputValue.trim() === '') {
158
368
  this.csRequestHistory.emit();
@@ -174,13 +384,21 @@ export class CoreSelector {
174
384
  if (!isInside) {
175
385
  this.isFocusedInternal = false;
176
386
  this.activeIndex = -1;
387
+ this.clearResultAnnouncement();
388
+ this.clearDeferredActiveDescendant();
389
+ // Annars är listan expanderad redan vid nästa fokus ([10.03]).
390
+ this.isNavigatingWithKeyboard = false;
391
+ this.isKeyboardNavigationActive = false;
392
+ this.hasTypedSinceFocus = false;
177
393
  this.csBlur.emit();
178
394
  }
179
395
  });
180
396
  };
181
397
  handleAfFocusedChange(newValue) {
182
398
  this.isFocusedInternal = newValue;
183
- if (newValue) {
399
+ // Fokus återställs bara om fältet inte redan har det. Ett onödigt focus() får
400
+ // skärmläsaren att läsa upp fältet igen, och det tränger undan live-regionerna.
401
+ if (newValue && this.hostElement.shadowRoot?.activeElement !== this.inputRef) {
184
402
  this.shouldFocusAfterRender = true;
185
403
  }
186
404
  }
@@ -189,6 +407,9 @@ export class CoreSelector {
189
407
  this.isFocusedInternal = false;
190
408
  this.activeIndex = -1;
191
409
  this.shouldFocusAfterRender = false;
410
+ this.isNavigatingWithKeyboard = false;
411
+ this.isKeyboardNavigationActive = false;
412
+ this.hasTypedSinceFocus = false;
192
413
  }
193
414
  }
194
415
  handleStateChange(newState, oldState) {
@@ -202,6 +423,16 @@ export class CoreSelector {
202
423
  if (result.shouldRestoreFocus) {
203
424
  this.shouldFocusAfterRender = true;
204
425
  }
426
+ this.scheduleResultAnnouncement(newState, oldState);
427
+ // Spärren stänger en expanderad lista: skärmläsaren säger "hopfälld" och tränger undan
428
+ // ett fel som visas samtidigt. Texten sätts därför in en stund efter att listan har stängts.
429
+ if (newState?.manualInputBlocked && !oldState?.manualInputBlocked && newState.validation === 'error') {
430
+ const wasExpanded = this.renderedExpanded || this.expandedAtManualSelect;
431
+ this.expandedAtManualSelect = false;
432
+ if (wasExpanded && !this.isComboboxExpanded()) {
433
+ this.showValidationMessageAfter(CoreSelector.ERROR_AFTER_COLLAPSE_DELAY_MS);
434
+ }
435
+ }
205
436
  }
206
437
  componentDidUpdate() {
207
438
  if (this.shouldFocusAfterRender) {
@@ -227,6 +458,28 @@ export class CoreSelector {
227
458
  }
228
459
  }
229
460
  }
461
+ /**
462
+ * aria-expanded: bara när listan faktiskt renderas. Vid fokus först vid tangentbordsnavigering,
463
+ * så att etiketten hinner läsas upp ([10.03]), även om fältet redan har text. När användaren har
464
+ * skrivit sedan fältet fick fokus är listan expanderad direkt, så att första pil ned bara ändrar
465
+ * aria-activedescendant och skärmläsaren läser upp raden.
466
+ */
467
+ isComboboxExpanded() {
468
+ if (!this.state || this.state.status === 'itemSelected')
469
+ return false;
470
+ const hasSuggestions = this.state.suggestions.length > 0 || shouldShowManualInput(this.state, this.config.requireSelection);
471
+ const hasTypedSinceFocus = this.hasTypedSinceFocus && this.state.inputValue.trim().length > 0;
472
+ return hasSuggestions && this.isSuggestionsListRendered() && (this.isNavigatingWithKeyboard || hasTypedSinceFocus);
473
+ }
474
+ /** Om förslagslistan renderas just nu (se render och renderSuggestionsList). */
475
+ isSuggestionsListRendered() {
476
+ if (!this.state || !this.isFocusedInternal || this.state.status === 'itemSelected')
477
+ return false;
478
+ const hasSearchInput = this.state.inputValue.trim().length > 0;
479
+ return this.state.suggestions.length > 0
480
+ || shouldShowManualInput(this.state, this.config.requireSelection)
481
+ || hasSearchInput;
482
+ }
230
483
  handleScroll(event) {
231
484
  if (!this.config.enableInfiniteScroll)
232
485
  return;
@@ -276,7 +529,19 @@ export class CoreSelector {
276
529
  }
277
530
  handleManualSelect() {
278
531
  const item = { id: '', label: this.state.inputValue.trim(), metadata: { type: 'ManualInput' } };
279
- this.shouldFocusAfterRender = true;
532
+ this.expandedAtManualSelect = this.renderedExpanded;
533
+ if (this.config.isFeedback) {
534
+ // Listan stängs. Ingen rad får vara kvar markerad, så att aria-expanded och
535
+ // aria-activedescendant inte pekar på en lista som inte renderas (t.ex. vid spärren).
536
+ this.isFocusedInternal = false;
537
+ this.shouldFocusAfterRender = false;
538
+ this.activeIndex = -1;
539
+ this.isKeyboardNavigationActive = false;
540
+ this.isNavigatingWithKeyboard = false;
541
+ }
542
+ else {
543
+ this.shouldFocusAfterRender = true;
544
+ }
280
545
  this.csSelect.emit(item);
281
546
  if (this.config.enableMultiple && this.state?.inputValue?.trim() === '') {
282
547
  this.csRequestHistory.emit();
@@ -286,7 +551,9 @@ export class CoreSelector {
286
551
  if (!this.state)
287
552
  return null;
288
553
  const isSelected = this.state.status === 'itemSelected';
289
- return (h("div", { class: { 'core-selector-wrapper': true, 'is-disabled': !!this.config.disabled }, "aria-disabled": this.config.disabled ? 'true' : 'false', onKeyDown: (e) => this.handleKeyDown(e), onMouseMove: this.handleMouseMove, onFocusin: this.onWrapperFocusIn, onFocusout: this.onWrapperFocusOut }, this.label && (h(AfLabel, { label: this.label, forId: `${this.componentId}-input`, description: this.labelDescription })), this.labelDescription && (h("div", { id: `${this.componentId}-description`, class: "visually-hidden" }, this.labelDescription)), this.state && this.state.status === 'loading' && h("div", { class: "loading-indicator" }, "Laddar..."), this.state && this.state.status === 'error' && h("div", { class: "error-message" }, this.state.message), this.state && ['searching', 'itemSelected', 'multiSelect'].includes(this.state.status) && (h("div", { class: "combobox-container" }, this.renderSearchContainer(), this.isFocusedInternal && !isSelected && this.renderSuggestionsList())), this.state && this.state.validation !== 'idle' && this.state.status !== 'itemSelected' && (h(AfValidationMessage, { id: `${this.componentId}-validation-message`, variant: this.state.validation === 'error' ? 'error' : 'success', role: this.state.validation === 'error' ? 'alert' : undefined, class: "selector-validation-message" }, this.state.message))));
554
+ return (h("div", { class: { 'core-selector-wrapper': true, 'is-disabled': !!this.config.disabled }, "aria-disabled": this.config.disabled ? 'true' : 'false', onKeyDown: (e) => this.handleKeyDown(e), onMouseMove: this.handleMouseMove, onFocusin: this.onWrapperFocusIn, onFocusout: this.onWrapperFocusOut }, this.label && (h(AfLabel, { label: this.label, forId: `${this.componentId}-input`, description: this.labelDescription })), this.labelDescription && (h("div", { id: `${this.componentId}-description`, class: "visually-hidden" }, this.labelDescription)), this.state && this.state.status === 'loading' && h("div", { class: "loading-indicator" }, "Laddar..."), this.state && this.state.status === 'error' && h("div", { class: "error-message" }, this.state.message), this.state && ['searching', 'itemSelected', 'multiSelect'].includes(this.state.status) && (h("div", { class: "combobox-container" }, this.renderSearchContainer(), this.isFocusedInternal && !isSelected && this.renderSuggestionsList())), h("div", { id: `${this.componentId}-validation-alert`, role: "alert" }, this.state && this.state.validation === 'error' && this.state.status !== 'itemSelected' && (h(AfValidationMessage, { id: `${this.componentId}-validation-message`, variant: "error", class: "selector-validation-message" }, this.isValidationMessageHidden
555
+ ? h("span", { class: "af-validation-message__placeholder", "aria-hidden": "true" }, this.state.message)
556
+ : this.state.message))), this.state && this.state.validation === 'success' && this.state.status !== 'itemSelected' && (h(AfValidationMessage, { id: `${this.componentId}-validation-message`, variant: "success", class: "selector-validation-message" }, this.state.message)), h("div", { id: `${this.componentId}-result-count`, class: "visually-hidden", role: "status", "aria-live": "polite", "aria-atomic": "true" }, this.resultAnnouncement)));
290
557
  }
291
558
  renderSearchContainer() {
292
559
  const isSelected = this.state.status === 'itemSelected';
@@ -294,8 +561,9 @@ export class CoreSelector {
294
561
  const isMulti = this.state.status === 'multiSelect';
295
562
  const hasInput = displayValue.length > 0;
296
563
  const hasTags = isMulti && this.state.selectedItems.length > 0;
297
- const hasSuggestions = this.state && (this.state.suggestions.length > 0 || shouldShowManualInput(this.state, this.config.requireSelection));
298
- const activeDescendantId = (this.activeIndex >= 0 && this.isNavigatingWithKeyboard)
564
+ const isExpanded = this.isComboboxExpanded();
565
+ this.renderedExpanded = isExpanded;
566
+ const activeDescendantId = (isExpanded && this.activeIndex >= 0 && this.isNavigatingWithKeyboard && !this.isActiveDescendantDeferred)
299
567
  ? (this.activeIndex === this.state.suggestions.length
300
568
  ? `${this.componentId}-list-option-manual-input`
301
569
  : `${this.componentId}-list-option-${this.activeIndex}`)
@@ -336,15 +604,38 @@ export class CoreSelector {
336
604
  } }), h("div", { class: { 'input-area': true, 'has-value': !this.config.showSearchIcon || hasInput || hasTags } }, isSelected && (h("span", { class: "selected-text-in-box" }, displayValue)), !isSelected && !hasInput && this.config.placeholder && (h("span", { class: "selector-placeholder-overlay", "aria-hidden": "true" }, this.config.placeholder)), h("input", { class: {
337
605
  'selector-input-field': true,
338
606
  'visually-hidden-selected': isSelected
339
- }, ref: (el) => this.inputRef = el, id: `${this.componentId}-input`, type: "text", value: displayValue, maxLength: SELECTOR_INPUT_MAX_LENGTH, onInput: (e) => {
607
+ }, ref: (el) => this.inputRef = el, id: `${this.componentId}-input`, type: "text", value: displayValue, maxLength: SELECTOR_INPUT_MAX_LENGTH, onFocus: () => {
608
+ if (this.config.disabled)
609
+ return;
610
+ if (this.isFocusedInternal)
611
+ return;
612
+ this.isFocusedInternal = true;
613
+ this.activeIndex = -1;
614
+ this.isNavigatingWithKeyboard = false;
615
+ this.isKeyboardNavigationActive = false;
616
+ this.hasTypedSinceFocus = false;
617
+ this.csFocus.emit();
618
+ if (this.state && this.state.inputValue.trim() === '') {
619
+ this.csRequestHistory.emit();
620
+ }
621
+ }, onInput: (e) => {
340
622
  if (this.config.disabled)
341
623
  return;
342
624
  this.isKeyboardNavigationActive = false;
343
625
  this.isNavigatingWithKeyboard = false;
344
- this.csInput.emit(e.target.value);
345
- }, autocomplete: "off", role: "combobox", "aria-label": this.label, "aria-autocomplete": "list", "aria-haspopup": "listbox", "aria-expanded": !isSelected && hasSuggestions && this.isNavigatingWithKeyboard ? 'true' : 'false', "aria-controls": !isSelected && hasSuggestions && this.isNavigatingWithKeyboard ? `${this.componentId}-listbox` : undefined, "aria-activedescendant": activeDescendantId, "aria-invalid": hasError ? 'true' : 'false', "aria-describedby": ariaDescribedBy, readOnly: isSelected, disabled: !!this.config.disabled })), h("button", { type: "button", class: { 'clear-button': true, 'is-visible': hasInput || isSelected }, tabIndex: hasInput || isSelected ? 0 : -1, disabled: !!this.config.disabled, "aria-label": "Rensa inmatad text", onMouseDown: (e) => e.preventDefault(), onClick: () => {
626
+ // Listan kan ha stängts medan fältet behöll fokus, t.ex. efter en spärrad förslagstext.
627
+ this.isFocusedInternal = true;
628
+ const value = e.target.value;
629
+ this.hasTypedSinceFocus = true;
630
+ this.clearDeferredActiveDescendant();
631
+ this.markResultAnnouncementPending(value);
632
+ this.csInput.emit(value);
633
+ }, autocomplete: "off", role: "combobox", "aria-label": this.label, "aria-autocomplete": "list", "aria-haspopup": "listbox", "aria-expanded": isExpanded ? 'true' : 'false', "aria-controls": isExpanded ? `${this.componentId}-listbox` : undefined, "aria-activedescendant": activeDescendantId, "aria-invalid": hasError ? 'true' : 'false', "aria-describedby": ariaDescribedBy, readOnly: isSelected, disabled: !!this.config.disabled })), h("button", { type: "button", class: { 'clear-button': true, 'is-visible': hasInput || isSelected }, tabIndex: hasInput || isSelected ? 0 : -1, disabled: !!this.config.disabled, "aria-label": "Rensa inmatad text", onMouseDown: (e) => e.preventDefault(), onClick: (e) => {
634
+ e.stopPropagation();
346
635
  if (this.config.disabled)
347
636
  return;
637
+ this.isFocusedInternal = true;
638
+ this.clearResultAnnouncement();
348
639
  this.csInput.emit('');
349
640
  this.shouldFocusAfterRender = true;
350
641
  this.csClear.emit();
@@ -369,7 +660,7 @@ export class CoreSelector {
369
660
  }, ref: (el) => (this.listRef = el), onScroll: (e) => this.handleScroll(e), onMouseLeave: this.handleMouseLeave }, (listHeader || showHistoryHeader) && (h("div", { class: "list-header-container" }, h("slot", { name: "suggestions-overlay" }), listHeader && (h("div", { class: "list-header" }, h("span", null, listHeader))), showHistoryHeader && (h("div", { class: "list-header history-header" }, h("span", null, "Din privata historik"), " - ", h("button", { type: "button", class: "history-clear-link", "aria-label": "Rensa historik", disabled: !!this.config.disabled, onMouseDown: (e) => e.preventDefault(), onClick: () => {
370
661
  if (!this.config.disabled)
371
662
  this.csClearHistory.emit();
372
- } }, "Rensa"))))), !listHeader && !showHistoryHeader && h("slot", { name: "suggestions-overlay" }), h("div", { id: `${this.componentId}-listbox`, role: "listbox" }, noResults && (h("div", { class: "suggestion-item no-results" }, "Inga resultat matchade din s\u00F6kning")), !noResults && this.state.suggestions.map((item, index) => (h("div", { key: item.id ? `${item.id}|${item.label}` : index, role: "option", id: `${this.componentId}-list-option-${index}`, "aria-selected": !!item.isSelected, "aria-current": index === this.activeIndex ? 'true' : 'false', class: {
663
+ } }, "Rensa"))))), !listHeader && !showHistoryHeader && h("slot", { name: "suggestions-overlay" }), h("div", { id: `${this.componentId}-listbox`, role: "listbox" }, noResults && (h("div", { class: "suggestion-item no-results" }, "Inga resultat matchade din s\u00F6kning")), this.state.suggestions.map((item, index) => (h("div", { key: item.id ? `${item.id}|${item.label}` : index, role: "option", id: `${this.componentId}-list-option-${index}`, "aria-selected": !!item.isSelected, "aria-current": index === this.activeIndex ? 'true' : 'false', class: {
373
664
  'suggestion-item': true,
374
665
  'active-suggestion': index === this.activeIndex,
375
666
  'is-selected': !!item.isSelected,
@@ -403,7 +694,7 @@ export class CoreSelector {
403
694
  } }, h(AfIcon, { name: "check", class: "selection-indicator-icon" }), item.displaySegments ? (h("span", null, item.displaySegments.map((segment, segmentIndex) => (h("span", { key: segmentIndex, class: {
404
695
  'match-highlight': !!segment.isMatch,
405
696
  'metadata-dimmed': !!segment.isMetadata
406
- } }, segment.text))))) : (h("span", null, item.label))))), !noResults && shouldShowManualInput(this.state, this.config.requireSelection) && (h("div", { role: "option", id: `${this.componentId}-list-option-manual-input`, class: {
697
+ } }, segment.text))))) : (h("span", null, item.label))))), shouldShowManualInput(this.state, this.config.requireSelection) && (h("div", { role: "option", id: `${this.componentId}-list-option-manual-input`, class: {
407
698
  'suggestion-item': true,
408
699
  'active-suggestion': this.activeIndex === this.state.suggestions.length,
409
700
  'is-keyboard-focus': this.activeIndex === this.state.suggestions.length && this.isNavigatingWithKeyboard
@@ -416,7 +707,7 @@ export class CoreSelector {
416
707
  return;
417
708
  this.isNavigatingWithKeyboard = false;
418
709
  this.activeIndex = this.state.suggestions.length;
419
- } }, h("span", null, "Anv\u00E4nd \"", h("strong", null, this.state.inputValue.trim()), "\"")))))));
710
+ } }, h("span", null, this.config.manualInputMode === 'feedback' ? (h("span", null, "Skicka in \"", h("strong", null, this.state.inputValue.trim()), "\" som f\u00F6rslag p\u00E5 ", this.config.feedbackTargetName || 'yrke', " som saknas.")) : this.config.manualInputMode === 'combined' ? (h("span", null, "Anv\u00E4nd \"", h("strong", null, this.state.inputValue.trim()), "\" och skicka in f\u00F6rslaget till Arbetsf\u00F6rmedlingen")) : (h("span", null, "Anv\u00E4nd \"", h("strong", null, this.state.inputValue.trim()), "\"")))))))));
420
711
  }
421
712
  static get is() { return "core-selector"; }
422
713
  static get encapsulation() { return "shadow"; }
@@ -587,7 +878,11 @@ export class CoreSelector {
587
878
  return {
588
879
  "activeIndex": {},
589
880
  "isFocusedInternal": {},
590
- "isNavigatingWithKeyboard": {}
881
+ "isNavigatingWithKeyboard": {},
882
+ "resultAnnouncement": {},
883
+ "isValidationMessageHidden": {},
884
+ "isActiveDescendantDeferred": {},
885
+ "hasTypedSinceFocus": {}
591
886
  };
592
887
  }
593
888
  static get events() {
@@ -4,10 +4,11 @@ const svgMarkup = {
4
4
  check: '<svg width="23" height="18" viewBox="0 0 23 18" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" style="width:100%;height:100%"><path d="M20.547.18L7.315 13.627 2.453 8.686a.597.597 0 00-.853 0L.177 10.132a.62.62 0 000 .868l6.711 6.82c.236.24.618.24.854 0L22.823 2.493a.62.62 0 000-.867L21.4.18a.597.597 0 00-.853 0z" fill="currentColor"/></svg>',
5
5
  x: '<svg width="12" height="12" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" style="width:100%;height:100%"><g stroke="currentColor" stroke-width="2" fill="none" fill-rule="evenodd" stroke-linecap="square"><path d="M2 2l7.986 7.986M9.986 2L2 9.986"/></g></svg>',
6
6
  };
7
- export const AfIcon = ({ name, class: className }) => (h("span", { class: className, "aria-hidden": "true", innerHTML: svgMarkup[name], style: {
8
- display: 'flex',
9
- width: className ? undefined : '12px',
10
- height: className ? undefined : '12px',
11
- minHeight: '1.4em',
12
- alignItems: 'center',
13
- } }));
7
+ // Utseendet ligger i klasserna af-icon och af-icon--default-size i af-design-tokens.css.
8
+ // Använd inte style-objekt här: Stencil ser dem bara i @Component-filer, och utan en
9
+ // sådan komponent i bygget saknar runtime stöd för style-objekt.
10
+ export const AfIcon = ({ name, class: className }) => (h("span", { class: {
11
+ 'af-icon': true,
12
+ 'af-icon--default-size': !className,
13
+ ...(typeof className === 'string' ? { [className]: true } : className),
14
+ }, "aria-hidden": "true", innerHTML: svgMarkup[name] }));
@@ -10,6 +10,8 @@ import { LabelFormatter } from "./logic/label-formatter";
10
10
  export class JobSelectorController {
11
11
  callbacks;
12
12
  config;
13
+ /** Förslagen från den senaste sökningen som kortades av vid maxResults. */
14
+ cappedResults;
13
15
  state = { status: 'loading' };
14
16
  taxonomyData = [];
15
17
  popularItems = [];
@@ -187,8 +189,11 @@ export class JobSelectorController {
187
189
  switch (this.state.status) {
188
190
  case 'searching':
189
191
  case 'multiSelect': {
190
- const genericResults = this.searchEngine.searchAsGeneric(value, this.config.maxResults);
191
- const results = genericResults.flatMap(g => g.metadata?.originalResult ? [g.metadata.originalResult] : []);
192
+ // En träff extra visar om det finns fler än som visas ("Minst N förslag").
193
+ const limit = this.config.maxResults;
194
+ const genericResults = this.searchEngine.searchAsGeneric(value, limit + 1);
195
+ const results = genericResults.slice(0, limit).flatMap(g => g.metadata?.originalResult ? [g.metadata.originalResult] : []);
196
+ this.cappedResults = genericResults.length > limit ? results : undefined;
192
197
  // Do not filter out selected items here - allow UI to handle grey-out
193
198
  this.updateState({ ...this.state, suggestions: results });
194
199
  break;
@@ -276,7 +281,8 @@ export class JobSelectorController {
276
281
  const validatedHistory = displayItems.filter((item) => {
277
282
  // 1. Check if it's a ManualInput item
278
283
  if (item.type === 'ManualInput') {
279
- return !this.config.requireSelection;
284
+ // Fritext från historiken visas bara när integratören tillåter fritext.
285
+ return this.config.manualInput === true;
280
286
  }
281
287
  // 2. Check if it's a valid Taxonomy item (must exist in current data)
282
288
  // Note: We use this.taxonomyData which is already loaded
@@ -817,6 +823,10 @@ export class JobSelectorController {
817
823
  this.selectItem(this.createManualInputItem(value));
818
824
  }
819
825
  }
826
+ /** Om sökningen bakom just dessa förslag hittade fler träffar än som visas. */
827
+ hasMoreResults(suggestions) {
828
+ return !!this.cappedResults && suggestions === this.cappedResults;
829
+ }
820
830
  loadMore() {
821
831
  // Increment maxResults or handle paging if supported by searchEngine
822
832
  this.config.maxResults += 10;