@celestia-island/hikari 0.55.412 → 0.55.413

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.
@@ -1,27 +1,49 @@
1
1
  // 2026-10-10 user direction — the ONE user-selection business component.
2
+ // 2026-11 user direction, second pass — "the whole project's thing has to
3
+ // be ONE component, a tooltip-style panel (not its own window — on phones
4
+ // that adapts to a bottom sheet), search on top and the candidates under
5
+ // it, and with an empty search bar the candidates must be EMPTY (listing
6
+ // everything would be absurd)".
2
7
  //
3
8
  // Every surface that needs "pick one or more users" renders this field:
4
9
  // selected members travel as tags (display name + email), and picking
5
- // happens through a search dialog — type a nickname, username or email,
6
- // the injected `search` callback answers from the backend, click a row.
7
- // The dialog is HkModal (a centered window on desktop, the bottom sheet
8
- // on mobile — HkModal's own responsive treatment) with an HkSearchInput
9
- // as its box. Hosts inject the search itself, so the component carries
10
- // zero transport: the panel wires its user-list RPC, another host could
11
- // wire anything that resolves a query to user options.
10
+ // happens in the ONE anchored panel the library already owns for this —
11
+ // HkSelectPanel, the same surface a dropdown opens (desktop popout under
12
+ // the field, phone bottom sheet), never a centered modal. So the family
13
+ // grows no second kind of window, and the panel geometry (width parity
14
+ // with the field, the surface's ONE scrollbar, Escape / outside-click
15
+ // closing, the back-gesture layer) is the shared surface's, not ours.
16
+ //
17
+ // SEARCH-FIRST CONTRACT: the panel opens with an EMPTY query and shows no
18
+ // candidates at all — a picker over the user directory must never list the
19
+ // directory on open. Typing (250ms debounce) is what queries the injected
20
+ // `search`; the newest answer wins (race token); a rejection renders a
21
+ // retry affordance, never a throw. Hosts inject the search itself, so the
22
+ // component still carries zero transport.
12
23
  //
13
24
  // Semantics (the HkAffixPicker vocabulary): "single" closes on pick and
14
- // replaces the selection; "multi" toggles rows in a working copy and
15
- // commits on Confirm. The field's tag × removes directly — no dialog.
25
+ // replaces the selection; "multi" toggles rows in a working copy, counts
26
+ // them in the panel footer and commits on Confirm. The field's tag ×
27
+ // removes directly — no panel involved.
16
28
  import { X } from "lucide-vue-next";
17
29
 
18
30
  import HkIconButton from "./HkIconButton";
19
31
 
20
- import { computed, defineComponent, ref, watch, type PropType } from "vue";
32
+ import {
33
+ computed,
34
+ defineComponent,
35
+ nextTick,
36
+ onBeforeUnmount,
37
+ ref,
38
+ useId,
39
+ watch,
40
+ type PropType,
41
+ } from "vue";
21
42
 
22
43
  import { useI18n } from "../i18n/context";
23
- import HkModal, { type ModalAction } from "./HkModal";
44
+ import HkButton from "./HkButton";
24
45
  import HkSearchInput from "./HkSearchInput";
46
+ import HkSelectPanel from "./HkSelectPanel";
25
47
  import "./HkUserPicker.scss";
26
48
 
