@aurodesignsystem/auro-formkit 3.0.1 → 3.1.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 (59) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/components/checkbox/README.md +1 -1
  3. package/components/checkbox/demo/api.min.js +468 -25
  4. package/components/checkbox/demo/index.min.js +468 -25
  5. package/components/checkbox/demo/readme.md +1 -1
  6. package/components/checkbox/dist/index.js +468 -25
  7. package/components/checkbox/dist/registered.js +468 -25
  8. package/components/combobox/README.md +1 -1
  9. package/components/combobox/demo/api.min.js +1125 -74
  10. package/components/combobox/demo/index.min.js +1125 -74
  11. package/components/combobox/demo/readme.md +1 -1
  12. package/components/combobox/dist/auro-combobox.d.ts +30 -0
  13. package/components/combobox/dist/index.js +1125 -74
  14. package/components/combobox/dist/registered.js +1125 -74
  15. package/components/counter/README.md +1 -1
  16. package/components/counter/demo/api.min.js +570 -45
  17. package/components/counter/demo/index.min.js +570 -45
  18. package/components/counter/demo/readme.md +1 -1
  19. package/components/counter/dist/index.js +570 -45
  20. package/components/counter/dist/registered.js +570 -45
  21. package/components/datepicker/README.md +1 -1
  22. package/components/datepicker/demo/api.min.js +1073 -70
  23. package/components/datepicker/demo/index.min.js +1073 -70
  24. package/components/datepicker/demo/readme.md +1 -1
  25. package/components/datepicker/dist/index.js +1073 -70
  26. package/components/datepicker/dist/registered.js +1073 -70
  27. package/components/dropdown/README.md +1 -1
  28. package/components/dropdown/demo/api.md +8 -5
  29. package/components/dropdown/demo/api.min.js +104 -22
  30. package/components/dropdown/demo/index.min.js +104 -22
  31. package/components/dropdown/demo/readme.md +1 -1
  32. package/components/dropdown/dist/auro-dropdown.d.ts +29 -0
  33. package/components/dropdown/dist/index.js +104 -22
  34. package/components/dropdown/dist/registered.js +104 -22
  35. package/components/form/README.md +1 -1
  36. package/components/form/demo/readme.md +1 -1
  37. package/components/input/README.md +1 -1
  38. package/components/input/demo/api.md +4 -1
  39. package/components/input/demo/api.min.js +503 -25
  40. package/components/input/demo/index.min.js +503 -25
  41. package/components/input/demo/readme.md +1 -1
  42. package/components/input/dist/base-input.d.ts +24 -0
  43. package/components/input/dist/index.js +503 -25
  44. package/components/input/dist/registered.js +503 -25
  45. package/components/menu/README.md +1 -1
  46. package/components/menu/demo/readme.md +1 -1
  47. package/components/radio/README.md +1 -1
  48. package/components/radio/demo/api.min.js +468 -25
  49. package/components/radio/demo/index.min.js +468 -25
  50. package/components/radio/demo/readme.md +1 -1
  51. package/components/radio/dist/index.js +468 -25
  52. package/components/radio/dist/registered.js +468 -25
  53. package/components/select/README.md +1 -1
  54. package/components/select/demo/api.min.js +570 -45
  55. package/components/select/demo/index.min.js +570 -45
  56. package/components/select/demo/readme.md +1 -1
  57. package/components/select/dist/index.js +570 -45
  58. package/components/select/dist/registered.js +570 -45
  59. package/package.json +2 -2
@@ -136,6 +136,414 @@ const t={ATTRIBUTE:1},e$1=t=>(...e)=>({_$litDirective$:t,values:e});let i$1 = cl
136
136
  */
137
137
  const a=Symbol.for(""),o$1=t=>{if(t?.r===a)return t?._$litStatic$},s=t=>({_$litStatic$:t,r:a}),i=(t,...r)=>({_$litStatic$:r.reduce(((r,e,a)=>r+(t=>{if(void 0!==t._$litStatic$)return t._$litStatic$;throw Error(`Value passed to 'literal' function must be a 'literal' result: ${t}. Use 'unsafeStatic' to pass non-literal values, but\n take care to ensure page security.`)})(e)+t[a+1]),t[0]),r:a}),l=new Map,n=t=>(r,...e)=>{const a=e.length;let s,i;const n=[],u=[];let c,$=0,f=false;for(;$<a;){for(c=r[$];$<a&&void 0!==(i=e[$],s=o$1(i));)c+=s+r[++$],f=true;$!==a&&u.push(i),n.push(c),$++;}if($===a&&n.push(r[a]),f){const t=n.join("$$lit$$");void 0===(r=l.get(t))&&(n.raw=n,l.set(t,r=n)),e=u;}return t(r,...e)},u=n(x);
