@reliability-design/web 1.4.6 → 1.4.8

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 (148) hide show
  1. package/CHANGELOG.md +246 -49
  2. package/dist/components/rel-accordion/README.md +133 -132
  3. package/dist/components/rel-alert/README.md +145 -141
  4. package/dist/components/rel-autocomplete/README.md +172 -61
  5. package/dist/components/rel-avatar/README.md +118 -130
  6. package/dist/components/rel-badge/README.md +97 -93
  7. package/dist/components/rel-breadcrumb/README.md +96 -102
  8. package/dist/components/rel-button/README.md +190 -130
  9. package/dist/components/rel-calendar/README.md +109 -109
  10. package/dist/components/rel-card/README.md +75 -94
  11. package/dist/components/rel-cardmedia/README.md +100 -127
  12. package/dist/components/rel-carousel/README.md +186 -166
  13. package/dist/components/rel-checkbox/README.md +96 -75
  14. package/dist/components/rel-chip/README.md +138 -121
  15. package/dist/components/rel-container/README.md +107 -99
  16. package/dist/components/rel-date-picker/README.md +200 -289
  17. package/dist/components/rel-divider/README.md +88 -100
  18. package/dist/components/rel-drawer/README.md +187 -200
  19. package/dist/components/rel-kbd/README.md +141 -151
  20. package/dist/components/rel-layout/README.md +34 -0
  21. package/dist/components/rel-menu/README.md +180 -151
  22. package/dist/components/rel-menubar/README.md +218 -329
  23. package/dist/components/rel-otp/README.md +171 -440
  24. package/dist/components/rel-pagination/README.md +100 -424
  25. package/dist/components/rel-popover/README.md +203 -568
  26. package/dist/components/rel-progress/README.md +88 -110
  27. package/dist/components/rel-radio/README.md +131 -138
  28. package/dist/components/rel-range-picker/README.md +165 -0
  29. package/dist/components/rel-resizable/README.md +199 -140
  30. package/dist/components/rel-segmented-button/README.md +156 -141
  31. package/dist/components/rel-select/README.md +156 -93
  32. package/dist/components/rel-sheet/README.md +168 -224
  33. package/dist/components/rel-skeleton/README.md +104 -0
  34. package/dist/components/rel-slider/README.md +131 -135
  35. package/dist/components/rel-snackbar/README.md +168 -134
  36. package/dist/components/rel-stepper/README.md +162 -160
  37. package/dist/components/rel-switch/README.md +117 -102
  38. package/dist/components/rel-tab/README.md +173 -163
  39. package/dist/components/rel-textfield/README.md +176 -69
  40. package/dist/components/rel-time-picker/README.md +122 -157
  41. package/dist/components/rel-toast/README.md +165 -148
  42. package/dist/components/rel-tooltip/README.md +119 -111
  43. package/dist/components/rel-upload/README.md +220 -0
  44. package/dist/index.d.mts +1726 -447
  45. package/dist/index.d.ts +1726 -447
  46. package/dist/index.js +13715 -10870
  47. package/dist/index.js.map +1 -1
  48. package/dist/index.mjs +14018 -11163
  49. package/dist/index.mjs.map +1 -1
  50. package/dist/styles/focus-ring.ts +84 -0
  51. package/dist/styles/vars.css +892 -866
  52. package/dist/{vars-XNMTSRVN.css → vars-DXX6QOAG.css} +892 -866
  53. package/package.json +3 -2
  54. package/dist/components/rel-accordion/rel-accordion.ts +0 -336
  55. package/dist/components/rel-alert/rel-alert.ts +0 -305
  56. package/dist/components/rel-autocomplete/rel-autocomplete.ts +0 -720
  57. package/dist/components/rel-avatar/rel-avatar.ts +0 -142
  58. package/dist/components/rel-badge/rel-badge.ts +0 -175
  59. package/dist/components/rel-breadcrumb/rel-breadcrumb.ts +0 -106
  60. package/dist/components/rel-button/rel-button.ts +0 -560
  61. package/dist/components/rel-calendar/index.ts +0 -1
  62. package/dist/components/rel-calendar/rel-calendar.ts +0 -565
  63. package/dist/components/rel-card/rel-card.ts +0 -88
  64. package/dist/components/rel-cardmedia/rel-cardmedia.ts +0 -88
  65. package/dist/components/rel-carousel/index.ts +0 -1
  66. package/dist/components/rel-carousel/rel-carousel.ts +0 -723
  67. package/dist/components/rel-chart/README.md +0 -286
  68. package/dist/components/rel-chart/index.ts +0 -1
  69. package/dist/components/rel-chart/rel-chart.ts +0 -754
  70. package/dist/components/rel-checkbox/rel-checkbox.ts +0 -382
  71. package/dist/components/rel-chip/rel-chip.ts +0 -483
  72. package/dist/components/rel-container/rel-container.ts +0 -95
  73. package/dist/components/rel-date-picker/date-format.test.ts +0 -43
  74. package/dist/components/rel-date-picker/date-format.ts +0 -47
  75. package/dist/components/rel-date-picker/date-parse.test.ts +0 -116
  76. package/dist/components/rel-date-picker/date-parse.ts +0 -178
  77. package/dist/components/rel-date-picker/index.ts +0 -1
  78. package/dist/components/rel-date-picker/rel-date-picker.ts +0 -1676
  79. package/dist/components/rel-divider/rel-divider.ts +0 -54
  80. package/dist/components/rel-drawer/index.ts +0 -1
  81. package/dist/components/rel-drawer/rel-drawer-footer.ts +0 -27
  82. package/dist/components/rel-drawer/rel-drawer.ts +0 -607
  83. package/dist/components/rel-kbd/rel-kbd.ts +0 -188
  84. package/dist/components/rel-layout/rel-layout.ts +0 -49
  85. package/dist/components/rel-menu/rel-menu.ts +0 -541
  86. package/dist/components/rel-menubar/index.ts +0 -2
  87. package/dist/components/rel-menubar/rel-menubar-menu.css +0 -3
  88. package/dist/components/rel-menubar/rel-menubar-menu.ts +0 -17
  89. package/dist/components/rel-menubar/rel-menubar.ts +0 -777
  90. package/dist/components/rel-nav-menu/README.md +0 -289
  91. package/dist/components/rel-nav-menu/index.ts +0 -3
  92. package/dist/components/rel-nav-menu/rel-nav-menu-item.ts +0 -243
  93. package/dist/components/rel-nav-menu/rel-nav-menu-panel.ts +0 -72
  94. package/dist/components/rel-nav-menu/rel-nav-menu.ts +0 -270
  95. package/dist/components/rel-navbar/README.md +0 -126
  96. package/dist/components/rel-navbar/rel-navbar.ts +0 -105
  97. package/dist/components/rel-otp/index.ts +0 -1
  98. package/dist/components/rel-otp/rel-otp.ts +0 -527
  99. package/dist/components/rel-pagination/index.ts +0 -1
  100. package/dist/components/rel-pagination/rel-pagination.ts +0 -522
  101. package/dist/components/rel-popover/index.ts +0 -2
  102. package/dist/components/rel-popover/rel-popover-content.ts +0 -81
  103. package/dist/components/rel-popover/rel-popover.ts +0 -475
  104. package/dist/components/rel-progress/rel-progress.ts +0 -234
  105. package/dist/components/rel-radio/rel-radio.ts +0 -481
  106. package/dist/components/rel-range-picker/rel-range-picker.ts +0 -1688
  107. package/dist/components/rel-resizable/index.ts +0 -3
  108. package/dist/components/rel-resizable/rel-resizable-group.ts +0 -405
  109. package/dist/components/rel-resizable/rel-resizable-handle.ts +0 -150
  110. package/dist/components/rel-resizable/rel-resizable-panel.ts +0 -58
  111. package/dist/components/rel-segmented-button/rel-segmented-button.ts +0 -217
  112. package/dist/components/rel-select/rel-select.ts +0 -1416
  113. package/dist/components/rel-sheet/rel-sheet.ts +0 -610
  114. package/dist/components/rel-sidebar/README.md +0 -209
  115. package/dist/components/rel-sidebar/rel-sidebar.ts +0 -1191
  116. package/dist/components/rel-skeleton/rel-skeleton.ts +0 -143
  117. package/dist/components/rel-slider/rel-slider.ts +0 -673
  118. package/dist/components/rel-snackbar/rel-snackbar.ts +0 -329
  119. package/dist/components/rel-stepper/rel-stepper.ts +0 -567
  120. package/dist/components/rel-switch/rel-switch.ts +0 -199
  121. package/dist/components/rel-tab/rel-tab.ts +0 -264
  122. package/dist/components/rel-table/README.md +0 -178
  123. package/dist/components/rel-table/rel-table-body.ts +0 -22
  124. package/dist/components/rel-table/rel-table-caption.ts +0 -30
  125. package/dist/components/rel-table/rel-table-cell.ts +0 -43
  126. package/dist/components/rel-table/rel-table-footer.ts +0 -24
  127. package/dist/components/rel-table/rel-table-head.ts +0 -47
  128. package/dist/components/rel-table/rel-table-header.ts +0 -22
  129. package/dist/components/rel-table/rel-table-row.ts +0 -37
  130. package/dist/components/rel-table/rel-table.ts +0 -62
  131. package/dist/components/rel-textfield/rel-textfield.ts +0 -1054
  132. package/dist/components/rel-time-picker/rel-time-picker.ts +0 -1482
  133. package/dist/components/rel-time-picker/time-parse.test.ts +0 -67
  134. package/dist/components/rel-time-picker/time-parse.ts +0 -85
  135. package/dist/components/rel-toast/rel-toast.ts +0 -206
  136. package/dist/components/rel-tooltip/rel-tooltip.ts +0 -193
  137. package/dist/components/rel-topbar/rel-topbar-actions.ts +0 -27
  138. package/dist/components/rel-topbar/rel-topbar-brand.ts +0 -54
  139. package/dist/components/rel-topbar/rel-topbar-dropdown-item.ts +0 -69
  140. package/dist/components/rel-topbar/rel-topbar-dropdown.ts +0 -31
  141. package/dist/components/rel-topbar/rel-topbar-item.ts +0 -324
  142. package/dist/components/rel-topbar/rel-topbar-mobile-panel.ts +0 -27
  143. package/dist/components/rel-topbar/rel-topbar-profile.ts +0 -243
  144. package/dist/components/rel-topbar/rel-topbar-utilities.ts +0 -27
  145. package/dist/components/rel-topbar/rel-topbar.ts +0 -446
  146. package/dist/components/rel-upload/UPLOAD-DESIGN-CHANGES.md +0 -134
  147. package/dist/components/rel-upload/rel-upload-actions.ts +0 -163
  148. package/dist/components/rel-upload/rel-upload.ts +0 -968
