@reliability-design/web 1.4.4 → 1.4.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 (39) hide show
  1. package/dist/components/rel-accordion/rel-accordion.ts +13 -1
  2. package/dist/components/rel-button/rel-button.ts +18 -2
  3. package/dist/components/rel-calendar/rel-calendar.ts +23 -1
  4. package/dist/components/rel-carousel/rel-carousel.ts +20 -0
  5. package/dist/components/rel-checkbox/rel-checkbox.ts +4 -1
  6. package/dist/components/rel-chip/rel-chip.ts +29 -0
  7. package/dist/components/rel-date-picker/rel-date-picker.ts +156 -13
  8. package/dist/components/rel-drawer/rel-drawer.ts +22 -58
  9. package/dist/components/rel-menu/rel-menu.ts +124 -15
  10. package/dist/components/rel-menubar/rel-menubar.ts +221 -63
  11. package/dist/components/rel-nav-menu/rel-nav-menu.ts +39 -3
  12. package/dist/components/rel-otp/rel-otp.ts +3 -3
  13. package/dist/components/rel-popover/rel-popover.ts +31 -3
  14. package/dist/components/rel-range-picker/rel-range-picker.ts +134 -1
  15. package/dist/components/rel-resizable/rel-resizable-group.ts +20 -0
  16. package/dist/components/rel-segmented-button/rel-segmented-button.ts +50 -12
  17. package/dist/components/rel-select/rel-select.ts +159 -11
  18. package/dist/components/rel-sheet/rel-sheet.ts +22 -1
  19. package/dist/components/rel-sidebar/rel-sidebar.ts +43 -39
  20. package/dist/components/rel-stepper/rel-stepper.ts +44 -1
  21. package/dist/components/rel-tab/rel-tab.ts +32 -7
  22. package/dist/components/rel-time-picker/rel-time-picker.ts +338 -206
  23. package/dist/components/rel-tooltip/rel-tooltip.ts +30 -0
  24. package/dist/components/rel-topbar/rel-topbar-actions.ts +1 -1
  25. package/dist/components/rel-topbar/rel-topbar-brand.ts +1 -1
  26. package/dist/components/rel-topbar/rel-topbar-dropdown-item.ts +1 -1
  27. package/dist/components/rel-topbar/rel-topbar-dropdown.ts +1 -1
  28. package/dist/components/rel-topbar/rel-topbar-item.ts +318 -319
  29. package/dist/components/rel-topbar/rel-topbar-mobile-panel.ts +1 -1
  30. package/dist/components/rel-topbar/rel-topbar-profile.ts +224 -224
  31. package/dist/components/rel-topbar/rel-topbar-utilities.ts +1 -1
  32. package/dist/components/rel-topbar/rel-topbar.ts +440 -440
  33. package/dist/index.d.mts +225 -17
  34. package/dist/index.d.ts +225 -17
  35. package/dist/index.js +1468 -344
  36. package/dist/index.js.map +1 -1
  37. package/dist/index.mjs +1721 -607
  38. package/dist/index.mjs.map +1 -1
  39. package/package.json +1 -1
@@ -270,6 +270,9 @@ export class RelAccordion extends LitElement {
270
270
  }