138
138
 
139
+ class DateFormatter {
140
+
141
+ constructor() {
142
+
143
+ /**
144
+ * @description Parses a date string into its components.
145
+ * @param {string} dateStr - Date string to parse.
146
+ * @param {string} format - Date format to parse.
147
+ * @returns {Object<key["month" | "day" | "year"]: number>|undefined}
148
+ */
149
+ this.parseDate = (dateStr, format = 'mm/dd/yyyy') => {
150
+
151
+ // Guard Clause: Date string is defined
152
+ if (!dateStr) {
153
+ return undefined;
154
+ }
155
+
156
+ // Assume the separator is a "/" a defined in our code base
157
+ const separator = '/';
158
+
159
+ // Get the parts of the date and format
160
+ const valueParts = dateStr.split(separator);
161
+ const formatParts = format.split(separator);
162
+
163
+ // Check if the value and format have the correct number of parts
164
+ if (valueParts.length !== formatParts.length) {
165
+ throw new Error('AuroDatepickerUtilities | parseDate: Date string and format length do not match');
166
+ }
167
+
168
+ // Holds the result to be returned
169
+ const result = formatParts.reduce((acc, part, index) => {
170
+ const value = valueParts[index];
171
+
172
+ if ((/m/iu).test(part)) {
173
+ acc.month = value;
174
+ } else if ((/d/iu).test(part)) {
175
+ acc.day = value;
176
+ } else if ((/y/iu).test(part)) {
177
+ acc.year = value;
178
+ }
179
+
180
+ return acc;
181
+ }, {});
182
+
183
+ // If we found all the parts, return the result
184
+ if (result.month && result.year) {
185
+ return result;
186
+ }
187
+
188
+ // Throw an error to let the dev know we were unable to parse the date string
189
+ throw new Error('AuroDatepickerUtilities | parseDate: Unable to parse date string');
190
+ };
191
+
192
+ /**
193
+ * Convert a date object to string format.
194
+ * @param {Object} date - Date to convert to string.
195
+ * @returns {Object} Returns the date as a string.
196
+ */
197
+ this.getDateAsString = (date) => date.toLocaleDateString(undefined, {
198
+ year: "numeric",
199
+ month: "2-digit",
200
+ day: "2-digit",
201
+ });
202
+
203
+ /**
204
+ * Converts a date string to a North American date format.
205
+ * @param {String} dateStr - Date to validate.
206
+ * @param {String} format - Date format to validate against.
207
+ * @returns {Boolean}
208
+ */
209
+ this.toNorthAmericanFormat = (dateStr, format) => {
210
+
211
+ if (format === 'mm/dd/yyyy') {
212
+ return dateStr;
213
+ }
214
+
215
+ const parsedDate = this.parseDate(dateStr, format);
216
+
217
+ if (!parsedDate) {
218
+ throw new Error('AuroDatepickerUtilities | toNorthAmericanFormat: Unable to parse date string');
219
+ }
220
+
221
+ const { month, day, year } = parsedDate;
222
+
223
+ const dateParts = [];
224
+ if (month) {
225
+ dateParts.push(month);
226
+ }
227
+
228
+ if (day) {
229
+ dateParts.push(day);
230
+ }
231
+
232
+ if (year) {
233
+ dateParts.push(year);
234
+ }
235
+
236
+ return dateParts.join('/');
237
+ };
238
+ }
239
+ }
240
+ const dateFormatter = new DateFormatter();
241
+
242
+ // filepath: dateConstraints.mjs
243
+ const DATE_UTIL_CONSTRAINTS = {
244
+ maxDay: 31,
245
+ maxMonth: 12,
246
+ maxYear: 2400,
247
+ minDay: 1,
248
+ minMonth: 1,
249
+ minYear: 1900,
250
+ };
251
+
252
+ class AuroDateUtilitiesBase {
253
+
254
+ /**
255
+ * @description The maximum day value allowed by the various utilities in this class.
256
+ * @readonly
257
+ * @type {Number}
258
+ */
259
+ get maxDay() {
260
+ return DATE_UTIL_CONSTRAINTS.maxDay;
261
+ }
262
+
263
+ /**
264
+ * @description The maximum month value allowed by the various utilities in this class.
265
+ * @readonly
266
+ * @type {Number}
267
+ */
268
+ get maxMonth() {
269
+ return DATE_UTIL_CONSTRAINTS.maxMonth;
270
+ }
271
+
272
+ /**
273
+ * @description The maximum year value allowed by the various utilities in this class.
274
+ * @readonly
275
+ * @type {Number}
276
+ */
277
+ get maxYear() {
278
+ return DATE_UTIL_CONSTRAINTS.maxYear;
279
+ }
280
+
281
+ /**
282
+ * @description The minimum day value allowed by the various utilities in this class.
283
+ * @readonly
284
+ * @type {Number}
285
+ */
286
+ get minDay() {
287
+ return DATE_UTIL_CONSTRAINTS.minDay;
288
+ }
289
+
290
+ /**
291
+ * @description The minimum month value allowed by the various utilities in this class.
292
+ * @readonly
293
+ * @type {Number}
294
+ */
295
+ get minMonth() {
296
+ return DATE_UTIL_CONSTRAINTS.minMonth;
297
+ }
298
+
299
+ /**
300
+ * @description The minimum year value allowed by the various utilities in this class.
301
+ * @readonly
302
+ * @type {Number}
303
+ */
304
+ get minYear() {
305
+ return DATE_UTIL_CONSTRAINTS.minYear;
306
+ }
307
+ }
308
+
309
+ /* eslint-disable no-magic-numbers */
310
+
311
+ class AuroDateUtilities extends AuroDateUtilitiesBase {
312
+
313
+ /**
314
+ * Returns the current century.
315
+ * @returns {String} The current century.
316
+ */
317
+ getCentury () {
318
+ return String(new Date().getFullYear()).slice(0, 2);
319
+ }
320
+
321
+ /**
322
+ * Returns a four digit year.
323
+ * @param {String} year - The year to convert to four digits.
324
+ * @returns {String} The four digit year.
325
+ */
326
+ getFourDigitYear (year) {
327
+
328
+ const strYear = String(year).trim();
329
+ return strYear.length <= 2 ? this.getCentury() + strYear : strYear;
330
+ }
331
+
332
+ constructor() {
333
+
334
+ super();
335
+
336
+ /**
337
+ * Compares two dates to see if they match.
338
+ * @param {Object} date1 - First date to compare.
339
+ * @param {Object} date2 - Second date to compare.
340
+ * @returns {Boolean} Returns true if the dates match.
341
+ */
342
+ this.datesMatch = (date1, date2) => new Date(date1).getTime() === new Date(date2).getTime();
343
+
344
+ /**
345
+ * Returns true if value passed in is a valid date.
346
+ * @param {String} date - Date to validate.
347
+ * @param {String} format - Date format to validate against.
348
+ * @returns {Boolean}
349
+ */
350
+ this.validDateStr = (date, format) => {
351
+
352
+ // The length we expect the date string to be
353
+ const dateStrLength = format.length;
354
+
355
+ // Guard Clause: Date and format are defined
356
+ if (typeof date === "undefined" || typeof format === "undefined") {
357
+ throw new Error('AuroDatepickerUtilities | validateDateStr: Date and format are required');
358
+ }
359
+
360
+ // Guard Clause: Date should be of type string
361
+ if (typeof date !== "string") {
362
+ throw new Error('AuroDatepickerUtilities | validateDateStr: Date must be a string');
363
+ }
364
+
365
+ // Guard Clause: Format should be of type string
366
+ if (typeof format !== "string") {
367
+ throw new Error('AuroDatepickerUtilities | validateDateStr: Format must be a string');
368
+ }
369
+
370
+ // Guard Clause: Length is what we expect it to be
371
+ if (date.length !== dateStrLength) {
372
+ return false;
373
+ }
374
+ // Get a formatted date string and parse it
375
+ const dateParts = dateFormatter.parseDate(date, format);
376
+
377
+ // Guard Clause: Date parse succeeded
378
+ if (!dateParts) {
379
+ return false;
380
+ }
381
+
382
+ // Create the expected date string based on the date parts
383
+ const expectedDateStr = `${dateParts.month}/${dateParts.day || "01"}/${this.getFourDigitYear(dateParts.year)}`;
384
+
385
+ // Generate a date object that we will extract a string date from to compare to the passed in date string
386
+ const dateObj = new Date(this.getFourDigitYear(dateParts.year), dateParts.month - 1, dateParts.day || 1);
387
+
388
+ // Get the date string of the date object we created from the string date
389
+ const actualDateStr = dateFormatter.getDateAsString(dateObj);
390
+
391
+ // Guard Clause: Generated date matches date string input
392
+ if (expectedDateStr !== actualDateStr) {
393
+ return false;
394
+ }
395
+
396
+ // If we passed all other checks, we can assume the date is valid
397
+ return true;
398
+ };
399
+
400
+ /**
401
+ * Determines if a string date value matches the format provided.
402
+ * @param {string} value = The date string value.
403
+ * @param { string} format = The date format to match against.
404
+ * @returns {boolean}
405
+ */
406
+ this.dateAndFormatMatch = (value, format) => {
407
+
408
+ // Ensure we have both values we need to do the comparison
409
+ if (!value || !format) {
410
+ throw new Error('AuroFormValidation | dateFormatMatch: value and format are required');
411
+ }
412
+
413
+ // If the lengths are different, they cannot match
414
+ if (value.length !== format.length) {
415
+ return false;
416
+ }
417
+
418
+ // Get the parts of the date
419
+ const dateParts = dateFormatter.parseDate(value, format);
420
+
421
+ // Validator for day
422
+ const dayValueIsValid = (day) => {
423
+
424
+ // Guard clause: if there is no day in the dateParts, we can ignore this check.
425
+ if (!dateParts.day) {
426
+ return true;
427
+ }
428
+
429
+ // Guard clause: ensure day exists.
430
+ if (!day) {
431
+ return false;
432
+ }
433
+
434
+ // Convert day to number
435
+ const numDay = Number.parseInt(day, 10);
436
+
437
+ // Guard clause: ensure day is a valid integer
438
+ if (Number.isNaN(numDay)) {
439
+ throw new Error('AuroDatepickerUtilities | dayValueIsValid: Unable to parse day value integer');
440
+ }
441
+
442
+ // Guard clause: ensure day is within the valid range
443
+ if (numDay < this.minDay || numDay > this.maxDay) {
444
+ return false;
445
+ }
446
+
447
+ // Default return
448
+ return true;
449
+ };
450
+
451
+ // Validator for month
452
+ const monthValueIsValid = (month) => {
453
+
454
+ // Guard clause: ensure month exists.
455
+ if (!month) {
456
+ return false;
457
+ }
458
+
459
+ // Convert month to number
460
+ const numMonth = Number.parseInt(month, 10);
461
+
462
+ // Guard clause: ensure month is a valid integer
463
+ if (Number.isNaN(numMonth)) {
464
+ throw new Error('AuroDatepickerUtilities | monthValueIsValid: Unable to parse month value integer');
465
+ }
466
+
467
+ // Guard clause: ensure month is within the valid range
468
+ if (numMonth < this.minMonth || numMonth > this.maxMonth) {
469
+ return false;
470
+ }
471
+
472
+ // Default return
473
+ return true;
474
+ };
475
+
476
+ // Validator for year
477
+ const yearIsValid = (_year) => {
478
+
479
+ // Guard clause: ensure year exists.
480
+ if (!_year) {
481
+ return false;
482
+ }
483
+
484
+ // Get the full year
485
+ const year = this.getFourDigitYear(_year);
486
+
487
+ // Convert year to number
488
+ const numYear = Number.parseInt(year, 10);
489
+
490
+ // Guard clause: ensure year is a valid integer
491
+ if (Number.isNaN(numYear)) {
492
+ throw new Error('AuroDatepickerUtilities | yearValueIsValid: Unable to parse year value integer');
493
+ }
494
+
495
+ // Guard clause: ensure year is within the valid range
496
+ if (numYear < this.minYear || numYear > this.maxYear) {
497
+ return false;
498
+ }
499
+
500
+ // Default return
501
+ return true;
502
+ };
503
+
504
+ // Self-contained checks for month, day, and year
505
+ const checks = [
506
+ monthValueIsValid(dateParts.month),
507
+ dayValueIsValid(dateParts.day),
508
+ yearIsValid(dateParts.year)
509
+ ];
510
+
511
+ // If any of the checks failed, the date format does not match and the result is invalid
512
+ const isValid = checks.every((check) => check === true);
513
+
514
+ // If the check is invalid, return false
515
+ if (!isValid) {
516
+ return false;
517
+ }
518
+
519
+ // Default case
520
+ return true;
521
+ };
522
+ }
523
+ }
524
+
525
+ // Export a class instance
526
+ const dateUtilities = new AuroDateUtilities();
527
+
528
+ // Export the class instance methods individually
529
+ const {
530
+ datesMatch,
531
+ validDateStr,
532
+ dateAndFormatMatch,
533
+ minDay,
534
+ minMonth,
535
+ minYear,
536
+ maxDay,
537
+ maxMonth,
538
+ maxYear
539
+ } = dateUtilities;
540
+
541
+ const {
542
+ toNorthAmericanFormat,
543
+ parseDate,
544
+ getDateAsString
545
+ } = dateFormatter;
546
+
139
547
  // Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