27
49
  /** One pickable user. `uid` is the stable identity (what the host stores);
@@ -41,22 +63,32 @@ function tagTitle(user: HkUserOption): string {
41
63
  return user.displayName?.trim() || user.username;
42
64
  }
43
65
 
66
+ /** Typing pause before the injected search runs (the family's debounce —
67
+ * HkSearchInput's own default interval, owned here because Enter is bound
68
+ * to row selection and must not ALSO flush a search). */
69
+ const SEARCH_DEBOUNCE_MS = 250;
70
+
44
71
  export default defineComponent({
45
72
  name: "HkUserPicker",
46
73
  props: {
47
74
  modelValue: { type: Array as PropType<HkUserOption[]>, required: true },
48
75
  /** "single" replaces the selection on pick; "multi" accumulates (the
49
- * HkAffixPicker mode vocabulary). */
76
+ * HkAffixPicker mode vocabulary). */
50
77
  mode: { type: String as PropType<"single" | "multi">, default: "single" },
51
- /** Backend search: resolve a query (may be empty — the initial batch)
52
- * to user options. Rejections render as a retry hint, never a throw. */
78
+ /** Backend search: resolve a NON-EMPTY query to user options. The
79
+ * component never calls it for an empty query (empty input = empty
80
+ * candidate list, by contract). Rejections render as a retry hint,
81
+ * never a throw. */
53
82
  search: { type: Function as PropType<(query: string) => Promise<HkUserOption[]>>, required: true },
54
83
  label: { type: String, default: undefined },
55
84
  placeholder: { type: String, default: undefined },
56
85
  disabled: { type: Boolean, default: false },
57
86
  /** Rows rendered per query — a runaway backend answer cannot turn the
58
- * dialog into a thousand-row scroll. */
87
+ * panel into a thousand-row scroll. */
59
88
  maxResults: { type: Number, default: 50 },
89
+ /** Standing hint shown while the query is empty (the panel's opening
90
+ * state). Defaults to the i18n bundle's `userPicker.emptyInitial`. */
91
+ emptyHint: { type: String, default: undefined },
60
92
  },
61
93
  emits: {
62
94
  "update:modelValue": (_users: HkUserOption[]) => true,
@@ -64,17 +96,45 @@ export default defineComponent({
64
96
  setup(props, { emit }) {
65
97
  const { t } = useI18n();
66
98
 
99
+ const fieldRef = ref<HTMLElement | null>(null);
100
+ /** The panel surface (HkSelectPanel) — its exposed `panelEl()` scopes
101
+ * the two DOM queries this component needs (focus the search field on
102
+ * open, scroll the keyboard cursor into view) to OUR surface, never
103
+ * the document. */
104
+ const panelExpose = ref<{ panelEl: () => HTMLElement | null }>();
105
+
67
106
  const open = ref(false);
68
107
  const query = ref("");
69
108
  const results = ref<HkUserOption[]>([]);
70
109
  const loading = ref(false);
71
110
  const failed = ref(false);
111
+ /** Keyboard cursor into `results` (-1 = nothing active). Published as
112
+ * `aria-activedescendant` on the search field; focus never leaves it. */
113
+ const activeIndex = ref(-1);
72
114
  /** Multi-mode working copy — committed only on Confirm. */
73
115
  const draft = ref<HkUserOption[]>([]);
74
116
  /** Race guard: only the newest in-flight search may write results. */
75
117
  let searchToken = 0;
118
+ /** The pending debounce (one timer for the whole component). */
119
+ let debounceTimer: ReturnType<typeof setTimeout> | null = null;
120
+
121
+ const generatedId = useId();
122
+ const listboxId = `${generatedId}-listbox`;
123
+
124
+ /** DOM id of a result row — encoded so a uid with quotes / spaces (an
125
+ * email-shaped id) still resolves as one id everywhere. */
126
+ function optionId(user: HkUserOption): string {
127
+ return `${generatedId}-user-${encodeURIComponent(user.uid)}`;
128
+ }
76
129
 
77
- async function runSearch(q: string) {
130
+ function stopPendingSearch(): void {
131
+ if (debounceTimer !== null) {
132
+ clearTimeout(debounceTimer);
133
+ debounceTimer = null;
134
+ }
135
+ }
136
+
137
+ async function runSearch(q: string): Promise<void> {
78
138
  const token = ++searchToken;
79
139
  loading.value = true;
80
140
  failed.value = false;
@@ -82,44 +142,91 @@ export default defineComponent({
82
142
  const found = await props.search(q);
83
143
  if (token !== searchToken) return;
84
144
  results.value = (found ?? []).slice(0, props.maxResults);
145
+ // The row set moved: an index from the previous answer would name
146
+ // a different user (or none) — the cursor restarts unset.
147
+ activeIndex.value = -1;
85
148
  } catch {
86
149
  if (token !== searchToken) return;
87
150
  results.value = [];
151
+ activeIndex.value = -1;
88
152
  failed.value = true;
89
153
  } finally {
90
154
  if (token === searchToken) loading.value = false;
91
155
  }
92
156
  }
93
157
 
94
- const openDialog = () => {
95
- if (props.disabled) return;
96
- open.value = true;
97
- };
158
+ /** The empty-candidate arm: no request, no rows. Bumping the token
159
+ * orphans any in-flight answer so a late resolve cannot repopulate a
160
+ * list the user just cleared. */
161
+ function clearCandidates(): void {
162
+ searchToken += 1;
163
+ results.value = [];
164
+ loading.value = false;
165
+ failed.value = false;
166
+ activeIndex.value = -1;
167
+ }
98
168
 
99
- // One search per open, always: the input is keyed per session, so it
100
- // REMOUNTS on every open (a fresh mount receives modelValue "" and
101
- // its no-immediate watch fires nothing; the remounted instance also
102
- // drops any in-flight debounce from the previous session), and the
103
- // explicit runSearch("") below is the one initial batch. Reopening
104
- // after a full close MUST search too — HkModal unmounts its content
105
- // when closed, so no watcher would ever fire (the R3 finding).
106
- const sessionSeq = ref(0);
107
- watch(open, (now) => {
108
- if (!now) return;
109
- sessionSeq.value += 1;
169
+ watch(query, (raw) => {
170
+ stopPendingSearch();
171
+ const q = raw.trim();
172
+ if (!q) {
173
+ // Hard contract: an empty (or whitespace-only) query searches
174
+ // NOTHING and lists NOTHING — the hint stands alone.
175
+ clearCandidates();
176
+ return;
177
+ }
178
+ debounceTimer = setTimeout(() => {
179
+ debounceTimer = null;
180
+ void runSearch(q);
181
+ }, SEARCH_DEBOUNCE_MS);
182
+ });
183
+
184
+ /** Fresh session per open: the panel content UNMOUNTS when the surface
185
+ * fully closes, so this is also where a previous session's answer,
186
+ * cursor and draft are dropped. */
187
+ function resetSession(): void {
188
+ stopPendingSearch();
189
+ searchToken += 1;
110
190
  query.value = "";
111
191
  results.value = [];
192
+ loading.value = false;
193
+ failed.value = false;
194
+ activeIndex.value = -1;
112
195
  draft.value = [...props.modelValue];
113
- void runSearch("");
196
+ }
197
+
198
+ /** Open focuses the search field (search-first surface): the panel
199
+ * content mounts on the surface's opening edge, so wait for that
200
+ * render before reaching into it. */
201
+ async function focusSearch(): Promise<void> {
202
+ await nextTick();
203
+ if (!open.value) return;
204
+ panelExpose.value
205
+ ?.panelEl()
206
+ ?.querySelector<HTMLInputElement>(".hk-user-picker-search input")
207
+ ?.focus();
208
+ }
209
+
210
+ watch(open, (now) => {
211
+ if (!now) {
212
+ stopPendingSearch();
213
+ loading.value = false;
214
+ return;
215
+ }
216
+ resetSession();
217
+ void focusSearch();
114
218
  });
115
219
 
116
- const onSearch = (q: string) => {
117
- void runSearch(q);
118
- };
220
+ onBeforeUnmount(stopPendingSearch);
119
221
 
120
222
  const inDraft = (uid: string) => draft.value.some((u) => u.uid === uid);
121
223
 
122
- const pickRow = (user: HkUserOption) => {
224
+ function togglePanel(): void {
225
+ if (props.disabled) return;
226
+ open.value = !open.value;
227
+ }
228
+
229
+ function pickRow(user: HkUserOption): void {
123
230
  if (props.mode === "single") {
124
231
  open.value = false;
125
232
  emit("update:modelValue", [user]);
@@ -128,12 +235,23 @@ export default defineComponent({
128
235
  draft.value = inDraft(user.uid)
129
236
  ? draft.value.filter((u) => u.uid !== user.uid)
130
237
  : [...draft.value, user];
131
- };
238
+ }
132
239
 
133
- const confirmDraft = () => {
240
+ function confirmDraft(): void {
134
241
  open.value = false;
135
242
  emit("update:modelValue", draft.value);
136
- };
243
+ }
244
+
245
+ function cancelDraft(): void {
246
+ open.value = false;
247
+ }
248
+
249
+ function retrySearch(): void {
250
+ const q = query.value.trim();
251
+ if (!q) return;
252
+ stopPendingSearch();
253
+ void runSearch(q);
254
+ }
137
255
 
138
256
  const removeTag = (uid: string) => {
139
257
  if (props.disabled) return;
@@ -143,135 +261,286 @@ export default defineComponent({
143
261
  );
144
262
  };
145
263
 
146
- const dialogTitle = computed(
147
- () => props.label ?? t("hikari::userPicker.title", "Select users"),
264
+ /** Arrow walk over the current rows, wrapping at both ends (the
265
+ * HkTagInput / HkSelect cursor). */
266
+ function moveActive(delta: 1 | -1): void {
267
+ const count = results.value.length;
268
+ if (count === 0) {
269
+ activeIndex.value = -1;
270
+ return;
271
+ }
272
+ const from = activeIndex.value;
273
+ if (from < 0 || from >= count) activeIndex.value = delta > 0 ? 0 : count - 1;
274
+ else activeIndex.value = (from + delta + count) % count;
275
+ }
276
+
277
+ /** Keep the cursor row inside the surface's ONE scroll region (the
278
+ * desktop popout or the sheet's list band), never a region of ours. */
279
+ function scrollActiveIntoView(): void {
280
+ if (activeIndex.value < 0) return;
281
+ const root = panelExpose.value?.panelEl();
282
+ root
283
+ ?.querySelector<HTMLElement>(`[data-user-index="${activeIndex.value}"]`)
284
+ ?.scrollIntoView?.({ block: "nearest" });
285
+ }
286
+
287
+ watch(activeIndex, () => {
288
+ scrollActiveIntoView();
289
+ });
290
+
291
+ /** Keys that bubbled from the panel surface — the search field lives
292
+ * inside it, so arrows pressed there arrive here (the HkSelectPanel
293
+ * `keydown` contract). Escape is the surface's own and never reaches
294
+ * this handler. */
295
+ function onPanelKeydown(e: KeyboardEvent): void {
296
+ if (e.isComposing) return;
297
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
298
+ e.preventDefault();
299
+ moveActive(e.key === "ArrowDown" ? 1 : -1);
300
+ return;
301
+ }
302
+ if (e.key === "Enter") {
303
+ // Enter takes the cursor row; with no cursor it takes the top
304
+ // match — the HkAffixPicker / HkTagInput "blind Enter" order, kept
305
+ // so a typed query can be committed without reaching for arrows.
306
+ const row = results.value[activeIndex.value] ?? results.value[0];
307
+ if (!row) return;
308
+ e.preventDefault();
309
+ pickRow(row);
310
+ }
311
+ }
312
+
313
+ /** The field's own keys (focus lives here while the panel is closed). */
314
+ function onFieldKeydown(e: KeyboardEvent): void {
315
+ if (props.disabled) return;
316
+ if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") {
317
+ e.preventDefault();
318
+ open.value = true;
319
+ return;
320
+ }
321
+ if (e.key === "Escape" && open.value) {
322
+ // The surface's Escape handler lives ON the surface; a key pressed
323
+ // on the field would never reach it (the HkSelect trigger rule).
324
+ e.preventDefault();
325
+ e.stopPropagation();
326
+ open.value = false;
327
+ }
328
+ }
329
+
330
+ const panelTitle = computed(() => props.label ?? t("hikari::userPicker.title", "Select users"));
331
+
332
+ const searchPlaceholder = computed(() =>
333
+ t("hikari::userPicker.searchPlaceholder", "Nickname, username or email"),
148
334
  );
149
335
 
150
- const dialogActions = computed<ModalAction[] | undefined>(() =>
151
- props.mode === "multi"
152
- ? [
153
- {
154
- label: t("hikari::messageBox.cancel", "Cancel"),
155
- variant: "secondary",
156
- onClick: () => { open.value = false; },
157
- },
158
- {
159
- label: t("hikari::userPicker.confirm", "Confirm"),
160
- variant: "primary",
161
- disabled: draft.value.length === 0,
162
- onClick: confirmDraft,
163
- },
164
- ]
165
- : undefined,
336
+ const emptyHint = computed(
337
+ () => props.emptyHint ?? t("hikari::userPicker.emptyInitial", "Type a nickname, username or email to search."),
166
338
  );
167
339
 
168
- return () => (
169
- <div class={{ "hk-user-picker": true, "is-disabled": props.disabled }}>
170
- {props.label && <div class="hk-user-picker-label">{props.label}</div>}
171
- <div
172
- class="hk-user-picker-field"
173
- role="button"
174
- tabindex={props.disabled ? -1 : 0}
175
- aria-disabled={props.disabled}
176
- aria-label={props.label ?? t("hikari::userPicker.title", "Select users")}
177
- onClick={openDialog}
178
- onKeydown={(e: KeyboardEvent) => {
179
- if (props.disabled) return;
180
- if (e.key === "Enter" || e.key === " ") {
181
- e.preventDefault();
182
- openDialog();
183
- }
184
- }}
185
- >
186
- {props.modelValue.map((user) => (
187
- <span key={user.uid} class="hk-user-picker-tag" title={`${tagTitle(user)} ${user.email ?? ""}`.trim()}>
188
- <span class="hk-user-picker-tag-body">
189
- <span class="hk-user-picker-tag-name">{tagTitle(user)}</span>
190
- {user.email && <span class="hk-user-picker-tag-email">{user.email}</span>}
340
+ /** The rows band's state ladder (loading → failed → empty → ready) —
341
+ * published as `data-state` so hosts/tests can key on the state
342
+ * without reading the note text. */
343
+ const rowsState = computed(() =>
344
+ loading.value
345
+ ? "loading"
346
+ : failed.value
347
+ ? "failed"
348
+ : results.value.length === 0
349
+ ? "empty"
350
+ : "ready",
351
+ );
352
+
353
+ return () => {
354
+ const activeId =
355
+ activeIndex.value >= 0 && results.value[activeIndex.value]
356
+ ? optionId(results.value[activeIndex.value]!)
357
+ : undefined;
358
+ const hasQuery = query.value.trim().length > 0;
359
+ const multi = props.mode === "multi";
360
+ return (
361
+ <div class={{ "hk-user-picker": true, "is-disabled": props.disabled }}>
362
+ {props.label && <div class="hk-user-picker-label">{props.label}</div>}
363
+ <div
364
+ ref={fieldRef}
365
+ class={{ "hk-user-picker-field": true, "is-open": open.value }}
366
+ role="button"
367
+ tabindex={props.disabled ? -1 : 0}
368
+ aria-disabled={props.disabled}
369
+ aria-haspopup="listbox"
370
+ aria-expanded={open.value}
371
+ aria-label={panelTitle.value}
372
+ onClick={togglePanel}
373
+ onKeydown={onFieldKeydown}
374
+ >
375
+ {props.modelValue.map((user) => (
376
+ <span key={user.uid} class="hk-user-picker-tag" title={`${tagTitle(user)} ${user.email ?? ""}`.trim()}>
377
+ <span class="hk-user-picker-tag-body">
378
+ <span class="hk-user-picker-tag-name">{tagTitle(user)}</span>
379
+ {user.email && <span class="hk-user-picker-tag-email">{user.email}</span>}
380
+ </span>
381
+ {!props.disabled && (
382
+ <HkIconButton
383
+ class="hk-user-picker-tag-x"
384
+ size={16}
385
+ variant="ghost"
386
+ aria-label={`${t("hikari::userPicker.remove", "Remove")} ${tagTitle(user)}`}
387
+ onClick={(e: MouseEvent) => {
388
+ e.stopPropagation();
389
+ removeTag(user.uid);
390
+ }}
391
+ >
392
+ {{ icon: () => <X aria-hidden="true" /> }}
393
+ </HkIconButton>
394
+ )}
191
395
  </span>
192
- {!props.disabled && (
193
- <HkIconButton
194
- class="hk-user-picker-tag-x"
195
- size={16}
196
- variant="ghost"
197
- aria-label={`${t("hikari::userPicker.remove", "Remove")} ${tagTitle(user)}`}
198
- onClick={(e: MouseEvent) => {
199
- e.stopPropagation();
200
- removeTag(user.uid);
201
- }}
202
- >
203
- {{ icon: () => <X aria-hidden="true" /> }}
204
- </HkIconButton>
205
- )}
396
+ ))}
397
+ <span class={{ "hk-user-picker-add": true, "is-placeholder": props.modelValue.length === 0 }}>
398
+ {props.modelValue.length === 0
399
+ ? (props.placeholder ?? t("hikari::userPicker.add", "Select users…"))
400
+ : t("hikari::userPicker.add", "Select users…")}
206
401
  </span>
207
- ))}
208
- <span class={{ "hk-user-picker-add": true, "is-placeholder": props.modelValue.length === 0 }}>
209
- {props.modelValue.length === 0
210
- ? (props.placeholder ?? t("hikari::userPicker.add", "Select users…"))
211
- : t("hikari::userPicker.add", "Select users…")}
212
- </span>
213
- </div>
402
+ </div>
214
403
 
215
- <HkModal
216
- modelValue={open.value}
217
- onUpdate:modelValue={(v: boolean) => { open.value = v; }}
218
- title={dialogTitle.value}
219
- width="30rem"
220
- footerActions={dialogActions.value}
221
- >
222
- <div class="hk-user-picker-dialog">
223
- <HkSearchInput
224
- key={sessionSeq.value}
225
- modelValue={query.value}
226
- onUpdate:modelValue={(v: string) => { query.value = v; }}
227
- onSearch={onSearch}
228
- debounce={250}
229
- placeholder={t("hikari::userPicker.searchPlaceholder", "Nickname, username or email")}
230
- />
231
- <div class="hk-user-picker-rows" data-state={loading.value ? "loading" : failed.value ? "failed" : results.value.length === 0 ? "empty" : "ready"}>
232
- {loading.value && (
233
- <p class="hk-user-picker-note">{t("hikari::userPicker.searching", "Searching…")}</p>
234
- )}
235
- {!loading.value && failed.value && (
236
- <p class="hk-user-picker-note">{t("hikari::userPicker.searchFailed", "The search failed; try again.")}</p>
237
- )}
238
- {!loading.value && !failed.value && results.value.length === 0 && (
239
- <p class="hk-user-picker-note">
240
- {query.value.trim()
241
- ? t("hikari::userPicker.empty", "No users match this search.")
242
- : t("hikari::userPicker.emptyInitial", "Type a nickname, username or email to search.")}
243
- </p>
244
- )}
245
- {!loading.value && results.value.map((user) => (
246
- <button
247
- key={user.uid}
248
- type="button"
249
- class={{ "hk-user-picker-row": true, "is-selected": props.mode === "multi" && inDraft(user.uid) }}
250
- // Grammar face attribute (_menu-item.scss): mi.item's
251
- // checked face and its hover guard key on data-checked —
252
- // emitted beside the legacy .is-selected class so the
253
- // picked row's face survives hover.
254
- data-checked={props.mode === "multi" && inDraft(user.uid) || undefined}
255
- onClick={() => pickRow(user)}
256
- >
257
- <span class="hk-user-picker-row-main">
258
- <span class="hk-user-picker-row-name">{tagTitle(user)}</span>
259
- {user.email && <span class="hk-user-picker-row-email">{user.email}</span>}
260
- </span>
261
- {props.mode === "multi" && inDraft(user.uid) && (
262
- <span class="hk-user-picker-row-check" aria-hidden>✓</span>
404
+ {/*
405
+ The ONE anchored surface (desktop popout / phone bottom sheet).
406
+ `matchAnchorWidth` is the surface's own default and stays on: the
407
+ panel reads as this field's drop-down, not as a floating window.
408
+ `maxHeight` bounds the surface that scrolls — the popout itself,
409
+ or the sheet's list band — so the panel keeps exactly ONE
410
+ scrollbar (the HkAffixPicker / HkTagInput rule). The measure is
411
+ the family's catalog cap with a little more room, because this
412
+ panel carries a search line AND (multi) a draft footer around the
413
+ rows.
414
+ */}
415
+ <HkSelectPanel
416
+ ref={panelExpose}
417
+ open={open.value}
418
+ onUpdate:open={(v: boolean) => { open.value = v; }}
419
+ anchorRef={fieldRef.value ?? null}
420
+ title={panelTitle.value}
421
+ placement="bottom-start"
422
+ maxHeight="min(22rem, 50dvh)"
423
+ onKeydown={onPanelKeydown}
424
+ >
425
+ <div class="hk-user-picker-panel">
426
+ <div class="hk-user-picker-search" role="search">
427
+ <HkSearchInput
428
+ role="combobox"
429
+ aria-expanded={true}
430
+ aria-controls={listboxId}
431
+ aria-autocomplete="list"
432
+ aria-activedescendant={activeId}
433
+ // The field's accessible name: the placeholder reads as
434
+ // the instruction ("Nickname, username or email") — the
435
+ // HkAffixPicker / HkTagInput precedent, so no new i18n
436
+ // key is invented for it.
437
+ aria-label={searchPlaceholder.value}
438
+ modelValue={query.value}
439
+ disabled={props.disabled}
440
+ placeholder={searchPlaceholder.value}
441
+ clearAriaLabel={t("hikari::search.clear", "Clear search")}
442
+ onUpdate:modelValue={(v: string) => { query.value = v; }}
443
+ />
444
+ </div>
445
+ <div
446
+ id={listboxId}
447
+ class="hk-user-picker-rows"
448
+ role="listbox"
449
+ aria-multiselectable={multi ? "true" : undefined}
450
+ aria-label={panelTitle.value}
451
+ data-state={rowsState.value}
452
+ >
453
+ {/* The standing state line (searching / failed / empty) is
454
+ * the listbox's own content while it holds no rows — the
455
+ * HkTagInput empty-state precedent: the element the input's
456
+ * `aria-controls` names always exists, and its state is
457
+ * read where the rows would be. Rows that ARE present stay
458
+ * mounted under a "Searching…" line (stale-while-revalidate)
459
+ * so a new query never flashes the list empty. */}
460
+ {loading.value && (
461
+ <p class="hk-user-picker-note">{t("hikari::userPicker.searching", "Searching…")}</p>
462
+ )}
463
+ {!loading.value && failed.value && (
464
+ // The retry affordance IS the note — clicking it re-runs
465
+ // the same query (the historic failed/retry semantics,
466
+ // never a toast).
467
+ <button
468
+ type="button"
469
+ class="hk-user-picker-retry"
470
+ onClick={retrySearch}
471
+ >
472
+ {t("hikari::userPicker.searchFailed", "The search failed; try again.")}
473
+ </button>
474
+ )}
475
+ {!loading.value && !failed.value && results.value.length === 0 && (
476
+ <p class="hk-user-picker-note">
477
+ {hasQuery
478
+ ? t("hikari::userPicker.empty", "No users match this search.")
479
+ : emptyHint.value}
480
+ </p>
481
+ )}
482
+ {results.value.map((user, index) => {
483
+ const selected = multi && inDraft(user.uid);
484
+ return (
485
+ <div
486
+ key={user.uid}
487
+ id={optionId(user)}
488
+ role="option"
489
+ tabindex={-1}
490
+ class={{ "hk-user-picker-row": true, "is-selected": selected }}
491
+ aria-selected={selected}
492
+ data-user-index={index}
493
+ data-active={activeIndex.value === index || undefined}
494
+ // Grammar face attribute (_menu-item.scss): mi.item's
495
+ // checked face and its hover guard key on data-checked —
496
+ // emitted beside the legacy .is-selected class so the
497
+ // picked row's face survives hover.
498
+ data-checked={props.mode === "multi" && inDraft(user.uid) || undefined}
499
+ onClick={() => pickRow(user)}
500
+ >
501
+ <span class="hk-user-picker-row-main">
502
+ <span class="hk-user-picker-row-name">{tagTitle(user)}</span>
503
+ {user.email && <span class="hk-user-picker-row-email">{user.email}</span>}
504
+ </span>
505
+ {multi && selected && (
506
+ <span class="hk-user-picker-row-check" aria-hidden>✓</span>
507
+ )}
508
+ </div>
509
+ );
510
+ })}
511
+ </div>
512
+ {multi && (
513
+ <div class="hk-user-picker-footer">
514
+ {draft.value.length > 0 && (
515
+ <p class="hk-user-picker-count">
516
+ {t("hikari::userPicker.selectedCount", "{count} selected").replace("{count}", String(draft.value.length))}
517
+ </p>
263
518
  )}
264
- </button>
265
- ))}
519
+ <div class="hk-user-picker-actions">
520
+ <HkButton
521
+ variant="secondary"
522
+ size="sm"
523
+ class="hk-user-picker-cancel"
524
+ onClick={cancelDraft}
525
+ >
526
+ {t("hikari::messageBox.cancel", "Cancel")}
527
+ </HkButton>
528
+ <HkButton
529
+ variant="primary"
530
+ size="sm"
531
+ class="hk-user-picker-confirm"
532
+ disabled={draft.value.length === 0}
533
+ onClick={confirmDraft}
534
+ >
535
+ {t("hikari::userPicker.confirm", "Confirm")}
536
+ </HkButton>
537
+ </div>
538
+ </div>
539
+ )}
266
540
  </div>
267
- {props.mode === "multi" && draft.value.length > 0 && (
268
- <p class="hk-user-picker-count">
269
- {t("hikari::userPicker.selectedCount", "{count} selected").replace("{count}", String(draft.value.length))}
270
- </p>
271
- )}
272
- </div>
273
- </HkModal>
274
- </div>
275
- );
541
+ </HkSelectPanel>
542
+ </div>
543
+ );
544
+ };
276
545
  },
277
- });
546
+ });