271
271
  `;
272
272
 
273
+ /** Stable id prefix wiring the header to its panel. */
274
+ private accordionId = `rel-accordion-${Math.random().toString(36).slice(2)}`;
275
+
273
276
  private toggle() {
274
277
  this.open = !this.open;
275
278
  this.dispatchEvent(
@@ -286,9 +289,11 @@ export class RelAccordion extends LitElement {
286
289
  <div part="base" class="accordion">
287
290
  <div
288
291
  part="trigger" class="header"
292
+ id="${this.accordionId}-header"
289
293
  role="button"
290
294
  tabindex="0"
291
295
  aria-expanded="${this.open}"
296
+ aria-controls="${this.accordionId}-body"
292
297
  @click=${this.toggle}
293
298
  @keydown=${(e: KeyboardEvent) => {
294
299
  if (e.key === "Enter" || e.key === " ") {
@@ -315,7 +320,14 @@ export class RelAccordion extends LitElement {
315
320
  </slot>
316
321
  </div>
317
322
  </div>
318
- <div part="content" class="body ${this.open ? "open" : "closed"}">
323
+ <div
324
+ part="content"
325
+ class="body ${this.open ? "open" : "closed"}"
326
+ id="${this.accordionId}-body"
327
+ role="region"
328
+ aria-labelledby="${this.accordionId}-header"
329
+ ?inert=${!this.open}
330
+ >
319
331
  <slot></slot>
320
332
  </div>
321
333
  </div>
@@ -137,9 +137,12 @@ export class RelButton extends LitElement {
137
137
  }
138
138
  }
139
139
 
140
- /* Sizes */
140
+ /* Sizes. Min-widths come from the Figma Button master (S/M/L =
141
+ 80/100/120) so short labels like "OK" keep a proper pill shape;
142
+ --rel-button-min-width lets a consumer override per instance. */
141
143
  .size-small {
142
144
  height: 32px;
145
+ min-width: var(--rel-button-min-width, 80px);
143
146
  padding: 0 var(--rel-spacing-sm);
144
147
  font-family: var(--rel-action-md-font-family);
145
148
  font-weight: var(--rel-action-md-font-weight);
@@ -150,6 +153,7 @@ export class RelButton extends LitElement {
150
153
 
151
154
  .size-medium {
152
155
  height: 40px;
156
+ min-width: var(--rel-button-min-width, 100px);
153
157
  gap: var(--rel-spacing-xs);
154
158
  padding: 0 var(--rel-spacing-md);
155
159
  font-family: var(--rel-action-lg-font-family);
@@ -161,6 +165,7 @@ export class RelButton extends LitElement {
161
165
 
162
166
  .size-large {
163
167
  height: 48px;
168
+ min-width: var(--rel-button-min-width, 120px);
164
169
  padding: 0 var(--rel-spacing-lg);
165
170
  font-family: var(--rel-action-xl-font-family);
166
171
  font-weight: var(--rel-action-xl-font-weight);
@@ -267,6 +272,11 @@ export class RelButton extends LitElement {
267
272
  color: var(--rel-action-neutral-label-icons-ghost);
268
273
  }
269
274
 
275
+ /* Figma master: ghost S has a narrower 56px min than primary/outline. */
276
+ .btn-text.size-small {
277
+ min-width: var(--rel-button-min-width, 56px);
278
+ }
279
+
270
280
  .btn-text.tone-critical {
271
281
  color: var(--rel-action-danger-label-icons-ghost);
272
282
  }
@@ -275,6 +285,8 @@ export class RelButton extends LitElement {
275
285
  background: transparent;
276
286
  color: var(--rel-action-neutral-label-icons-link);
277
287
  text-decoration: underline;
288
+ /* Links are inline actions — no minimum footprint in the Figma master. */
289
+ min-width: 0;
278
290
  }
279
291
 
280
292
  button.btn-link:hover:not(:disabled) {
@@ -303,6 +315,7 @@ export class RelButton extends LitElement {
303
315
  /* Icon Only as an independent axis: square button of the current style */
304
316
  .btn-icon-only {
305
317
  padding: 0;
318
+ min-width: 0;
306
319
  }
307
320
 
308
321
  .btn-icon-only.size-small {
@@ -321,6 +334,7 @@ export class RelButton extends LitElement {
321
334
  width: 40px;
322
335
  height: 40px;
323
336
  padding: 0;
337
+ min-width: 0;
324
338
  border-radius: 50%;
325
339
  }
326
340
  .btn-icon.tone-default {
@@ -365,7 +379,9 @@ export class RelButton extends LitElement {
365
379
  .btn-text: ghost gets tone-accent hovers below (this generic grey overlay
366
380
  has higher specificity than the per-tone ghost rules and was overriding
367
381
  them, which is why every ghost hover looked grey). */
368
- button:hover:not(:disabled):not(.btn-primary):not(.btn-default):not(.btn-icon):not(.btn-secondary):not(.btn-static):not(.btn-text) {
382
+ /* Link buttons change label color only (rule above) — the overlay fill
383
+ here would make a hovered link read as a ghost button. */
384
+ button:hover:not(:disabled):not(.btn-primary):not(.btn-default):not(.btn-icon):not(.btn-secondary):not(.btn-static):not(.btn-text):not(.btn-link) {
369
385
  background: var(--rel-action-overlay-hover);
370
386
  }
371
387
 
@@ -426,9 +426,31 @@ export class RelCalendar extends LitElement {
426
426
  }
427
427
  }
428
428
 
429
+ /**
430
+ * Index of the single grid cell carrying tabindex="0". The old expression
431
+ * (`isSelected || (index === 0 && !focusedDate)`) left the grid with ZERO
432
+ * tab stops once the user arrowed around without a selection — Tab could
433
+ * never re-enter the calendar.
434
+ */
435
+ private getRovingIndex(days: CalendarDay[]): number {
436
+ const candidates = [
437
+ this.focusedDate
438
+ ? days.findIndex(
439
+ (d) => d.isCurrentMonth && this.isSameDay(d.date, this.focusedDate!)
440
+ )
441
+ : -1,
442
+ days.findIndex((d) => d.isSelected),
443
+ days.findIndex((d) => d.isCurrentMonth && d.isToday),
444
+ days.findIndex((d) => d.isCurrentMonth && !d.isDisabled),
445
+ ];
446
+ const found = candidates.find((i) => i >= 0);
447
+ return found ?? 0;
448
+ }
449
+
429
450
  render() {
430
451
  const days = this.getCalendarDays();
431
452
  const weekdayLabels = this.getWeekdayLabels();
453
+ const rovingIndex = this.getRovingIndex(days);
432
454
 
433
455
  return html`