140
548
  // See LICENSE in the project root for license information.
141
549
 
@@ -211,6 +619,7 @@ let AuroLibraryRuntimeUtils$3 = class AuroLibraryRuntimeUtils {
211
619
 
212
620
 
213
621
  class AuroFormValidation {
622
+
214
623
  constructor() {
215
624
  this.runtimeUtils = new AuroLibraryRuntimeUtils$3();
216
625
  }
@@ -302,17 +711,17 @@ class AuroFormValidation {
302
711
  ]
303
712
  }
304
713
  };
305
-
714
+
306
715
  let elementType;
307
716
  if (this.runtimeUtils.elementMatch(elem, 'auro-input')) {
308
717
  elementType = 'input';
309
718
  } else if (this.runtimeUtils.elementMatch(elem, 'auro-counter') || this.runtimeUtils.elementMatch(elem, 'auro-counter-group')) {
310
719
  elementType = 'counter';
311
720
  }
312
-
721
+
313
722
  if (elementType) {
314
723
  const rules = validationRules[elementType];
315
-
724
+
316
725
  if (rules) {
317
726
  Object.values(rules).flat().forEach(rule => {
318
727
  if (rule.check(elem)) {
@@ -338,48 +747,82 @@ class AuroFormValidation {
338
747
  if (!elem.value.match(emailRegex)) {
339
748
  elem.validity = 'patternMismatch';
340
749
  elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
750
+ return;
341
751
  }
342
752
  } else if (elem.type === 'credit-card') {
343
753
  if (elem.value.length > 0 && elem.value.length < elem.validationCCLength) {
344
754
  elem.validity = 'tooShort';
345
755
  elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
756
+ return;
346
757
  }
347
758
  } else if (elem.type === 'number') {
348
759
  if (elem.max !== undefined && Number(elem.max) < Number(elem.value)) {
349
760
  elem.validity = 'rangeOverflow';
350
761
  elem.errorMessage = elem.setCustomValidityRangeOverflow || elem.setCustomValidity || '';
762
+ return;
351
763
  }
352
764
 
353
765
  if (elem.min !== undefined && elem.value?.length > 0 && Number(elem.min) > Number(elem.value)) {
354
766
  elem.validity = 'rangeUnderflow';
355
767
  elem.errorMessage = elem.setCustomValidityRangeUnderflow || elem.setCustomValidity || '';
768
+ return;
356
769
  }
357
- } else if (elem.type === 'date') {
358
- if (elem.value?.length > 0 && elem.value?.length < elem.lengthForType) {
770
+ } else if (elem.type === 'date' && elem.value?.length > 0) {
771
+
772
+ // Guard Clause: if the value is too short
773
+ if (elem.value.length < elem.lengthForType) {
774
+
359
775
  elem.validity = 'tooShort';
360
776
  elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
361
- } else if (elem.value?.length === elem.lengthForType && elem.util.toNorthAmericanFormat(elem.value, elem.format)) {
362
- const formattedValue = elem.util.toNorthAmericanFormat(elem.value, elem.format);
363
- const valueDate = new Date(formattedValue.dateForComparison);
777
+ return;
778
+ }
779
+
780
+ // Guard Clause: If the value is too long for the type
781
+ if (elem.value?.length > elem.lengthForType) {
364
782
 
365
- // validate max
366
- if (elem.max?.length === elem.lengthForType) {
367
- const maxDate = new Date(elem.util.toNorthAmericanFormat(elem.max, elem.format).dateForComparison);
783
+ elem.validity = 'tooLong';
784
+ elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
785
+ return;
786
+ }
787
+
788
+ // Validate that the date passed was the correct format
789
+ if (!dateAndFormatMatch(elem.value, elem.format)) {
790
+ elem.validity = 'patternMismatch';
791
+ elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || 'Invalid Date Format Entered';
792
+ return;
793
+ }
794
+
795
+ // Validate that the date passed was a valid date
796
+ if (!validDateStr(elem.value, elem.format)) {
797
+ elem.validity = 'invalidDate';
798
+ elem.errorMessage = elem.setCustomValidityInvalidDate || elem.setCustomValidity || 'Invalid Date Entered';
799
+ return;
800
+ }
368
801
 
369
- if (valueDate > maxDate) {
370
- elem.validity = 'rangeOverflow';
371
- elem.errorMessage = elem.setCustomValidityRangeOverflow || elem.setCustomValidity || '';
372
- }
802
+ // Perform the rest of the validation
803
+ const formattedValue = toNorthAmericanFormat(elem.value, elem.format);
804
+ const valueDate = new Date(formattedValue);
805
+
806
+ // // Validate max date
807
+ if (elem.max?.length === elem.lengthForType) {
808
+
809
+ const maxDate = new Date(toNorthAmericanFormat(elem.max, elem.format));
810
+
811
+ if (valueDate > maxDate) {
812
+ elem.validity = 'rangeOverflow';
813
+ elem.errorMessage = elem.setCustomValidityRangeOverflow || elem.setCustomValidity || '';
814
+ return;
373
815
  }
816
+ }
374
817
 
375
- // validate min
376
- if (elem.min?.length === elem.lengthForType) {
377
- const minDate = new Date(elem.util.toNorthAmericanFormat(elem.min, elem.format).dateForComparison);
818
+ // Validate min date
819
+ if (elem.min?.length === elem.lengthForType) {
820
+ const minDate = new Date(toNorthAmericanFormat(elem.min, elem.format));
378
821
 
379
- if (valueDate < minDate) {
380
- elem.validity = 'rangeUnderflow';
381
- elem.errorMessage = elem.setCustomValidityRangeUnderflow || elem.setCustomValidity || '';
382
- }
822
+ if (valueDate < minDate) {
823
+ elem.validity = 'rangeUnderflow';
824
+ elem.errorMessage = elem.setCustomValidityRangeUnderflow || elem.setCustomValidity || '';
825
+ return;
383
826
  }
384
827
  }
385
828
  }
@@ -498,7 +941,7 @@ class AuroFormValidation {
498
941
  if (input.validationMessage.length > 0) {
499
942
  elem.errorMessage = input.validationMessage;
500
943
  }
501
- } else if (this.inputElements?.length > 0 && elem.errorMessage === '') {
944
+ } else if (this.inputElements?.length > 0 && elem.errorMessage === '') {
502
945
  const firstInput = this.inputElements[0];
503
946
 
504
947
  if (firstInput.validationMessage.length > 0) {
@@ -2406,7 +2849,7 @@ class AuroFloatingUI {
2406
2849
  /**
2407
2850
  * @private
2408
2851
  * getting called on 'blur' in trigger or `focusin` in document
2409
- *
2852
+ *
2410
2853
  * Hides the bib if focus moves outside of the trigger or bib, unless a 'noHideOnThisFocusLoss' flag is set.
2411
2854
  * This method checks if the currently active element is still within the trigger or bib.
2412
2855
  * If not, and if the bib isn't in fullscreen mode with focus lost, it hides the bib.
@@ -2522,7 +2965,7 @@ class AuroFloatingUI {
2522
2965
  // Close any other dropdown that is already open
2523
2966
  const existedVisibleFloatingUI = document.expandedAuroFormkitDropdown || document.expandedAuroFloater;
2524
2967
  if (existedVisibleFloatingUI && existedVisibleFloatingUI !== this &&
2525
- existedVisibleFloatingUI.isPopoverVisible &&
2968
+ existedVisibleFloatingUI.element.isPopoverVisible &&
2526
2969
  document.expandedAuroFloater.eventPrefix === this.eventPrefix) {
2527
2970
  document.expandedAuroFloater.hideBib();
2528
2971
  }
@@ -2698,7 +3141,7 @@ class AuroFloatingUI {
2698
3141
  this.id = window.crypto.randomUUID();
2699
3142
  this.element.setAttribute('id', this.id);
2700
3143
  }
2701
-
3144
+
2702
3145
  this.element.bib.setAttribute("id", `${this.id}-floater-bib`);
2703
3146
  }
2704
3147
 
@@ -2751,7 +3194,7 @@ class AuroFloatingUI {
2751
3194
  if (this.element.bib) {
2752
3195
  this.element.shadowRoot.append(this.element.bib);
2753
3196
  }
2754
-
3197
+
2755
3198
  // Remove event & keyboard listeners
2756
3199
  if (this.element?.trigger) {
2757
3200
  this.element.trigger.removeEventListener('keydown', this.handleEvent);
@@ -3480,6 +3923,7 @@ var helpTextVersion = '1.0.0';
3480
3923
  * @csspart helpText - The helpText content container.
3481
3924
  * @event auroDropdown-triggerClick - Notifies that the trigger has been clicked.
3482
3925
  * @event auroDropdown-toggled - Notifies that the visibility of the dropdown bib has changed.
3926
+ * @event auroDropdown-idAdded - Notifies consumers that the unique ID for the dropdown bib has been generated.
3483
3927
  */
3484
3928
  class AuroDropdown extends r {
3485
3929
  constructor() {
@@ -3525,7 +3969,9 @@ class AuroDropdown extends r {
3525
3969
  this.rounded = false;
3526
3970
  this.tabIndex = 0;
3527
3971
  this.noToggle = false;
3972
+ this.a11yAutocomplete = 'none';
3528
3973
  this.labeled = true;
3974
+ this.a11yRole = 'combobox';
3529
3975
  this.onDark = false;
3530
3976
 
3531
3977
  // floaterConfig
@@ -3661,6 +4107,16 @@ class AuroDropdown extends r {
3661
4107
  type: Number
3662
4108
  },
3663
4109
 
4110
+ /**
4111
+ * The unique ID for the dropdown bib element.
4112
+ * @private
4113
+ */
4114
+ dropdownId: {
4115
+ type: String,
4116
+ reflect: false,
4117
+ attribute: false
4118
+ },
4119
+
3664
4120
  /**
3665
4121
  * If declared in combination with `bordered` property or `helpText` slot content, will apply red color to both.
3666
4122
  */
@@ -3823,6 +4279,23 @@ class AuroDropdown extends r {
3823
4279
  */
3824
4280
  tabIndex: {
3825
4281
  type: Number
4282
+ },
4283
+
4284
+ /**
4285
+ * The value for the role attribute of the trigger element.
4286
+ */
4287
+ a11yRole: {
4288
+ type: String || undefined,
4289
+ attribute: false,
4290
+ reflect: false
4291
+ },
4292
+
4293
+ /**
4294
+ * The value for the aria-autocomplete attribute of the trigger element.
4295
+ */
4296
+ a11yAutocomplete: {
4297
+ type: String,
4298
+ attribute: false,
3826
4299
  }
3827
4300
  };
3828
4301
  }
@@ -3873,7 +4346,22 @@ class AuroDropdown extends r {
3873
4346
  }
3874
4347
 
3875
4348
  firstUpdated() {
4349
+
4350
+ // Configure the floater to, this will generate the ID for the bib
3876
4351
  this.floater.configure(this, 'auroDropdown');
4352
+
4353
+ /**
4354
+ * @description Let subscribers know that the dropdown ID ha been generated and added.
4355
+ * @event auroDropdown-idAdded
4356
+ * @type {Object<key: 'id', value: string>} - The ID of the dropdown bib element.
4357
+ */
4358
+ this.dispatchEvent(new CustomEvent('auroDropdown-idAdded', {detail: {id: this.floater.element.id}}));
4359
+
4360
+ // Set the bib ID locally if the user hasn't provided a focusable trigger
4361
+ if (!this.triggerContentFocusable) {
4362
+ this.dropdownId = this.floater.element.id;
4363
+ }
4364
+
3877
4365
  this.bibContent = this.floater.element.bib;
3878
4366
 
3879
4367
  // Add the tag name as an attribute if it is different than the component name
@@ -4025,6 +4513,30 @@ class AuroDropdown extends r {
4025
4513
  });
4026
4514
  }
4027
4515
 
4516
+ /*
4517
+ * Sets aria attributes for the trigger element if a custom one is passed in.
4518
+ * @private
4519
+ * @method setTriggerAriaAttributes
4520
+ * @param { HTMLElement } triggerElement - The custom trigger element.
4521
+ */
4522
+ clearTriggerA11yAttributes(triggerElement) {
4523
+
4524
+ if (!triggerElement || !triggerElement.removeAttribute) {
4525
+ return;
4526
+ }
4527
+
4528
+ // Reset appropriate attributes for a11y
4529
+ triggerElement.removeAttribute('aria-labelledby');
4530
+ if (triggerElement.getAttribute('id') === `${this.id}-trigger-element`) {
4531
+ triggerElement.removeAttribute('id');
4532
+ }
4533
+ triggerElement.removeAttribute('role');
4534
+ triggerElement.removeAttribute('aria-expanded');
4535
+
4536
+ triggerElement.removeAttribute('aria-controls');
4537
+ triggerElement.removeAttribute('aria-autocomplete');
4538
+ }
4539
+
4028
4540
  /**
4029
4541
  * Handles changes to the trigger content slot and updates related properties.
4030
4542
  *
@@ -4038,32 +4550,41 @@ class AuroDropdown extends r {
4038
4550
  * @returns {void}
4039
4551
  */
4040
4552
  handleTriggerContentSlotChange(event) {
4553
+
4041
4554
  this.floater.handleTriggerTabIndex();
4042
4555
 
4556
+ // Get the trigger
4557
+ const trigger = this.shadowRoot.querySelector('#trigger');
4558
+
4559
+ // Get the trigger slot
4043
4560
  const triggerSlot = this.shadowRoot.querySelector('.triggerContent slot');
4044
4561
 
4562
+ // If there's a trigger slot
4045
4563
  if (triggerSlot) {
4046
4564
 
4565
+ // Get the content nodes to see if there are any children
4047
4566
  const triggerContentNodes = triggerSlot.assignedNodes();
4048
4567
 
4568
+ // If there are children
4049
4569
  if (triggerContentNodes) {
4050
4570
 
4051
- triggerContentNodes.forEach((node) => {
4052
- if (!this.triggerContentFocusable) {
4053
- this.triggerContentFocusable = this.containsFocusableElement(node);
4054
- }
4055
- });
4056
- }
4057
- }
4571
+ // See if any of them are focusable elemeents
4572
+ this.triggerContentFocusable = triggerContentNodes.some((node) => this.containsFocusableElement(node));
4058
4573
 
4059
- const trigger = this.shadowRoot.querySelector('#trigger');
4574
+ // If any of them are focusable elements
4575
+ if (this.triggerContentFocusable) {
4060
4576
 
4061
- if (!this.triggerContentFocusable) {
4062
- trigger.setAttribute('tabindex', '0');
4063
- trigger.setAttribute('role', 'button');
4064
- } else {
4065
- trigger.removeAttribute('tabindex');
4066
- trigger.removeAttribute('role');
4577
+ // Assume the consumer will be providing their own a11y in whatever they passed in
4578
+ this.clearTriggerA11yAttributes(trigger);
4579
+
4580
+ // Remove the tabindex from the trigger so it doesn't interrupt focus flow
4581
+ trigger.removeAttribute('tabindex');
4582
+ } else {
4583
+
4584
+ // Add the tabindex to the trigger so that it's in the focus flow
4585
+ trigger.setAttribute('tabindex', '0');
4586
+ }
4587
+ }
4067
4588
  }
4068
4589
 
4069
4590
  if (event) {
@@ -4073,6 +4594,7 @@ class AuroDropdown extends r {
4073
4594
 
4074
4595
  if (this.triggerContentSlot) {
4075
4596
  this.setupTriggerFocusEventBinding();
4597
+
4076
4598
  this.hasTriggerContent = this.triggerContentSlot.some((slot) => {
4077
4599
  if (slot.textContent.trim()) {
4078
4600
  return true;
@@ -4140,10 +4662,13 @@ class AuroDropdown extends r {
4140
4662
  id="trigger"
4141
4663
  class="trigger"
4142
4664
  part="trigger"
4143
- aria-labelledby="triggerLabel"
4144
4665
  tabindex="${this.tabIndex}"
4145
4666
  ?showBorder="${this.showTriggerBorders}"
4146
- >
4667
+ role="${o(this.triggerContentFocusable ? undefined : this.a11yRole)}"
4668
+ aria-expanded="${o(this.triggerContentFocusable ? undefined : this.isPopoverVisible)}"
4669
+ aria-controls="${o(this.triggerContentFocusable ? undefined : this.dropdownId)}"
4670
+ aria-labelledby="${o(this.triggerContentFocusable ? undefined : 'triggerLabel')}"
4671
+ >
4147
4672
  <div class="triggerContentWrapper">
4148
4673
  <label class="label" id="triggerLabel" hasTrigger=${this.hasTriggerContent}>
4149
4674
  <slot name="label" @slotchange="${this.handleLabelSlotChange}"></slot>
@@ -4177,12 +4702,12 @@ class AuroDropdown extends r {
4177
4702
  <div id="bibSizer" part="size"></div>
4178
4703
  <${this.dropdownBibTag}
4179
4704
  id="bib"
4180
- role="tooltip"
4181
4705
  ?data-show="${this.isPopoverVisible}"
4182
4706
  ?isfullscreen="${this.isBibFullscreen}"
4183
4707
  ?common="${this.common}"
4184
4708
  ?rounded="${this.common || this.rounded}"
4185
- ?inset="${this.common || this.inset}">
4709
+ ?inset="${this.common || this.inset}"
4710
+ >
4186
4711
  </${this.dropdownBibTag}>
4187
4712
  </div>
4188
4713
  `;