@@ -1,1416 +0,0 @@
1
- import { LitElement, html, css, nothing, PropertyValues } from "lit";
2
- import { customElement, property, state, query } from "lit/decorators.js";
3
- import { repeat } from "lit/directives/repeat.js";
4
- import "@reliability-design/icons/rel-icon";
5
- import "../rel-chip/rel-chip.js";
6
- import "../rel-checkbox/rel-checkbox.js";
7
- import type { FieldLabelStyle } from "../rel-textfield/rel-textfield.js";
8
- import { announce } from "../../utils/announce";
9
-
10
- export type SelectState = "default" | "error" | "disabled";
11
- export type SelectSize = "small" | "medium" | "large";
12
- export type SelectBorder = "rounded" | "sharp";
13
- /** Alias of the shared field type — kept so existing imports keep resolving. */
14
- export type SelectLabelStyle = FieldLabelStyle;
15
-
16
- export interface SelectOptionObject {
17
- value: string;
18
- label?: string;
19
- supportingText?: string;
20
- /** rel-icon name rendered as a prefix (leading icon) on the menu item. */
21
- icon?: string;
22
- }
23
- export type SelectOption = string | SelectOptionObject;
24
-
25
- interface NormalizedOption {
26
- value: string;
27
- label: string;
28
- supportingText: string;
29
- icon: string;
30
- }
31
-
32
- function normalizeOption(o: SelectOption): NormalizedOption {
33
- if (typeof o === "string") return { value: o, label: o, supportingText: "", icon: "" };
34
- return {
35
- value: o.value,
36
- label: o.label ?? o.value,
37
- supportingText: o.supportingText ?? "",
38
- icon: o.icon ?? "",
39
- };
40
- }
41
-
42
- @customElement("rel-select")
43
- export class RelSelect extends LitElement {
44
- @property({ type: String }) label: string = "";
45
-
46
- // Lit's default attribute name is the property name fully lowercased (no
47
- // hyphens) — e.g. labelStyle would otherwise only respond to "labelstyle".
48
- // Every multi-word property below gets an explicit kebab-case `attribute`
49
- // so it works the way HTML usage actually looks.
50
- @property({ type: String, attribute: "label-style", reflect: true })
51
- labelStyle: SelectLabelStyle = "default";
52
-
53
- /**
54
- * Accessible name for the trigger. Required when `labelStyle="none"`, since no
55
- * `<label>` renders and a placeholder is not a valid naming mechanism.
56
- */
57
- @property({ type: String, attribute: "field-aria-label" }) fieldAriaLabel?: string;
58
- /** IDREF list of external element(s) naming the trigger. Wins over `fieldAriaLabel`. */
59
- @property({ type: String, attribute: "field-aria-labelledby" }) fieldAriaLabelledby?: string;
60
-
61
- @property({ type: Array }) options: SelectOption[] = [];
62
-
63
- /** Enables multi-select: selected values render as removable chips and options as checkboxes. */
64
- @property({ type: Boolean }) multiple: boolean = false;
65
-
66
- /** Selected value — single-select mode only. */
67
- @property({ type: String }) selected: string = "";
68
-
69
- /** Selected values — multi-select mode only. */
70
- @property({ type: Array, attribute: "selected-values" }) selectedValues: string[] = [];
71
-
72
- @property({ type: String }) state: SelectState = "default";
73
-
74
- @property({ type: String, attribute: "supporting-text" }) supportingText: string = "";
75
-
76
- @property({ type: String, reflect: true }) size: SelectSize = "medium";
77
-
78
- @property({ type: String }) border: SelectBorder = "rounded";
79
-
80
- @property({ type: String, attribute: "left-icon" }) leftIcon: string = "";
81
-
82
- @property({ type: String, attribute: "right-icon" }) rightIcon: string = "";
83
-
84
- @property({ type: String }) placeholder: string = "Select option";
85
-
86
- @property({ type: String, attribute: "search-placeholder" }) searchPlaceholder: string = "Search option";
87
-
88
- @property({ type: String, attribute: "select-all-label" }) selectAllLabel: string = "Select all";
89
-
90
- /**
91
- * Optional hard cap on visible chips. By default (no cap) the visible
92
- * count adapts to the trigger's width: chips collapse into the "+N" badge
93
- * one by one instead of wrapping to a second line.
94
- */
95
- @property({ type: Number, attribute: "max-visible-chips" }) maxVisibleChips: number = Infinity;
96
-
97
- // Boolean props default true and toggled off via ="false" are a classic Lit
98
- // trap: for type:Boolean, attribute *presence* (not its string value)
99
- // decides truthiness, so searchable="false" would still read as true. Named
100
- // negatively instead, so the natural HTML idiom — just adding the bare
101
- // attribute, no value — does what it looks like it does.
102
- /** Hides the in-panel search field. Figma's "Single Option" dropdown has no search bar at all — use this for short, non-searchable lists. */
103
- @property({ type: Boolean, attribute: "no-search" }) noSearch: boolean = false;
104
-
105
- @state() private open = false;
106
- @state() private highlightedIndex = -1;
107
- /** Virtual highlight on the Select-All header row (multi mode). */
108
- @state() private selectAllHighlighted = false;
109
-
110
- private typeaheadBuffer = "";
111
- private typeaheadTimer: number | undefined;
112
- @state() private panelStyle = "";
113
- @state() private searchValue = "";
114
- @state() private internalState: "default" | "focused" = "default";
115
-
116
- /** How many chips currently fit in the trigger width (width-adaptive). */
117
- @state() private visibleChipCount = Infinity;
118
-
119
- @query(".select-trigger") private triggerEl!: HTMLButtonElement;
120
- @query(".search-input") private searchInputEl!: HTMLInputElement;
121
- @query(".select-listbox") private listboxEl!: HTMLDivElement;
122
- @query(".select-value") private valueEl!: HTMLElement;
123
- @query(".select-chips-measure") private chipsMeasureEl!: HTMLElement;
124
-
125
- /** Must match the `gap` of .select-chips / .select-chips-measure. */
126
- private static readonly CHIP_GAP = 6;
127
-
128
- private chipResizeObserver?: ResizeObserver;
129
-
130
- private uniqueId = `select-${Math.random().toString(36).slice(2)}`;
131
-
132
- static styles = css`
133
- :host {
134
- color: var(--rel-text-default);
135
- display: block;
136
- font-family: var(--rel-fonts-font-family);
137
- width: 100%;
138
- }
139
-
140
- .select-wrapper {
141
- display: flex;
142
- flex-direction: column;
143
- gap: var(--rel-spacing-2xs);
144
- width: 100%;
145
- }
146
-
147
- /* Dims everything inside uniformly (label, trigger, icons, value text,
148
- supporting text) — matches rel-button's :host([disabled]) opacity
149
- approach instead of relying on one barely-different background tint. */
150
- .select-wrapper.disabled {
151
- opacity: 0.5;
152
- }
153
-
154
- .select-label {
155
- color: var(--rel-select-label-color, var(--rel-text-label));
156
-
157
- font-family: var(--rel-body-sm-regular-font-family);
158
-
159
- font-weight: var(--rel-body-sm-regular-font-weight);
160
-
161
- font-size: var(--rel-body-sm-regular-font-size);
162
-
163
- line-height: var(--rel-body-sm-regular-line-height);
164
-
165
- letter-spacing: var(--rel-body-sm-regular-letter-spacing);
166
-
167
- }
168
-
169
- /* ── labelStyle="none" ──
170
- No label renders. An empty spacer holds the label row's full height so the
171
- trigger still bottom-aligns with labelled siblings in a form row.
172
- The reserve covers label line-height + the wrapper gap, and the negative
173
- margin cancels the flex gap that would otherwise sit below it — so
174
- --rel-field-label-reserve: 0 collapses the row to genuinely zero
175
- (toolbars, table cells), not just to the leftover gap. */
176
- .label-reserve {
177
- flex: none;
178
- height: var(
179
- --rel-field-label-reserve,
180
- calc(var(--rel-body-sm-regular-line-height) + var(--rel-spacing-2xs))
181
- );
182
- margin-bottom: calc(-1 * var(--rel-spacing-2xs));
183
- }
184
-
185
- /* Error only colors the border/focus ring and the supporting text below
186
- the field — label, floating label, placeholder, and icons stay normal. */
187
-
188
- /* Container */
189
- .select-container {
190
- position: relative;
191
- }
192
-
193
- /* Trigger button — visually a text field, semantically a combobox button */
194
- .select-trigger {
195
- display: flex;
196
- align-items: center;
197
- width: 100%;
198
- box-sizing: border-box;
199
- gap: 8px;
200
- background: var(--rel-select-bg, var(--rel-bg-neutral));
201
- border: 1px solid var(--rel-select-border-default, var(--rel-border-default));
202
- cursor: pointer;
203
- font-family: inherit;
204
- transition: border-color 0.15s ease;
205
- text-align: left;
206
- }
207
-
208
- .border-rounded .select-trigger {
209
- border-radius: var(--rel-select-radius, var(--rel-border-radius-xs));
210
- }
211
-
212
- .border-sharp .select-trigger {
213
- border-radius: 0;
214
- }
215
-
216
- .select-trigger:focus-visible,
217
- .select-wrapper.open .select-trigger {
218
- outline: none;
219
- border-color: var(--rel-select-border-focus, var(--rel-border-strong));
220
- }
221
-
222
- .select-wrapper.error .select-trigger {
223
- border-color: var(--rel-select-border-error, var(--rel-border-danger));
224
- }
225
-
226
- .select-wrapper.disabled .select-trigger {
227
- cursor: not-allowed;
228
- background: var(--rel-select-bg-disabled, var(--rel-bg-neutral-elevated-1));
229
- border-color: var(--rel-select-border-default, var(--rel-border-default));
230
- }
231
-
232
- /* Sizes */
233
- .select-wrapper.small .select-trigger {
234
- padding: var(--rel-spacing-xs) var(--rel-spacing-sm);
235
- min-height: 40px;
236
- font-family: var(--rel-body-sm-regular-font-family);
237
- font-weight: var(--rel-body-sm-regular-font-weight);
238
- font-size: var(--rel-body-sm-regular-font-size);
239
- line-height: var(--rel-body-sm-regular-line-height);
240
- letter-spacing: var(--rel-body-sm-regular-letter-spacing);
241
- }
242
-
243
- .select-wrapper.medium .select-trigger {
244
- padding: 12px;
245
- min-height: 48px;
246
- font-family: var(--rel-body-md-regular-font-family);
247
- font-weight: var(--rel-body-md-regular-font-weight);
248
- font-size: var(--rel-body-md-regular-font-size);
249
- line-height: var(--rel-body-md-regular-line-height);
250
- letter-spacing: var(--rel-body-md-regular-letter-spacing);
251
- }
252
-
253
- .select-wrapper.large .select-trigger {
254
- padding: var(--rel-spacing-md);
255
- min-height: 56px;
256
- font-family: var(--rel-body-lg-regular-font-family);
257
- font-weight: var(--rel-body-lg-regular-font-weight);
258
- font-size: var(--rel-body-lg-regular-font-size);
259
- line-height: var(--rel-body-lg-regular-line-height);
260
- letter-spacing: var(--rel-body-lg-regular-letter-spacing);
261
- }
262
-
263
- /* Icons */
264
- .select-trigger .icon {
265
- display: flex;
266
- align-items: center;
267
- flex-shrink: 0;
268
- color: var(--rel-select-icon-color, var(--rel-text-default));
269
- }
270
-
271
- .select-trigger .icon.chevron {
272
- transition: transform 0.15s ease;
273
- }
274
-
275
- .select-wrapper.open .icon.chevron {
276
- transform: rotate(180deg);
277
- }
278
-
279
- .select-wrapper.disabled .icon {
280
- color: var(--rel-text-disabled);
281
- }
282
-
283
- /* Value area */
284
- .select-value {
285
- flex: 1;
286
- min-width: 0;
287
- display: flex;
288
- align-items: center;
289
- gap: 6px;
290
- flex-wrap: nowrap;
291
- color: var(--rel-select-value-color, var(--rel-text-default));
292
- overflow: hidden;
293
- }
294
-
295
- .select-value.placeholder {
296
- color: var(--rel-select-placeholder-color, var(--rel-text-placeholder));
297
- }
298
-
299
- .select-wrapper.disabled .select-value.placeholder {
300
- color: var(--rel-select-placeholder-disabled-color, var(--rel-text-disabled));
301
- }
302
-
303
- .select-value-text {
304
- overflow: hidden;
305
- text-overflow: ellipsis;
306
- white-space: nowrap;
307
- }
308
-
309
- /* Chips never wrap — the number of rendered chips adapts to the
310
- available width instead (see computeVisibleChips), collapsing the
311
- remainder into a trailing "+N" chip. overflow:hidden guards the one
312
- frame between a resize and the recomputation catching up. */
313
- .select-chips {
314
- display: flex;
315
- align-items: center;
316
- gap: 6px;
317
- flex-wrap: nowrap;
318
- min-width: 0;
319
- overflow: hidden;
320
- }
321
-
322
- /* Invisible copy of ALL selected chips (plus a worst-case "+N" chip),
323
- laid out unconstrained so computeVisibleChips can read each chip's
324
- natural width — including chips currently collapsed into "+N", whose
325
- widths are needed again when the field grows. */
326
- .select-chips-measure {
327
- position: absolute;
328
- top: 0;
329
- left: 0;
330
- display: flex;
331
- align-items: center;
332
- gap: 6px;
333
- width: max-content;
334
- visibility: hidden;
335
- pointer-events: none;
336
- }
337
-
338
- /* rel-chip's outer element is a tabindex="0" span, not a native button —
339
- a disabled native <button> ancestor doesn't suppress clicks on that
340
- automatically the way it would for a nested native form control, so
341
- this has to be switched off explicitly. The cursor still correctly
342
- falls through to the disabled trigger underneath. */
343
- .select-wrapper.disabled .select-chips {
344
- pointer-events: none;
345
- }
346
-
347
- /* Floating label — single element that animates between resting (inside,
348
- at the value position) and floated (small, on the border line), same
349
- mechanism as rel-textfield's [floatinglabel]. */
350
- .floating-label {
351
- position: absolute;
352
- left: 12px;
353
- top: 50%;
354
- transform: translateY(-50%);
355
- background: var(--rel-select-bg, var(--rel-bg-neutral));
356
- padding: 0 4px;
357
- color: var(--rel-select-placeholder-color, var(--rel-text-placeholder));
358
- pointer-events: none;
359
- z-index: 1;
360
- white-space: nowrap;
361
- transition: top 0.15s ease, left 0.15s ease, font-size 0.15s ease, color 0.15s ease;
362
- font-family: var(--rel-body-md-regular-font-family);
363
- font-weight: var(--rel-body-md-regular-font-weight);
364
- font-size: var(--rel-body-md-regular-font-size);
365
- line-height: var(--rel-body-md-regular-line-height);
366
- letter-spacing: var(--rel-body-md-regular-letter-spacing);
367
- }
368
-
369
- .floating-label.has-left-icon {
370
- left: 40px;
371
- }
372
-
373
- .select-wrapper.focused .floating-label,
374
- .select-wrapper.has-value .floating-label,
375
- .select-wrapper.open .floating-label {
376
- top: 0;
377
- left: 12px;
378
- font-size: var(--rel-body-sm-medium-font-size);
379
- line-height: var(--rel-body-sm-medium-line-height);
380
- letter-spacing: var(--rel-body-sm-medium-letter-spacing);
381
- font-weight: var(--rel-body-xs-medium-font-weight);
382
- color: var(--rel-select-label-color, var(--rel-text-label));
383
- }
384
-
385
- /* The real placeholder hides while the float-label rests in its spot,
386
- and fades in once the label has moved up to the border. */
387
- .select-wrapper.floating .select-value.placeholder {
388
- opacity: 0;
389
- transition: opacity 0.1s ease;
390
- }
391
-
392
- .select-wrapper.floating.focused .select-value.placeholder,
393
- .select-wrapper.floating.open .select-value.placeholder {
394
- opacity: 1;
395
- }
396
-
397
- /* Supporting text */
398
- .select-support {
399
- margin-top: var(--rel-spacing-3xs);
400
- font-size: 13px;
401
- color: var(--rel-select-supporting-color, var(--rel-text-caption));
402
- }
403
-
404
- .select-support.error {
405
- color: var(--rel-text-danger);
406
- }
407
-
408
- /* ── Dropdown listbox ── */
409
- .select-listbox {
410
- position: fixed;
411
- z-index: 1001;
412
- display: none;
413
- /* Reset native [popover] UA styles (the listbox is promoted to the
414
- top layer so transformed ancestors — e.g. a centered rel-modal
415
- panel — can't hijack its containing block or clip it). */
416
- inset: auto;
417
- margin: 0;
418
- padding: 0;
419
- width: auto;
420
- height: auto;
421
- color: inherit;
422
- box-sizing: border-box;
423
- background: var(--rel-select-bg, var(--rel-bg-neutral));
424
- border: 1px solid var(--rel-select-menu-border, var(--rel-border-default));
425
- border-radius: var(--rel-select-menu-radius, var(--rel-border-radius-sm));
426
- /* A border alone doesn't read clearly against a similarly-light page,
427
- and a shadow alone barely shows on a dark background — together
428
- they hold up in both themes. */
429
- box-shadow: var(--rel-select-menu-shadow, var(--rel-shadows-shadow-300));
430
- max-height: 360px;
431
- overflow-y: auto;
432
- }
433
-
434
- .select-listbox[data-open] {
435
- display: block;
436
- }
437
-
438
- /* Search and Select All pin together while the options scroll beneath.
439
- z-index is load-bearing: multiselect rows contain rel-checkbox, whose
440
- .row wrapper is position:relative (Tab-scroll fix), so without it the
441
- positioned rows paint over the sticky header in DOM order. */
442
- .select-header {
443
- position: sticky;
444
- top: 0;
445
- z-index: 1;
446
- background: var(--rel-select-bg, var(--rel-bg-neutral));
447
- }
448
-
449
- .select-search {
450
- padding: var(--rel-spacing-xs);
451
- border-bottom: 1px solid var(--rel-select-divider, var(--rel-border-subtle));
452
- }
453
-
454
- /* Base = "small" textfield sizing, shared by both small AND medium
455
- select — only "large" select bumps the search field up to "medium". */
456
- .search-input-wrap {
457
- display: flex;
458
- align-items: center;
459
- gap: 8px;
460
- border: 1px solid var(--rel-select-search-border, var(--rel-border-default));
461
- border-radius: 4px;
462
- padding: var(--rel-spacing-xs) var(--rel-spacing-sm);
463
- }
464
-
465
- .search-input-wrap .icon {
466
- display: flex;
467
- align-items: center;
468
- flex-shrink: 0;
469
- color: var(--rel-select-icon-color, var(--rel-text-default));
470
- }
471
-
472
- .search-input {
473
- flex: 1;
474
- min-width: 0;
475
- border: none;
476
- outline: none;
477
- background: transparent;
478
- color: var(--rel-select-value-color, var(--rel-text-default));
479
- font-family: var(--rel-body-sm-regular-font-family);
480
- font-weight: var(--rel-body-sm-regular-font-weight);
481
- font-size: var(--rel-body-sm-regular-font-size);
482
- line-height: var(--rel-body-sm-regular-line-height);
483
- letter-spacing: var(--rel-body-sm-regular-letter-spacing);
484
- }
485
-
486
- .search-input::placeholder {
487
- color: var(--rel-select-placeholder-color, var(--rel-text-placeholder));
488
- }
489
-
490
- :host([size="large"]) .search-input-wrap {
491
- padding: 12px;
492
- }
493
-
494
- :host([size="large"]) .search-input {
495
-
496
- font-family: var(--rel-body-md-regular-font-family);
497
-
498
- font-weight: var(--rel-body-md-regular-font-weight);
499
-
500
- font-size: var(--rel-body-md-regular-font-size);
501
-
502
- line-height: var(--rel-body-md-regular-line-height);
503
-
504
- letter-spacing: var(--rel-body-md-regular-letter-spacing);
505
-
506
- }
507
-
508
- .select-options {
509
- padding: 4px 0;
510
- }
511
-
512
- .select-option {
513
- display: flex;
514
- align-items: center;
515
- justify-content: space-between;
516
- gap: 12px;
517
- padding: var(--rel-spacing-xs) 12px;
518
- color: var(--rel-select-value-color, var(--rel-text-default));
519
- cursor: pointer;
520
- font-family: var(--rel-body-md-regular-font-family);
521
- font-weight: var(--rel-body-md-regular-font-weight);
522
- font-size: var(--rel-body-md-regular-font-size);
523
- line-height: var(--rel-body-md-regular-line-height);
524
- letter-spacing: var(--rel-body-md-regular-letter-spacing);
525
- }
526
-
527
- /* Groups the optional prefix icon with the label so the trailing
528
- check indicator stays pinned to the right edge of the row. */
529
- .select-option-content {
530
- flex: 1;
531
- min-width: 0;
532
- display: flex;
533
- align-items: center;
534
- gap: var(--rel-spacing-xs);
535
- }
536
-
537
- .select-option-icon {
538
- flex-shrink: 0;
539
- color: var(--rel-select-icon-color, var(--rel-text-default));
540
- }
541
-
542
- .select-option-label {
543
- overflow: hidden;
544
- text-overflow: ellipsis;
545
- white-space: nowrap;
546
- }
547
-
548
- .select-option-check {
549
- flex-shrink: 0;
550
- color: var(--rel-select-value-color, var(--rel-text-default));
551
- }
552
-
553
- .select-option:hover,
554
- .select-option.highlighted {
555
- background: var(--rel-select-option-hover, var(--rel-bg-neutral-elevated-1));
556
- }
557
-
558
- .select-option[aria-selected="true"] {
559
- font-weight: var(--rel-body-md-medium-font-weight);
560
- }
561
-
562
- :host([size="large"]) .select-option[aria-selected="true"] {
563
- font-weight: var(--rel-body-lg-medium-font-weight);
564
- }
565
-
566
- .checkbox-option {
567
- padding: 12px;
568
- }
569
-
570
- .checkbox-option:hover,
571
- .checkbox-option.highlighted {
572
- background: var(--rel-select-option-hover, var(--rel-bg-neutral-elevated-1));
573
- }
574
-
575
- .select-all-row {
576
- border-bottom: 1px solid var(--rel-select-divider, var(--rel-border-subtle));
577
- padding: 12px;
578
- }
579
-
580
- .select-all-row.highlighted {
581
- background: var(--rel-select-option-hover, var(--rel-bg-neutral-elevated-1));
582
- }
583
-
584
- .select-empty {
585
- padding: var(--rel-spacing-xs) 12px;
586
- color: var(--rel-select-placeholder-color, var(--rel-text-body));
587
- font-family: var(--rel-body-sm-regular-font-family);
588
- font-weight: var(--rel-body-sm-regular-font-weight);
589
- font-size: var(--rel-body-sm-regular-font-size);
590
- line-height: var(--rel-body-sm-regular-line-height);
591
- letter-spacing: var(--rel-body-sm-regular-letter-spacing);
592
- }
593
-
594
- `;
595
-
596
- connectedCallback() {
597
- super.connectedCallback();
598
- // firstUpdated only runs once — re-observe if the element is re-attached.
599
- if (this.chipResizeObserver && this.triggerEl) {
600
- this.chipResizeObserver.observe(this.triggerEl);
601
- }
602
- }
603
-
604
- disconnectedCallback() {
605
- super.disconnectedCallback();
606
- this.removeGlobalListeners();
607
- this.hideNativePopover();
608
- this.chipResizeObserver?.disconnect();
609
- }
610
-
611
- protected firstUpdated() {
612
- this.chipResizeObserver = new ResizeObserver(() => this.computeVisibleChips());
613
- this.chipResizeObserver.observe(this.triggerEl);
614
- }
615
-
616
- protected willUpdate(changed: PropertyValues<this>) {
617
- if (changed.has("multiple") && this.multiple === false) {
618
- this.selectedValues = [];
619
- }
620
- }
621
-
622
- private _warnedNoName = false;
623
-
624
- protected updated(changed: PropertyValues<this>) {
625
- if (
626
- !this._warnedNoName &&
627
- this.labelStyle === "none" &&
628
- !this.fieldAriaLabel &&
629
- !this.fieldAriaLabelledby &&
630
- !this.getAttribute("aria-label")
631
- ) {
632
- this._warnedNoName = true;
633
- console.warn(
634
- '<rel-select label-style="none"> has no accessible name. Set ' +
635
- "`field-aria-label` or `field-aria-labelledby` — a placeholder is not a " +
636
- "valid naming mechanism.",
637
- this
638
- );
639
- }
640
-
641
- if (
642
- changed.has("selectedValues") ||
643
- changed.has("options") ||
644
- changed.has("multiple") ||
645
- changed.has("size")
646
- ) {
647
- // rAF: rel-chip renders in its own (microtask) update cycle, so its
648
- // width isn't measurable synchronously here — by the next frame it is.
649
- requestAnimationFrame(() => this.computeVisibleChips());
650
- }
651
- }
652
-
653
- /**
654
- * Width-adaptive chip collapsing: measures every selected chip in the
655
- * hidden .select-chips-measure row and works out how many fit in the value
656
- * area, always reserving room for the trailing "+N" chip when not all fit.
657
- * At least one chip stays visible no matter how narrow the field gets.
658
- */
659
- private computeVisibleChips() {
660
- if (!this.isConnected || !this.multiple || this.selectedValues.length === 0) return;
661
- const measure = this.chipsMeasureEl;
662
- const container = this.valueEl;
663
- if (!measure || !container) return;
664
-
665
- const available = container.clientWidth;
666
- if (available <= 0) return; // hidden (display:none) — RO will refire when visible
667
-
668
- const children = Array.from(measure.children) as HTMLElement[];
669
- if (children.length < 2) return;
670
-
671
- const gap = RelSelect.CHIP_GAP;
672
- // Last measure child is the worst-case "+N" chip (N = total selected,
673
- // i.e. the widest label the badge can ever need).
674
- const overflowWidth = children[children.length - 1].offsetWidth;
675
- const chipWidths = children.slice(0, -1).map((c) => c.offsetWidth);
676
- const total = chipWidths.reduce((sum, w) => sum + w, 0) + gap * (chipWidths.length - 1);
677
-
678
- let fit: number;
679
- if (total <= available) {
680
- fit = chipWidths.length;
681
- } else {
682
- fit = 0;
683
- let used = 0;
684
- for (let i = 0; i < chipWidths.length; i++) {
685
- const w = chipWidths[i] + (i > 0 ? gap : 0);
686
- if (used + w + gap + overflowWidth <= available) {
687
- used += w;
688
- fit = i + 1;
689
- } else {
690
- break;
691
- }
692
- }
693
- fit = Math.max(1, fit);
694
- }
695
-
696
- if (fit !== this.visibleChipCount) this.visibleChipCount = fit;
697
- }
698
-
699
- private get normalizedOptions(): NormalizedOption[] {
700
- return this.options.map(normalizeOption);
701
- }
702
-
703
- /** Options matching the current search text (substring match, case-insensitive). */
704
- private get filteredOptions(): NormalizedOption[] {
705
- const opts = this.normalizedOptions;
706
- if (!this.searchValue) return opts;
707
- const v = this.searchValue.toLowerCase();
708
- return opts.filter((o) => o.label.toLowerCase().includes(v));
709
- }
710
-
711
- private get hasValue(): boolean {
712
- return this.multiple ? this.selectedValues.length > 0 : !!this.selected;
713
- }
714
-
715
- /** Icon size scales with the select's own size, matching the trigger. */
716
- private get iconSize(): "xs" | "sm" | "md" {
717
- return this.size === "small" ? "xs" : this.size === "large" ? "md" : "sm";
718
- }
719
-
720
- /** The search field uses "small" sizing for both small and medium select — only "large" select bumps it to "medium". */
721
- private get searchIconSize(): "sm" | "md" {
722
- return this.size === "large" ? "md" : "sm";
723
- }
724
-
725
- private get selectAllStatus(): "checked" | "unchecked" | "indeterminate" {
726
- const filtered = this.filteredOptions;
727
- if (filtered.length === 0) return "unchecked";
728
- const selectedCount = filtered.filter((o) => this.selectedValues.includes(o.value)).length;
729
- if (selectedCount === 0) return "unchecked";
730
- if (selectedCount === filtered.length) return "checked";
731
- return "indeterminate";
732
- }
733
-
734
- private addGlobalListeners() {
735
- // Capture phase so a pointerdown that another component stops in its own
736
- // capture listener (e.g. a rel-popover trigger) still closes this listbox.
737
- document.addEventListener("pointerdown", this.onOutsidePointerDown, true);
738
- window.addEventListener("resize", this.updatePosition);
739
- window.addEventListener("scroll", this.onPageScroll, true);
740
- }
741
-
742
- private removeGlobalListeners() {
743
- document.removeEventListener("pointerdown", this.onOutsidePointerDown, true);
744
- window.removeEventListener("resize", this.updatePosition);
745
- window.removeEventListener("scroll", this.onPageScroll, true);
746
- }
747
-
748
- private onOutsidePointerDown = (e: PointerEvent) => {
749
- if (!this.open) return;
750
- const path = e.composedPath();
751
- if (path.includes(this)) return;
752
- this.closeListbox();
753
- };
754
-
755
- // Continuously re-deriving a fixed-position panel's coordinates from
756
- // every page scroll event is fragile (it's what was causing the panel to
757
- // jump to the top of the viewport). Instead, close the panel on any
758
- // *outside* scroll, same as clicking outside — scrolling the option list
759
- // itself (target is the listbox) is the one case that should NOT close it.
760
- private onPageScroll = (e: Event) => {
761
- if (!this.open) return;
762
- if (e.composedPath()[0] === this.listboxEl) return;
763
- this.closeListbox();
764
- };
765
-
766
- private emitChange() {
767
- this.dispatchEvent(
768
- new CustomEvent("changed", {
769
- detail: { value: this.multiple ? this.selectedValues : this.selected },
770
- bubbles: true,
771
- composed: true,
772
- })
773
- );
774
- }
775
-
776
- private openListbox() {
777
- if (this.state === "disabled" || this.open) return;
778
- this.open = true;
779
- this.searchValue = "";
780
- // No pre-highlight — the first item showing a hover-style highlight
781
- // before the user has touched anything reads as an unintended default.
782
- // Highlight only kicks in once they actually hover or press an arrow key.
783
- this.highlightedIndex = -1;
784
- this.selectAllHighlighted = false;
785
- this.addGlobalListeners();
786
- requestAnimationFrame(() => {
787
- this.showNativePopover();
788
- this.updatePosition();
789
- // preventScroll: focusing the search field must not let the browser
790
- // scroll the page into view — that would move the trigger (normal
791
- // flow) out from under the panel (fixed position, already computed
792
- // above), breaking the anchor. When there's no search field, focus
793
- // simply stays on the trigger, which already has the nav keydown
794
- // handling wired up for this case.
795
- if (!this.noSearch) {
796
- this.searchInputEl?.focus({ preventScroll: true });
797
- }
798
- });
799
- }
800
-
801
- private closeListbox() {
802
- if (!this.open) return;
803
- this.open = false;
804
- this.removeGlobalListeners();
805
- this.hideNativePopover();
806
- this.triggerEl?.focus();
807
- }
808
-
809
- /* A transformed ancestor (e.g. rel-modal's centered panel with
810
- * translate(-50%,-50%)) becomes the containing block for position:fixed
811
- * descendants, breaking viewport-based coordinates and letting the
812
- * panel's overflow:hidden clip the listbox. Promoting the listbox to
813
- * the browser top layer sidesteps both — same fix as rel-popover /
814
- * rel-autocomplete. `manual` keeps light-dismiss and Escape handling
815
- * under this component's own control. */
816
-
817
- private showNativePopover() {
818
- const p = this.listboxEl;
819
- if (!p || typeof p.showPopover !== "function") return;
820
- try {
821
- if (!p.matches(":popover-open")) p.showPopover();
822
- } catch {
823
- /* older engines / detached element — fixed-position fallback applies */
824
- }
825
- }
826
-
827
- private hideNativePopover() {
828
- const p = this.listboxEl;
829
- if (!p || typeof p.hidePopover !== "function") return;
830
- try {
831
- if (p.matches(":popover-open")) p.hidePopover();
832
- } catch {
833
- /* already hidden or unsupported — nothing to do */
834
- }
835
- }
836
-
837
- private updatePosition = () => {
838
- if (!this.triggerEl || !this.listboxEl) return;
839
-
840
- this.listboxEl.setAttribute("data-open", "");
841
-
842
- const t = this.triggerEl.getBoundingClientRect();
843
- const c = this.listboxEl.getBoundingClientRect();
844
-
845
- let top = t.bottom + 4;
846
- if (top + c.height > window.innerHeight - 8) {
847
- top = Math.max(8, t.top - c.height - 4);
848
- }
849
-
850
- // Use t.width (the trigger's width, which is also what we set the panel's
851
- // own width to below) rather than c.width — c.width reflects the
852
- // *previous* render's panelStyle, so on the very next measurement it can
853
- // be a frame stale, nudging left by a few px even when there's no real
854
- // overflow. Checking against t.width directly removes that drift.
855
- let left = t.left;
856
- if (left + t.width > window.innerWidth - 8) {
857
- left = Math.max(8, window.innerWidth - t.width - 8);
858
- }
859
-
860
- // Without top-layer support a transformed ancestor may be the containing
861
- // block for position:fixed, shifting the listbox away from the viewport
862
- // coordinates computed above. Apply, re-measure, and cancel the offset.
863
- this.listboxEl.style.top = `${top}px`;
864
- this.listboxEl.style.left = `${left}px`;
865
- this.listboxEl.style.width = `${t.width}px`;
866
- const applied = this.listboxEl.getBoundingClientRect();
867
- top -= applied.top - top;
868
- left -= applied.left - left;
869
- this.listboxEl.style.top = `${top}px`;
870
- this.listboxEl.style.left = `${left}px`;
871
-
872
- this.panelStyle = `top:${top}px;left:${left}px;width:${t.width}px;`;
873
- };
874
-
875
- private selectSingleOption(option: NormalizedOption) {
876
- this.selected = option.value;
877
- if (this.state === "error") this.state = "default";
878
- this.closeListbox();
879
- this.emitChange();
880
- }
881
-
882
- private toggleMultiOption(option: NormalizedOption) {
883
- const idx = this.selectedValues.indexOf(option.value);
884
- this.selectedValues =
885
- idx >= 0
886
- ? this.selectedValues.filter((v) => v !== option.value)
887
- : [...this.selectedValues, option.value];
888
- announce(`${option.label} ${idx >= 0 ? "deselected" : "selected"}`);
889
- if (this.state === "error") this.state = "default";
890
- this.emitChange();
891
- }
892
-
893
- private toggleSelectAll() {
894
- const filtered = this.filteredOptions;
895
- const status = this.selectAllStatus;
896
- if (status === "checked") {
897
- const filteredValues = new Set(filtered.map((o) => o.value));
898
- this.selectedValues = this.selectedValues.filter((v) => !filteredValues.has(v));
899
- } else {
900
- const toAdd = filtered.map((o) => o.value).filter((v) => !this.selectedValues.includes(v));
901
- this.selectedValues = [...this.selectedValues, ...toAdd];
902
- }
903
- announce(status === "checked" ? "All options deselected" : "All options selected");
904
- if (this.state === "error") this.state = "default";
905
- this.emitChange();
906
- }
907
-
908
- private removeChip(value: string) {
909
- if (this.state === "disabled") return;
910
- this.selectedValues = this.selectedValues.filter((v) => v !== value);
911
- const opt = this.normalizedOptions.find((o) => o.value === value);
912
- announce(`${opt?.label ?? value} removed`);
913
- this.emitChange();
914
- }
915
-
916
- private onTriggerClick() {
917
- if (this.open) this.closeListbox();
918
- else this.openListbox();
919
- }
920
-
921
- private onTriggerKeyDown(e: KeyboardEvent) {
922
- if (this.state === "disabled") return;
923
-
924
- // Chips render inside the trigger <button>, so their remove buttons can
925
- // never be tab stops — Backspace/Delete is the keyboard path for
926
- // removing the most recent selection (standard multi-combobox behavior).
927
- if (
928
- this.multiple &&
929
- (e.key === "Backspace" || e.key === "Delete") &&
930
- this.selectedValues.length > 0
931
- ) {
932
- e.preventDefault();
933
- this.removeChip(this.selectedValues[this.selectedValues.length - 1]);
934
- return;
935
- }
936
-
937
- if (!this.open) {
938
- if (["ArrowDown", "ArrowUp", "Enter", " "].includes(e.key)) {
939
- e.preventDefault();
940
- this.openListbox();
941
- }
942
- return;
943
- }
944
- // No search field to hold focus/keydown in this mode — the trigger
945
- // itself keeps focus while open, so it needs the same nav handling.
946
- if (this.noSearch) this.handleListNavigation(e);
947
- }
948
-
949
- private onSearchInput = (e: InputEvent) => {
950
- this.searchValue = (e.target as HTMLInputElement).value;
951
- const count = this.filteredOptions.length;
952
- this.highlightedIndex = count > 0 ? 0 : -1;
953
- this.selectAllHighlighted = false;
954
- if (count === 0) {
955
- announce(this.options.length === 0 ? "No options available" : "No matches found");
956
- } else {
957
- announce(`${count} option${count === 1 ? "" : "s"} available`);
958
- }
959
- requestAnimationFrame(() => this.updatePosition());
960
- };
961
-
962
- private onSearchKeyDown(e: KeyboardEvent) {
963
- // Backspace in an empty search field removes the last chip (see
964
- // onTriggerKeyDown for the rationale).
965
- if (
966
- this.multiple &&
967
- e.key === "Backspace" &&
968
- this.searchValue === "" &&
969
- this.selectedValues.length > 0
970
- ) {
971
- this.removeChip(this.selectedValues[this.selectedValues.length - 1]);
972
- return;
973
- }
974
- this.handleListNavigation(e);
975
- }
976
-
977
- private handleListNavigation(e: KeyboardEvent) {
978
- const filtered = this.filteredOptions;
979
- // The Select-All row participates in arrow navigation as a virtual row
980
- // above the first option — it lives in the panel header, outside the
981
- // option list, and would otherwise be keyboard-unreachable.
982
- const hasSelectAll = this.multiple && filtered.length > 0;
983
-
984
- switch (e.key) {
985
- case "ArrowDown":
986
- e.preventDefault();
987
- if (this.selectAllHighlighted) {
988
- this.selectAllHighlighted = false;
989
- this.highlightedIndex = filtered.length > 0 ? 0 : -1;
990
- } else if (this.highlightedIndex === -1 && hasSelectAll) {
991
- this.selectAllHighlighted = true;
992
- } else {
993
- this.highlightedIndex = Math.min(filtered.length - 1, this.highlightedIndex + 1);
994
- }
995
- this.scrollHighlightedIntoView();
996
- break;
997
- case "ArrowUp":
998
- e.preventDefault();
999
- if (!this.selectAllHighlighted && this.highlightedIndex <= 0 && hasSelectAll) {
1000
- this.highlightedIndex = -1;
1001
- this.selectAllHighlighted = true;
1002
- } else {
1003
- this.highlightedIndex = Math.max(0, this.highlightedIndex - 1);
1004
- }
1005
- this.scrollHighlightedIntoView();
1006
- break;
1007
- case "Home":
1008
- if (filtered.length === 0) break;
1009
- e.preventDefault();
1010
- this.selectAllHighlighted = false;
1011
- this.highlightedIndex = 0;
1012
- this.scrollHighlightedIntoView();
1013
- break;
1014
- case "End":
1015
- if (filtered.length === 0) break;
1016
- e.preventDefault();
1017
- this.selectAllHighlighted = false;
1018
- this.highlightedIndex = filtered.length - 1;
1019
- this.scrollHighlightedIntoView();
1020
- break;
1021
- case " ":
1022
- // With a search field, Space types into it; only the no-search mode
1023
- // (trigger holds focus) treats Space as toggle/select.
1024
- if (!this.noSearch) return;
1025
- e.preventDefault();
1026
- this.activateHighlighted();
1027
- break;
1028
- case "Enter":
1029
- e.preventDefault();
1030
- this.activateHighlighted();
1031
- break;
1032
- case "Escape":
1033
- e.preventDefault();
1034
- this.closeListbox();
1035
- break;
1036
- case "Tab":
1037
- this.closeListbox();
1038
- break;
1039
- default:
1040
- this.handleTypeahead(e);
1041
- break;
1042
- }
1043
- }
1044
-
1045
- /** APG typeahead for the no-search mode (with a search field, typing
1046
- * filters instead). Accumulates printable keys for 500 ms and jumps the
1047
- * highlight to the next option whose label starts with the buffer. */
1048
- private handleTypeahead(e: KeyboardEvent) {
1049
- if (!this.noSearch) return;
1050
- if (e.key.length !== 1 || e.ctrlKey || e.metaKey || e.altKey) return;
1051
-
1052
- e.preventDefault();
1053
- const isNewQuery = this.typeaheadBuffer === "";
1054
- this.typeaheadBuffer += e.key.toLowerCase();
1055
- clearTimeout(this.typeaheadTimer);
1056
- this.typeaheadTimer = window.setTimeout(() => {
1057
- this.typeaheadBuffer = "";
1058
- }, 500);
1059
-
1060
- const filtered = this.filteredOptions;
1061
- if (filtered.length === 0) return;
1062
-
1063
- // A fresh single-letter query starts searching AFTER the highlight (so
1064
- // repeated presses cycle through matches); a growing buffer re-tests the
1065
- // current one first.
1066
- const start = Math.max(0, this.highlightedIndex) + (isNewQuery ? 1 : 0);
1067
- for (let offset = 0; offset < filtered.length; offset++) {
1068
- const idx = (start + offset) % filtered.length;
1069
- if (filtered[idx].label.toLowerCase().startsWith(this.typeaheadBuffer)) {
1070
- this.selectAllHighlighted = false;
1071
- this.highlightedIndex = idx;
1072
- this.scrollHighlightedIntoView();
1073
- return;
1074
- }
1075
- }
1076
- }
1077
-
1078
- private activateHighlighted() {
1079
- if (this.selectAllHighlighted) {
1080
- this.toggleSelectAll();
1081
- return;
1082
- }
1083
- const filtered = this.filteredOptions;
1084
- if (this.highlightedIndex >= 0 && filtered[this.highlightedIndex]) {
1085
- const opt = filtered[this.highlightedIndex];
1086
- if (this.multiple) this.toggleMultiOption(opt);
1087
- else this.selectSingleOption(opt);
1088
- }
1089
- }
1090
-
1091
- private scrollHighlightedIntoView() {
1092
- if (this.highlightedIndex < 0) return;
1093
- requestAnimationFrame(() => {
1094
- this.renderRoot
1095
- .querySelector<HTMLElement>(`#${this.uniqueId}-option-${this.highlightedIndex}`)
1096
- ?.scrollIntoView({ block: "nearest" });
1097
- });
1098
- }
1099
-
1100
- private renderChips() {
1101
- const values = this.selectedValues;
1102
- const visible = values.slice(0, Math.min(this.visibleChipCount, this.maxVisibleChips));
1103
- const overflow = values.length - visible.length;
1104
- const opts = this.normalizedOptions;
1105
-
1106
- return html`
1107
- <span class="select-chips">
1108
- ${repeat(
1109
- visible,
1110
- (v) => v,
1111
- (v) => {
1112
- const opt = opts.find((o) => o.value === v);
1113
- // Keyed by value: rel-chip tracks its own "removed" flag
1114
- // internally once its (x) is clicked, so reusing DOM nodes
1115
- // positionally (plain .map()) could hand a freshly-shown value
1116
- // a node that still remembers being removed as a *different*
1117
- // value. Keying forces a fresh node per value instead.
1118
- return html`
1119
- <rel-chip
1120
- label="${opt?.label ?? v}"
1121
- size="sm"
1122
- variant="subtle"
1123
- border="default"
1124
- ?removable=${this.state !== "disabled"}
1125
- @click=${(e: Event) => e.stopPropagation()}
1126
- @removed=${(e: Event) => {
1127
- e.stopPropagation();
1128
- this.removeChip(v);
1129
- }}
1130
- ></rel-chip>
1131
- `;
1132
- }
1133
- )}
1134
- ${overflow > 0
1135
- ? html`<rel-chip label="+${overflow}" size="sm" variant="fill" border="default"></rel-chip>`
1136
- : nothing}
1137
- </span>
1138
- `;
1139
- }
1140
-
1141
- /**
1142
- * Hidden, unconstrained copy of every selected chip used purely for width
1143
- * measurement (see computeVisibleChips). Chips mirror the visible ones'
1144
- * width-affecting props (removable adds the ✕ icon). The trailing chip is
1145
- * the widest "+N" badge that could ever be needed.
1146
- */
1147
- private renderChipsMeasure() {
1148
- const values = this.selectedValues;
1149
- const opts = this.normalizedOptions;
1150
- return html`
1151
- <span class="select-chips-measure" aria-hidden="true">
1152
- ${values.map((v) => {
1153
- const opt = opts.find((o) => o.value === v);
1154
- return html`
1155
- <rel-chip
1156
- label="${opt?.label ?? v}"
1157
- size="sm"
1158
- variant="subtle"
1159
- border="default"
1160
- ?removable=${this.state !== "disabled"}
1161
- ></rel-chip>
1162
- `;
1163
- })}
1164
- <rel-chip label="+${values.length}" size="sm" variant="fill" border="default"></rel-chip>
1165
- </span>
1166
- `;
1167
- }
1168
-
1169
- render() {
1170
- const opts = this.normalizedOptions;
1171
- const filtered = this.filteredOptions;
1172
- const isDisabled = this.state === "disabled";
1173
- const labelHidden = this.labelStyle === "none";
1174
- const showFloatingChrome = this.labelStyle === "floating" && !!this.label;
1175
- // With no visible label the ARIA name comes from fieldAriaLabel instead.
1176
- const accessibleName = (labelHidden ? this.fieldAriaLabel : this.label) || "";
1177
-
1178
- const wrapperClasses = [
1179
- "select-wrapper",
1180
- this.size,
1181
- this.state,
1182
- `border-${this.border}`,
1183
- showFloatingChrome ? "floating" : "",
1184
- this.internalState === "focused" ? "focused" : "",
1185
- this.hasValue ? "has-value" : "",
1186
- this.open ? "open" : "",
1187
- ]
1188
- .filter(Boolean)
1189
- .join(" ");
1190
-
1191
- const listboxId = `${this.uniqueId}-listbox`;
1192
- const activeOptionId = !this.open
1193
- ? ""
1194
- : this.selectAllHighlighted
1195
- ? `${this.uniqueId}-select-all`
1196
- : this.highlightedIndex >= 0
1197
- ? `${this.uniqueId}-option-${this.highlightedIndex}`
1198
- : "";
1199
-
1200
- const selectedSingle = opts.find((o) => o.value === this.selected);
1201
-
1202
- const baseName = accessibleName || this.placeholder;
1203
- let triggerLabel = baseName;
1204
- if (this.multiple && this.selectedValues.length > 0) {
1205
- const labels = this.selectedValues.map((v) => opts.find((o) => o.value === v)?.label ?? v);
1206
- const shown = labels.slice(0, 3);
1207
- const more = labels.length - shown.length;
1208
- triggerLabel = `${baseName}, ${shown.join(", ")}${more > 0 ? `, plus ${more} more` : ""}`;
1209
- } else if (!this.multiple && selectedSingle) {
1210
- triggerLabel = `${baseName}, ${selectedSingle.label}`;
1211
- }
1212
-
1213
- return html`
1214
- <div class="${wrapperClasses}">
1215
- ${labelHidden
1216
- ? html`<div class="label-reserve" aria-hidden="true"></div>`
1217
- : !showFloatingChrome && this.label
1218
- ? html`<label part="label" class="select-label" for="${this.uniqueId}">${this.label}</label>`
1219
- : ""}
1220
-
1221
- <div class="select-container">
1222
- ${showFloatingChrome
1223
- ? html`<span class="floating-label${this.leftIcon ? " has-left-icon" : ""}"
1224
- >${this.label}</span
1225
- >`
1226
- : ""}
1227
-
1228
- <button
1229
- id="${this.uniqueId}"
1230
- type="button"
1231
- part="trigger" class="select-trigger"
1232
- role="combobox"
1233
- aria-haspopup="listbox"
1234
- aria-expanded="${this.open}"
1235
- aria-controls="${listboxId}"
1236
- aria-activedescendant="${this.noSearch ? activeOptionId : nothing}"
1237
- aria-invalid="${this.state === "error"}"
1238
- aria-label="${this.fieldAriaLabelledby ? nothing : triggerLabel}"
1239
- aria-labelledby="${this.fieldAriaLabelledby ?? nothing}"
1240
- ?disabled="${isDisabled}"
1241
- @click="${this.onTriggerClick}"
1242
- @keydown="${this.onTriggerKeyDown}"
1243
- @focus="${() => (this.internalState = "focused")}"
1244
- @blur="${() => (this.internalState = "default")}"
1245
- >
1246
- ${this.leftIcon
1247
- ? html`<rel-icon name="${this.leftIcon}" size="${this.iconSize}" class="icon left"></rel-icon>`
1248
- : ""}
1249
-
1250
- ${this.multiple
1251
- ? this.selectedValues.length > 0
1252
- ? html`<span part="value" class="select-value">${this.renderChips()}</span>`
1253
- : html`<span part="value" class="select-value placeholder">
1254
- <span class="select-value-text">${this.placeholder}</span>
1255
- </span>`
1256
- : html`<span part="value" class="select-value ${selectedSingle ? "" : "placeholder"}">
1257
- <span class="select-value-text"
1258
- >${selectedSingle ? selectedSingle.label : this.placeholder}</span
1259
- >
1260
- </span>`}
1261
-
1262
- <rel-icon
1263
- name="${this.rightIcon || "chevron-down"}"
1264
- size="${this.iconSize}"
1265
- class="icon ${this.rightIcon ? "" : "chevron"}"
1266
- ></rel-icon>
1267
- </button>
1268
-
1269
- ${this.multiple && this.selectedValues.length > 0 ? this.renderChipsMeasure() : nothing}
1270
- </div>
1271
-
1272
- ${this.supportingText
1273
- ? html`<span part="helper" class="select-support ${this.state === "error" ? "error" : ""}">
1274
- ${this.supportingText}
1275
- </span>`
1276
- : ""}
1277
- </div>
1278
-
1279
- <div
1280
- id="${listboxId}"
1281
- part="panel list" class="select-listbox"
1282
- popover="manual"
1283
- role="listbox"
1284
- aria-multiselectable="${this.multiple}"
1285
- aria-label="${accessibleName || "Options"}"
1286
- style="${this.panelStyle}"
1287
- ?data-open="${this.open}"
1288
- >
1289
- ${!this.noSearch || (this.multiple && filtered.length > 0)
1290
- ? html`<div class="select-header">
1291
- ${!this.noSearch
1292
- ? html`<div class="select-search">
1293
- <div class="search-input-wrap">
1294
- <rel-icon name="search" size="${this.searchIconSize}" class="icon"></rel-icon>
1295
- <input
1296
- part="input" class="search-input"
1297
- type="text"
1298
- role="combobox"
1299
- aria-expanded="${this.open}"
1300
- aria-controls="${listboxId}"
1301
- aria-activedescendant="${activeOptionId}"
1302
- aria-label="${accessibleName || this.placeholder}"
1303
- placeholder="${this.searchPlaceholder}"
1304
- .value="${this.searchValue}"
1305
- @input="${this.onSearchInput}"
1306
- @keydown="${(e: KeyboardEvent) => this.onSearchKeyDown(e)}"
1307
- />
1308
- </div>
1309
- </div>`
1310
- : ""}
1311
- ${this.multiple && filtered.length > 0
1312
- ? html`<div
1313
- id="${this.uniqueId}-select-all"
1314
- class="select-all-row ${this.selectAllHighlighted ? "highlighted" : ""}"
1315
- role="option"
1316
- aria-selected="${this.selectAllStatus === "checked"}"
1317
- aria-label="${this.selectAllLabel}"
1318
- @pointerenter="${() => {
1319
- this.selectAllHighlighted = true;
1320
- this.highlightedIndex = -1;
1321
- }}"
1322
- @pointerleave="${() => (this.selectAllHighlighted = false)}"
1323
- @mousedown="${(e: Event) => e.preventDefault()}"
1324
- @click="${() => this.toggleSelectAll()}"
1325
- >
1326
- <rel-checkbox
1327
- inert
1328
- aria-hidden="true"
1329
- label="${this.selectAllLabel}"
1330
- status="${this.selectAllStatus}"
1331
- ></rel-checkbox>
1332
- </div>`
1333
- : ""}
1334
- </div>`
1335
- : ""}
1336
-
1337
- ${filtered.length === 0
1338
- ? html`<div class="select-empty">
1339
- ${opts.length === 0 ? "No options available" : "No matches found"}
1340
- </div>`
1341
- : this.multiple
1342
- ? html`
1343
- <div class="select-options">
1344
- ${repeat(
1345
- filtered,
1346
- (option) => option.value,
1347
- (option, index) => html`
1348
- <div
1349
- id="${this.uniqueId}-option-${index}"
1350
- class="checkbox-option ${index === this.highlightedIndex ? "highlighted" : ""}"
1351
- role="option"
1352
- aria-selected="${this.selectedValues.includes(option.value)}"
1353
- aria-label="${option.label}"
1354
- @pointerenter="${() => {
1355
- this.highlightedIndex = index;
1356
- this.selectAllHighlighted = false;
1357
- }}"
1358
- @mousedown="${(e: Event) => e.preventDefault()}"
1359
- @click="${() => this.toggleMultiOption(option)}"
1360
- >
1361
- <rel-checkbox
1362
- inert
1363
- aria-hidden="true"
1364
- label="${option.label}"
1365
- icon="${option.icon}"
1366
- supportingtext="${option.supportingText}"
1367
- status="${this.selectedValues.includes(option.value) ? "checked" : "unchecked"}"
1368
- ></rel-checkbox>
1369
- </div>
1370
- `
1371
- )}
1372
- </div>
1373
- `
1374
- : html`
1375
- <div class="select-options">
1376
- ${repeat(
1377
- filtered,
1378
- (option) => option.value,
1379
- (option, index) => html`
1380
- <div
1381
- id="${this.uniqueId}-option-${index}"
1382
- part="option" class="select-option ${index === this.highlightedIndex ? "highlighted" : ""}"
1383
- role="option"
1384
- aria-selected="${option.value === this.selected}"
1385
- @mousedown="${(e: Event) => e.preventDefault()}"
1386
- @click="${() => this.selectSingleOption(option)}"
1387
- @pointerenter="${() => (this.highlightedIndex = index)}"
1388
- >
1389
- <span class="select-option-content">
1390
- ${option.icon
1391
- ? html`<rel-icon
1392
- name="${option.icon}"
1393
- size="sm"
1394
- class="select-option-icon"
1395
- ></rel-icon>`
1396
- : nothing}
1397
- <span class="select-option-label">${option.label}</span>
1398
- </span>
1399
- ${option.value === this.selected
1400
- ? html`<rel-icon name="check" size="sm" class="select-option-check"></rel-icon>`
1401
- : ""}
1402
- </div>
1403
- `
1404
- )}
1405
- </div>
1406
- `}
1407
- </div>
1408
- `;
1409
- }
1410
- }
1411
-
1412
- declare global {
1413
- interface HTMLElementTagNameMap {
1414
- "rel-select": RelSelect;
1415
- }
1416
- }