434
456
  <div role="grid" aria-label="Calendar">
@@ -484,7 +506,7 @@ export class RelCalendar extends LitElement {
484
506
  ?disabled=${day.isDisabled}
485
507
  @click=${() => this.selectDay(day)}
486
508
  @keydown=${(e: KeyboardEvent) => this.handleKeyDown(e, day, index)}
487
- tabindex="${day.isSelected || (index === 0 && !this.focusedDate) ? 0 : -1}"
509
+ tabindex="${index === rovingIndex ? 0 : -1}"
488
510
  >
489
511
  ${day.day}
490
512
  </button>
@@ -251,6 +251,11 @@ export class RelCarousel extends LitElement {
251
251
  "(prefers-reduced-motion: reduce)"
252
252
  ).matches;
253
253
 
254
+ // WCAG 2.2.2: auto-advance must pause while keyboard focus is inside the
255
+ // carousel, not just on mouse hover.
256
+ this.addEventListener("focusin", this.handleFocusIn);
257
+ this.addEventListener("focusout", this.handleFocusOut);
258
+
254
259
  if (this.autoplay) {
255
260
  this.startAutoplay();
256
261
  }
@@ -285,6 +290,8 @@ export class RelCarousel extends LitElement {
285
290
 
286
291
  disconnectedCallback() {
287
292
  super.disconnectedCallback();
293
+ this.removeEventListener("focusin", this.handleFocusIn);
294
+ this.removeEventListener("focusout", this.handleFocusOut);
288
295
  this._ro?.disconnect();
289
296
  this.stopAutoplay();
290
297
  if (this.animationId) {
@@ -556,6 +563,18 @@ export class RelCarousel extends LitElement {
556
563
  }
557
564
  }
558
565
 
566
+ private handleFocusIn = () => {
567
+ if (this.autoplay) this.stopAutoplay();
568
+ };
569
+
570
+ private handleFocusOut = (e: FocusEvent) => {
571
+ if (!this.autoplay) return;
572
+ const next = e.relatedTarget as Node | null;
573
+ // Resume only once focus has fully left the carousel (light or shadow).
574
+ if (next && (this.contains(next) || this.shadowRoot?.contains(next))) return;
575
+ this.startAutoplay();
576
+ };
577
+
559
578
  private handleMouseEnter() {
560
579
  if (this.autoplay && this.pauseOnHover) {
561
580
  this.stopAutoplay();
@@ -667,6 +686,7 @@ export class RelCarousel extends LitElement {
667
686
  class="dot ${i === this.value ? "active" : ""}"
668
687
  part="dot"
669
688
  aria-label="Go to slide ${i + 1}"
689
+ aria-current="${i === this.value ? "true" : nothing}"
670
690
  @click=${() => this.goToSlide(i)}
671
691
  ></button>
672
692
  `)
@@ -1,4 +1,4 @@
1
- import { LitElement, html, css, type PropertyValues } from "lit";
1
+ import { LitElement, html, css, nothing, type PropertyValues } from "lit";
2
2
  import { customElement, property } from "lit/decorators.js";
3
3
  import "@reliability-design/icons/rel-icon";
4
4
 
@@ -334,6 +334,9 @@ export class RelCheckbox extends LitElement {
334
334
  <label class="row">
335
335
  <input
336
336
  type="checkbox"
337
+ .checked=${this.status === "checked"}
338
+ .indeterminate=${this.status === "indeterminate"}
339
+ aria-checked="${this.status === "indeterminate" ? "mixed" : nothing}"
337
340
  @click=${this.toggle}
338
341
  @blur=${() => this._onTouched()}
339
342
  ?disabled=${this.state === "disabled"}
@@ -365,6 +365,34 @@ export class RelChip extends LitElement {
365
365
  );
366
366
  }
367
367
 
368
+ /** The chip body is announced as a button, so it must also act on keys:
369
+ * Enter/Space re-dispatch as a host click (consumers' @click handlers
370
+ * fire), Delete/Backspace remove when removable, and arrow keys ask the
371
+ * container to reorder a draggable chip (`chip-move`) — the keyboard
372
+ * alternative to pointer drag-and-drop. */
373
+ private handleKeydown = (e: KeyboardEvent) => {
374
+ if (e.key === "Enter" || e.key === " ") {
375
+ e.preventDefault();
376
+ this.click();
377
+ return;
378
+ }
379
+ if ((e.key === "Delete" || e.key === "Backspace") && this.removable) {
380
+ e.preventDefault();
381
+ this.handleRemove(e);
382
+ return;
383
+ }
384
+ if (this.draggableChip && (e.key === "ArrowLeft" || e.key === "ArrowRight")) {
385
+ e.preventDefault();
386
+ this.dispatchEvent(
387
+ new CustomEvent("chip-move", {
388
+ detail: { direction: e.key === "ArrowLeft" ? -1 : 1 },
389
+ bubbles: true,
390
+ composed: true,
391
+ })
392
+ );
393
+ }
394
+ };
395
+
368
396
  private onDragStart = (e: DragEvent) => {
369
397
  if (!this.draggableChip) return;
370
398
  this.dragging = true;
@@ -409,6 +437,7 @@ export class RelChip extends LitElement {
409
437
  role="button"
410
438
  tabindex="0"
411
439
  aria-label="${this.label}"
440
+ @keydown=${this.handleKeydown}
412
441
  >
413
442
  ${showAvatar
414
443
  ? html`<rel-avatar type="text" text=${this.avatar} size="xs"></rel-avatar>`
@@ -1,6 +1,7 @@
1
1
  import { LitElement, html, css, nothing } from "lit";
2
2
  import { customElement, property, state, query } from "lit/decorators.js";
3
3
  import { formatDatePattern } from "./date-format";
4
+ import { getDeepActiveElement, trapTabKey } from "../../utils/focus.js";
4
5
 
5
6
  interface CalendarDay {
6
7
  date: Date;
@@ -357,6 +358,11 @@ export class RelDatePicker extends LitElement {
357
358
  }
358
359
 
359
360
  .dropdown-item {
361
+ display: block;
362
+ width: 100%;
363
+ border: none;
364
+ background: transparent;
365
+ text-align: left;
360
366
  padding: var(--rel-spacing-xs) var(--rel-spacing-sm);
361
367
  cursor: pointer;
362
368
  color: var(--rel-text-default);
@@ -368,6 +374,11 @@ export class RelDatePicker extends LitElement {
368
374
  letter-spacing: var(--rel-body-sm-regular-letter-spacing);
369
375
  }
370
376
 
377
+ .dropdown-item:focus-visible {
378
+ outline: 2px solid var(--rel-border-focus);
379
+ outline-offset: -2px;
380
+ }
381
+
371
382
  .dropdown-item:hover {
372
383
  background: var(--rel-bg-surface-elevated);
373
384
  }
@@ -497,8 +508,15 @@ export class RelDatePicker extends LitElement {
497
508
  };
498
509
 
499
510
  private handleEscapeKey = (e: KeyboardEvent) => {
500
- if (e.key === "Escape" && this.open) {
511
+ if (!this.open) return;
512
+ if (e.key === "Escape") {
501
513
  this.closeCalendarPopover();
514
+ return;
515
+ }
516
+ // The popover announces itself as a dialog — keep Tab inside it.
517
+ if (e.key === "Tab") {
518
+ const popover = this.renderRoot.querySelector<HTMLElement>(".popover");
519
+ if (popover) trapTabKey(e, popover);
502
520
  }
503
521
  };
504
522
 
@@ -512,12 +530,17 @@ export class RelDatePicker extends LitElement {
512
530
  }
513
531
 
514
532
  if (changedProperties.has("open") && this.open) {
515
- // Focus first day when opening
533
+ // Focus the roving cell (selected day, else today, else first
534
+ // selectable) when opening — not blindly the first of the month.
516
535
  setTimeout(() => {
517
- const firstDay = this.calendarGrid?.querySelector<HTMLButtonElement>(
518
- ".day-button:not(:disabled)"
519
- );
520
- firstDay?.focus();
536
+ const target =
537
+ this.calendarGrid?.querySelector<HTMLButtonElement>(
538
+ '.day-button[tabindex="0"]:not(:disabled)'
539
+ ) ??
540
+ this.calendarGrid?.querySelector<HTMLButtonElement>(
541
+ ".day-button:not(:disabled)"
542
+ );
543
+ target?.focus();
521
544
  }, 100);
522
545
  }
523
546
  }
@@ -865,24 +888,125 @@ export class RelDatePicker extends LitElement {
865
888
  e.stopPropagation();
866
889
  this.monthDropdownOpen = !this.monthDropdownOpen;
867
890
  this.yearDropdownOpen = false;
891
+ if (this.monthDropdownOpen) this.focusOpenDropdownSelection();
868
892
  }
869
893
 
870
894
  private toggleYearDropdown(e: Event) {
871
895
  e.stopPropagation();
872
896
  this.yearDropdownOpen = !this.yearDropdownOpen;
873
897
  this.monthDropdownOpen = false;
898
+ if (this.yearDropdownOpen) this.focusOpenDropdownSelection();
874
899
  }
875
900
 
901
+ private handleDropdownTriggerKeydown(e: KeyboardEvent, kind: "month" | "year") {
902
+ if (e.key !== "ArrowDown") return;
903
+ e.preventDefault();
904
+ e.stopPropagation();
905
+ this.monthDropdownOpen = kind === "month";
906
+ this.yearDropdownOpen = kind === "year";
907
+ this.focusOpenDropdownSelection();
908
+ }
909
+
910
+ private async focusOpenDropdownSelection() {
911
+ await this.updateComplete;
912
+ const menu = this.renderRoot.querySelector<HTMLElement>(".dropdown-menu.open");
913
+ if (!menu) return;
914
+ const target =
915
+ menu.querySelector<HTMLElement>(".dropdown-item.selected") ??
916
+ menu.querySelector<HTMLElement>(".dropdown-item");
917
+ target?.focus();
918
+ target?.scrollIntoView({ block: "nearest" });
919
+ }
920
+
921
+ private handleDropdownKeydown = (e: KeyboardEvent) => {
922
+ const menu = e.currentTarget as HTMLElement;
923
+ const items = Array.from(
924
+ menu.querySelectorAll<HTMLElement>(".dropdown-item")
925
+ );
926
+ if (items.length === 0) return;
927
+
928
+ if (e.key === "Escape") {
929
+ // Close only the dropdown, not the whole calendar popover behind it.
930
+ e.preventDefault();
931
+ e.stopPropagation();
932
+ const trigger = menu
933
+ .closest(".dropdown-container")
934
+ ?.querySelector<HTMLElement>(".dropdown-trigger");
935
+ this.monthDropdownOpen = false;
936
+ this.yearDropdownOpen = false;
937
+ trigger?.focus();
938
+ return;
939
+ }
940
+
941
+ if (e.key === "Tab") {
942
+ this.monthDropdownOpen = false;
943
+ this.yearDropdownOpen = false;
944
+ return;
945
+ }
946
+
947
+ const idx = items.indexOf(getDeepActiveElement() as HTMLElement);
948
+ let target: number;
949
+ switch (e.key) {
950
+ case "ArrowDown":
951
+ target = Math.min(items.length - 1, idx + 1);
952
+ break;
953
+ case "ArrowUp":
954
+ target = Math.max(0, idx - 1);
955
+ break;
956
+ case "Home":
957
+ target = 0;
958
+ break;
959
+ case "End":
960
+ target = items.length - 1;
961
+ break;
962
+ default:
963
+ return;
964
+ }
965
+ e.preventDefault();
966
+ e.stopPropagation();
967
+ items[target]?.focus();
968
+ items[target]?.scrollIntoView({ block: "nearest" });
969
+ };
970
+
876
971
  private selectMonth(month: number, e: Event) {
877
972
  e.stopPropagation();
973
+ const trigger = (e.target as HTMLElement)
974
+ .closest(".dropdown-container")
975
+ ?.querySelector<HTMLElement>(".dropdown-trigger");
878
976
  this.viewMonth = month;
879
977
  this.monthDropdownOpen = false;
978
+ // The focused item just went display:none — keep keyboard users anchored.
979
+ this.updateComplete.then(() => trigger?.focus());
880
980
  }
881
981
 
882
982
  private selectYear(year: number, e: Event) {
883
983
  e.stopPropagation();
984
+ const trigger = (e.target as HTMLElement)
985
+ .closest(".dropdown-container")
986
+ ?.querySelector<HTMLElement>(".dropdown-trigger");
884
987
  this.viewYear = year;
885
988
  this.yearDropdownOpen = false;
989
+ this.updateComplete.then(() => trigger?.focus());
990
+ }
991
+
992
+ /**
993
+ * Index of the single grid cell carrying tabindex="0". The old expression
994
+ * (`isSelected || (index === 0 && !value)`) left the grid with ZERO tab
995
+ * stops once the user arrowed around without a selection.
996
+ */
997
+ private getRovingIndex(days: CalendarDay[]): number {
998
+ const candidates = [
999
+ this.focusedDate
1000
+ ? days.findIndex(
1001
+ (d) => d.isCurrentMonth && this.isSameDay(d.date, this.focusedDate!)
1002
+ )
1003
+ : -1,
1004
+ days.findIndex((d) => d.isSelected),
1005
+ days.findIndex((d) => d.isCurrentMonth && d.isToday),
1006
+ days.findIndex((d) => d.isCurrentMonth && !d.isDisabled),
1007
+ ];
1008
+ const found = candidates.find((i) => i >= 0);
1009
+ return found ?? 0;
886
1010
  }
887
1011
 
888
1012
  render() {
@@ -890,6 +1014,7 @@ export class RelDatePicker extends LitElement {
890
1014
  const weekdayLabels = this.getWeekdayLabels();
891
1015
  const months = this.getMonthsList();
892
1016
  const years = this.getYearsList();
1017
+ const rovingIndex = this.getRovingIndex(days);
893
1018
 
894
1019
  const isError = this.error;
895
1020
  const belowText = isError && this.errorMessage ? this.errorMessage : this.helperText;
@@ -988,22 +1113,31 @@ export class RelDatePicker extends LitElement {
988
1113
  class="dropdown-trigger"
989
1114
  type="button"
990
1115
  @click=${this.toggleMonthDropdown}
1116
+ @keydown=${(e: KeyboardEvent) => this.handleDropdownTriggerKeydown(e, "month")}
991
1117
  aria-label="Select month"
1118
+ aria-haspopup="listbox"
992
1119
  aria-expanded=${this.monthDropdownOpen}
993
1120
  >
994
1121
  ${this.getMonthName()}
995
1122
  </button>
996
- <div class="dropdown-menu ${this.monthDropdownOpen ? "open" : ""}">
1123
+ <div
1124
+ class="dropdown-menu ${this.monthDropdownOpen ? "open" : ""}"
1125
+ role="listbox"
1126
+ aria-label="Month"
1127
+ @keydown=${this.handleDropdownKeydown}
1128
+ >
997
1129
  ${months.map(
998
1130
  (m) => html`
999
- <div
1131
+ <button
1000
1132
  class="dropdown-item ${m.value === this.viewMonth ? "selected" : ""}"
1133
+ type="button"
1134
+ tabindex="-1"
1001
1135
  @click=${(e: Event) => this.selectMonth(m.value, e)}
1002
1136
  role="option"
1003
1137
  aria-selected=${m.value === this.viewMonth}
1004
1138
  >
1005
1139
  ${m.label}
1006
- </div>
1140
+ </button>
1007
1141
  `
1008
1142
  )}
1009
1143
  </div>
@@ -1014,22 +1148,31 @@ export class RelDatePicker extends LitElement {
1014
1148
  class="dropdown-trigger"
1015
1149
  type="button"
1016
1150
  @click=${this.toggleYearDropdown}
1151
+ @keydown=${(e: KeyboardEvent) => this.handleDropdownTriggerKeydown(e, "year")}
1017
1152
  aria-label="Select year"
1153
+ aria-haspopup="listbox"
1018
1154
  aria-expanded=${this.yearDropdownOpen}
1019
1155
  >
1020
1156
  ${this.viewYear}
1021
1157
  </button>
1022
- <div class="dropdown-menu ${this.yearDropdownOpen ? "open" : ""}">
1158
+ <div
1159
+ class="dropdown-menu ${this.yearDropdownOpen ? "open" : ""}"
1160
+ role="listbox"
1161
+ aria-label="Year"
1162
+ @keydown=${this.handleDropdownKeydown}
1163
+ >
1023
1164
  ${years.map(
1024
1165
  (y) => html`
1025
- <div
1166
+ <button
1026
1167
  class="dropdown-item ${y === this.viewYear ? "selected" : ""}"
1168
+ type="button"
1169
+ tabindex="-1"
1027
1170
  @click=${(e: Event) => this.selectYear(y, e)}
1028
1171
  role="option"
1029
1172
  aria-selected=${y === this.viewYear}
1030
1173
  >
1031
1174
  ${y}
1032
- </div>
1175
+ </button>
1033
1176
  `
1034
1177
  )}
1035
1178
  </div>
@@ -1074,7 +1217,7 @@ export class RelDatePicker extends LitElement {
1074
1217
  ?disabled=${day.isDisabled}
1075
1218
  @click=${() => this.selectDay(day)}
1076
1219
  @keydown=${(e: KeyboardEvent) => this.handleDayKeydown(e, day, index)}
1077
- tabindex="${day.isSelected || (index === 0 && !this.value) ? 0 : -1}"
1220
+ tabindex="${index === rovingIndex ? 0 : -1}"
1078
1221
  >
1079
1222
  ${day.day}
1080
1223
  </button>
@@ -2,6 +2,7 @@ import { LitElement, html, css } from "lit";
2
2
  import { customElement, property, state, query } from "lit/decorators.js";
3
3
  import "@reliability-design/icons/rel-icon";
4
4
  import "./rel-drawer-footer";
5
+ import { getDeepActiveElement, getFocusableElements, trapTabKey } from "../../utils/focus.js";
5
6
 
6
7
  export type DrawerSide = "bottom" | "left" | "right";
7
8
  export type DrawerCloseReason = "backdrop" | "escape" | "drag" | "programmatic";
@@ -327,16 +328,26 @@ export class RelDrawer extends LitElement {
327
328
  }
328
329
 
329
330
  private handleOpen() {
330
- this.previousFocus = document.activeElement as HTMLElement;
331
+ // Deep-resolved: document.activeElement retargets to a component's host
332
+ // (e.g. <rel-button>), whose .focus() is a no-op — restore would drop
333
+ // focus to <body>.
334
+ this.previousFocus = getDeepActiveElement();
331
335
  this.lockScroll();
332
336
 
333
337
  if (this.modal) {
338
+ // The panel lives in the shadow root, so plain this.querySelector never
339
+ // found it (focus was never moved in). The shared util walks the
340
+ // composed tree, seeing both shadow and slotted content.
334
341
  this.updateComplete.then(() => {
335
- const focusTarget =
336
- this.querySelector<HTMLElement>("[autofocus]") ??
337
- this.querySelector<HTMLElement>(".close-button") ??
338
- this.querySelector<HTMLElement>(".panel");
339
- focusTarget?.focus();
342
+ const panel = this.panelElement;
343
+ if (!panel) return;
344
+ const focusTarget = getFocusableElements(panel)[0];
345
+ if (focusTarget) {
346
+ focusTarget.focus();
347
+ } else {
348
+ panel.tabIndex = -1;
349
+ panel.focus();
350
+ }
340
351
  });
341
352
  }
342
353
 
@@ -414,35 +425,6 @@ export class RelDrawer extends LitElement {
414
425
  document.body.style.paddingRight = this.originalBodyPaddingRight;
415
426
  }
416
427
 
417
- private getFocusableElements(): HTMLElement[] {
418
- if (!this.panelElement) return [];
419
-
420
- const selectors = [
421
- 'a[href]',
422
- 'button:not([disabled])',
423
- 'textarea:not([disabled])',
424
- 'input:not([disabled])',
425
- 'select:not([disabled])',
426
- '[tabindex]:not([tabindex="-1"])',
427
- ].join(",");
428
-
429
- const elements = Array.from(
430
- this.panelElement.querySelectorAll(selectors)
431
- ) as HTMLElement[];
432
-
433
- // Also check slotted content
434
- const slots = this.panelElement.querySelectorAll("slot");
435
- slots.forEach((slot) => {
436
- const assigned = slot.assignedElements({ flatten: true });
437
- assigned.forEach((el) => {
438
- const focusableInSlot = el.querySelectorAll(selectors);
439
- elements.push(...(Array.from(focusableInSlot) as HTMLElement[]));
440
- });
441
- });
442
-
443
- return elements;
444
- }
445
-
446
428
  private handleKeydown = (e: KeyboardEvent) => {
447
429
  if (!this.open) return;
448
430
 
@@ -452,29 +434,11 @@ export class RelDrawer extends LitElement {
452
434
  return;
453
435
  }
454
436
 
455
- // Focus trap
456
- if (e.key === "Tab" && this.modal) {
457
- const focusable = this.getFocusableElements();
458
- if (focusable.length === 0) {
459
- e.preventDefault();
460
- return;
461
- }
462
-
463
- const firstFocusable = focusable[0];
464
- const lastFocusable = focusable[focusable.length - 1];
465
- const activeElement = document.activeElement;
466
-
467
- if (e.shiftKey) {
468
- if (activeElement === firstFocusable) {
469
- e.preventDefault();
470
- lastFocusable.focus();
471
- }
472
- } else {
473
- if (activeElement === lastFocusable) {
474
- e.preventDefault();
475
- firstFocusable.focus();
476
- }
477
- }
437
+ // Focus trap — the shared helper resolves the deep active element, which
438
+ // the old document.activeElement comparison never could (it retargets to
439
+ // the <rel-drawer> host, so Tab was never wrapped).
440
+ if (e.key === "Tab" && this.modal && this.panelElement) {
441
+ trapTabKey(e, this.panelElement);
478
442
  }
479
443
  };
480
444