@t3q-ui/design-system 1.67.3 → 1.67.4

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.
@@ -3,32 +3,100 @@ import { jsxs, jsx } from "react/jsx-runtime";
3
3
  import * as React from "react";
4
4
  import { Check } from "lucide-react";
5
5
  import { cn } from "../../utils/cn.js";
6
+ import { Popover, PopoverAnchor, PopoverContent } from "../popover.js";
6
7
  import { getTableFilterItemClassName, getTableFilterTextSlotClassName, tableFilterScrollbarClassName, tableFilterContentClassName, tableFilterOperatorContentClassName, TableFilterOperatorGlyph, TableFilterLoadingItem } from "../tableFilterParts.js";
7
8
  import { useColumnFilter } from "./ColumnFilter.js";
8
9
  import { OPERATOR_LABELS } from "./types.js";
9
10
  const FOCUS_RING_MAIN_STYLE = {
10
11
  outlineColor: "var(--color-sys-focus-ring-main)"
11
12
  };
12
- const popoverContentStyles = cn(
13
- "fixed z-[var(--z-index-overlay)] rounded-medium bg-sys-background shadow-gray-small outline-none border border-sys-divider-subtler",
14
- "animate-[fade-in_150ms_ease-out,zoom-in_150ms_ease-out]"
15
- );
13
+ function FilterPopoverContent(props) {
14
+ const { popoverAnchor: anchor, closePopover } = useColumnFilter();
15
+ if (!anchor) return null;
16
+ return /* @__PURE__ */ jsxs(
17
+ Popover,
18
+ {
19
+ open: true,
20
+ onOpenChange: (open) => {
21
+ if (!open) closePopover();
22
+ },
23
+ children: [
24
+ /* @__PURE__ */ jsx(PopoverAnchor, { virtualRef: { current: anchor } }),
25
+ /* @__PURE__ */ jsx(
26
+ PopoverContent,
27
+ {
28
+ align: "start",
29
+ sideOffset: 8,
30
+ role: void 0,
31
+ onOpenAutoFocus: (e) => e.preventDefault(),
32
+ onPointerDownOutside: (e) => {
33
+ if (anchor.contains(e.target)) e.preventDefault();
34
+ },
35
+ onFocusOutside: (e) => e.preventDefault(),
36
+ onEscapeKeyDown: () => anchor.focus(),
37
+ onKeyDown: (e) => {
38
+ if (e.key !== "Tab") return;
39
+ if (e.shiftKey) e.preventDefault();
40
+ closePopover();
41
+ anchor.focus();
42
+ },
43
+ ...props
44
+ }
45
+ )
46
+ ]
47
+ }
48
+ );
49
+ }
50
+ function useFocusInput() {
51
+ const { ids, setAutocompleteFocusMode } = useColumnFilter();
52
+ return React.useCallback(() => {
53
+ setAutocompleteFocusMode("input");
54
+ requestAnimationFrame(() => document.getElementById(ids.inputId)?.focus());
55
+ }, [ids.inputId, setAutocompleteFocusMode]);
56
+ }
57
+ const LIST_MOVES = /* @__PURE__ */ new Map([
58
+ ["ArrowDown", (index) => index + 1],
59
+ ["ArrowRight", (index) => index + 1],
60
+ ["ArrowUp", (index) => index - 1],
61
+ ["ArrowLeft", (index) => index - 1],
62
+ ["Home", () => 0],
63
+ ["End", (_, count) => count - 1]
64
+ ]);
65
+ function handleListItemKeyDown(e, {
66
+ index,
67
+ count,
68
+ choose,
69
+ moveTo,
70
+ backToInput
71
+ }) {
72
+ const move = LIST_MOVES.get(e.key);
73
+ const typed = e.key === "Backspace" || e.key === "Delete" || e.key.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey;
74
+ if (e.key === "Enter" || e.key === " ") {
75
+ e.preventDefault();
76
+ choose();
77
+ } else if (move) {
78
+ e.preventDefault();
79
+ moveTo((move(index, count) + count) % count);
80
+ } else if (backToInput && typed) {
81
+ e.preventDefault();
82
+ backToInput();
83
+ }
84
+ }
16
85
  function ColumnSelectPopover() {
17
86
  const {
18
87
  columns,
19
88
  activePopover,
20
89
  popoverTrigger,
21
- closePopover,
22
90
  selectColumn,
23
91
  editingFilter,
24
- popoverPosition,
25
92
  ids,
26
93
  columnSuggestionIndex,
27
94
  setColumnSuggestionIndex,
28
95
  autocompleteFocusMode,
29
96
  setAutocompleteFocusMode
30
97
  } = useColumnFilter();
31
- const popoverRef = React.useRef(null);
98
+ const focusInput = useFocusInput();
99
+ const listRef = React.useRef(null);
32
100
  const columnItemRefs = React.useRef([]);
33
101
  const [hoveredColumn, setHoveredColumn] = React.useState(null);
34
102
  const [focusedColumnIndex, setFocusedColumnIndex] = React.useState(0);
@@ -40,37 +108,24 @@ function ColumnSelectPopover() {
40
108
  editingFilter?.column ? columns.findIndex((column) => column.key === editingFilter.column) : 0
41
109
  );
42
110
  const activeColumnIndex = isInputDriven ? columnSuggestionIndex >= 0 ? columnSuggestionIndex : 0 : focusedColumnIndex;
43
- const focusInput = React.useCallback(() => {
44
- requestAnimationFrame(() => {
45
- document.getElementById(ids.inputId)?.focus();
46
- });
47
- }, [ids.inputId]);
48
- const focusNextAfterColumn = React.useCallback(() => {
49
- requestAnimationFrame(() => {
50
- const nextElement = document.querySelector("[data-column-filter-value-input]") ?? document.querySelector("[data-operator-button]") ?? document.getElementById(ids.inputId);
51
- nextElement?.focus();
52
- });
53
- }, [ids.inputId]);
54
111
  const focusColumnItem = React.useCallback(
55
112
  (index) => {
56
- if (columns.length === 0) return;
57
- const nextIndex = (index % columns.length + columns.length) % columns.length;
58
113
  if (isInputDriven) {
59
114
  setAutocompleteFocusMode("option");
60
- setColumnSuggestionIndex(nextIndex);
115
+ setColumnSuggestionIndex(index);
61
116
  }
62
- setFocusedColumnIndex(nextIndex);
63
- setHoveredColumn(columns[nextIndex]?.key ?? null);
117
+ setFocusedColumnIndex(index);
118
+ setHoveredColumn(columns[index]?.key ?? null);
64
119
  requestAnimationFrame(() => {
65
- columnItemRefs.current[nextIndex]?.focus();
120
+ columnItemRefs.current[index]?.focus();
66
121
  });
67
122
  },
68
123
  [columns, isInputDriven, setAutocompleteFocusMode, setColumnSuggestionIndex]
69
124
  );
70
- const returnFocusToInput = React.useCallback(() => {
71
- setAutocompleteFocusMode("input");
125
+ const chooseColumn = (key) => {
126
+ selectColumn(key);
72
127
  focusInput();
73
- }, [focusInput, setAutocompleteFocusMode]);
128
+ };
74
129
  React.useEffect(() => {
75
130
  if (activePopover !== "column" || columns.length === 0) return;
76
131
  if (isInputDriven) {
@@ -95,45 +150,20 @@ function ColumnSelectPopover() {
95
150
  React.useEffect(() => {
96
151
  if (activePopover !== "column") return;
97
152
  requestAnimationFrame(() => {
98
- popoverRef.current?.querySelector('[aria-selected="true"]')?.scrollIntoView({ block: "nearest" });
153
+ listRef.current?.querySelector('[aria-selected="true"]')?.scrollIntoView({ block: "nearest" });
99
154
  });
100
155
  }, [activePopover]);
101
- React.useEffect(() => {
102
- if (activePopover !== "column") return;
103
- const handleClickOutside = (e) => {
104
- const target = e.target;
105
- if (!target) return;
106
- if (isInputDriven && document.getElementById(ids.inputId)?.contains(target)) {
107
- return;
108
- }
109
- if (popoverRef.current && !popoverRef.current.contains(target)) {
110
- closePopover();
111
- }
112
- };
113
- const timer = setTimeout(() => {
114
- document.addEventListener("mousedown", handleClickOutside);
115
- }, 10);
116
- return () => {
117
- clearTimeout(timer);
118
- document.removeEventListener("mousedown", handleClickOutside);
119
- };
120
- }, [activePopover, closePopover, ids.inputId, isInputDriven]);
121
- if (activePopover !== "column" || !popoverPosition) return null;
156
+ if (activePopover !== "column") return null;
122
157
  return /* @__PURE__ */ jsx(
123
- "div",
158
+ FilterPopoverContent,
124
159
  {
125
- ref: popoverRef,
126
160
  "data-slot": "column-select-popover",
127
- className: cn(popoverContentStyles, "p-[8px]"),
128
- style: {
129
- top: popoverPosition.y + 8,
130
- left: popoverPosition.x
131
- },
132
161
  onMouseLeave: () => setHoveredColumn(null),
133
162
  children: /* @__PURE__ */ jsxs("div", { className: "flex gap-[4px]", children: [
134
163
  /* @__PURE__ */ jsx(
135
164
  "div",
136
165
  {
166
+ ref: listRef,
137
167
  id: ids.columnListId,
138
168
  role: isInputDriven ? "listbox" : "menu",
139
169
  className: cn(
@@ -160,10 +190,7 @@ function ColumnSelectPopover() {
160
190
  onMouseDown: (e) => {
161
191
  if (isInputDriven) e.preventDefault();
162
192
  },
163
- onClick: () => {
164
- selectColumn(column.key);
165
- focusNextAfterColumn();
166
- },
193
+ onClick: () => chooseColumn(column.key),
167
194
  onMouseEnter: () => {
168
195
  setHoveredColumn(column.key);
169
196
  if (isInputDriven) {
@@ -172,57 +199,13 @@ function ColumnSelectPopover() {
172
199
  setFocusedColumnIndex(index);
173
200
  }
174
201
  },
175
- onKeyDown: (e) => {
176
- if (e.key === "Enter" || e.key === " ") {
177
- e.preventDefault();
178
- selectColumn(column.key);
179
- focusNextAfterColumn();
180
- return;
181
- }
182
- if (e.key === "ArrowDown" || e.key === "ArrowRight") {
183
- e.preventDefault();
184
- focusColumnItem(index + 1);
185
- return;
186
- }
187
- if (e.key === "ArrowUp" || e.key === "ArrowLeft") {
188
- e.preventDefault();
189
- focusColumnItem(index - 1);
190
- return;
191
- }
192
- if (e.key === "Home") {
193
- e.preventDefault();
194
- focusColumnItem(0);
195
- return;
196
- }
197
- if (e.key === "End") {
198
- e.preventDefault();
199
- focusColumnItem(columns.length - 1);
200
- return;
201
- }
202
- if (e.key === "Escape") {
203
- e.preventDefault();
204
- closePopover();
205
- returnFocusToInput();
206
- return;
207
- }
208
- if (e.key === "Tab") {
209
- closePopover();
210
- if (e.shiftKey) {
211
- e.preventDefault();
212
- returnFocusToInput();
213
- }
214
- return;
215
- }
216
- if (isInputDriven && e.key.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey) {
217
- e.preventDefault();
218
- returnFocusToInput();
219
- return;
220
- }
221
- if (isInputDriven && (e.key === "Backspace" || e.key === "Delete" || e.key === "ArrowLeft" || e.key === "ArrowRight")) {
222
- e.preventDefault();
223
- returnFocusToInput();
224
- }
225
- },
202
+ onKeyDown: (e) => handleListItemKeyDown(e, {
203
+ index,
204
+ count: columns.length,
205
+ choose: () => chooseColumn(column.key),
206
+ moveTo: focusColumnItem,
207
+ backToInput: isInputDriven ? focusInput : void 0
208
+ }),
226
209
  children: [
227
210
  /* @__PURE__ */ jsx(Check, { size: 16, className: cn(isSelected ? "text-primary50" : "invisible") }),
228
211
  /* @__PURE__ */ jsx("span", { className: getTableFilterTextSlotClassName({ selected: isSelected }), children: column.label })
@@ -253,16 +236,8 @@ function ColumnSelectPopover() {
253
236
  }
254
237
  ColumnSelectPopover.displayName = "ColumnSelectPopover";
255
238
  function OperatorSelectPopover() {
256
- const {
257
- activePopover,
258
- closePopover,
259
- selectOperator,
260
- editingFilter,
261
- getOperatorsForColumn,
262
- popoverPosition,
263
- ids
264
- } = useColumnFilter();
265
- const popoverRef = React.useRef(null);
239
+ const { activePopover, selectOperator, editingFilter, getOperatorsForColumn, ids } = useColumnFilter();
240
+ const focusInput = useFocusInput();
266
241
  const operatorItemRefs = React.useRef([]);
267
242
  const [focusedOperatorIndex, setFocusedOperatorIndex] = React.useState(0);
268
243
  const operators = editingFilter?.column ? getOperatorsForColumn(editingFilter.column) : [];
@@ -270,28 +245,16 @@ function OperatorSelectPopover() {
270
245
  0,
271
246
  editingFilter?.operator ? operators.indexOf(editingFilter.operator) : 0
272
247
  );
273
- const focusOperatorButton = React.useCallback(() => {
274
- requestAnimationFrame(() => {
275
- document.querySelector("[data-operator-button]")?.focus();
276
- });
277
- }, []);
278
- const focusNextAfterOperator = React.useCallback(() => {
248
+ const focusOperatorItem = React.useCallback((index) => {
249
+ setFocusedOperatorIndex(index);
279
250
  requestAnimationFrame(() => {
280
- const nextElement = document.querySelector("[data-column-filter-value-input]") ?? document.querySelector("[data-editing-cancel-button]") ?? document.querySelector("[data-column-filter-reset-button]");
281
- nextElement?.focus();
251
+ operatorItemRefs.current[index]?.focus();
282
252
  });
283
253
  }, []);
284
- const focusOperatorItem = React.useCallback(
285
- (index) => {
286
- if (operators.length === 0) return;
287
- const nextIndex = (index + operators.length) % operators.length;
288
- setFocusedOperatorIndex(nextIndex);
289
- requestAnimationFrame(() => {
290
- operatorItemRefs.current[nextIndex]?.focus();
291
- });
292
- },
293
- [operators.length]
294
- );
254
+ const chooseOperator = (operator) => {
255
+ selectOperator(operator);
256
+ focusInput();
257
+ };
295
258
  React.useEffect(() => {
296
259
  if (activePopover !== "operator" || operators.length === 0) return;
297
260
  setFocusedOperatorIndex(selectedOperatorIndex);
@@ -299,34 +262,14 @@ function OperatorSelectPopover() {
299
262
  operatorItemRefs.current[selectedOperatorIndex]?.focus();
300
263
  });
301
264
  }, [activePopover, operators.length, selectedOperatorIndex]);
302
- React.useEffect(() => {
303
- if (activePopover !== "operator") return;
304
- const handleClickOutside = (e) => {
305
- if (popoverRef.current && !popoverRef.current.contains(e.target)) {
306
- closePopover();
307
- }
308
- };
309
- const timer = setTimeout(() => {
310
- document.addEventListener("mousedown", handleClickOutside);
311
- }, 10);
312
- return () => {
313
- clearTimeout(timer);
314
- document.removeEventListener("mousedown", handleClickOutside);
315
- };
316
- }, [activePopover, closePopover]);
317
- if (activePopover !== "operator" || !popoverPosition) return null;
265
+ if (activePopover !== "operator") return null;
318
266
  return /* @__PURE__ */ jsx(
319
- "div",
267
+ FilterPopoverContent,
320
268
  {
321
- ref: popoverRef,
322
269
  "data-slot": "operator-select-popover",
323
270
  role: "menu",
324
271
  id: ids.operatorListId,
325
- className: cn(popoverContentStyles, "w-[100px] p-[8px]"),
326
- style: {
327
- top: popoverPosition.y + 8,
328
- left: popoverPosition.x
329
- },
272
+ className: "w-[100px]",
330
273
  children: /* @__PURE__ */ jsx("div", { className: tableFilterOperatorContentClassName, children: operators.map((operator, index) => {
331
274
  const isSelected = editingFilter?.operator === operator;
332
275
  return /* @__PURE__ */ jsxs(
@@ -342,54 +285,13 @@ function OperatorSelectPopover() {
342
285
  "aria-label": OPERATOR_LABELS[operator],
343
286
  className: getTableFilterItemClassName({ kind: "operator", selected: isSelected }),
344
287
  style: FOCUS_RING_MAIN_STYLE,
345
- onClick: () => {
346
- selectOperator(operator);
347
- focusNextAfterOperator();
348
- },
349
- onKeyDown: (e) => {
350
- if (e.key === "Enter" || e.key === " ") {
351
- e.preventDefault();
352
- selectOperator(operator);
353
- focusNextAfterOperator();
354
- return;
355
- }
356
- if (e.key === "ArrowDown" || e.key === "ArrowRight") {
357
- e.preventDefault();
358
- focusOperatorItem(index + 1);
359
- return;
360
- }
361
- if (e.key === "ArrowUp" || e.key === "ArrowLeft") {
362
- e.preventDefault();
363
- focusOperatorItem(index - 1);
364
- return;
365
- }
366
- if (e.key === "Home") {
367
- e.preventDefault();
368
- focusOperatorItem(0);
369
- return;
370
- }
371
- if (e.key === "End") {
372
- e.preventDefault();
373
- focusOperatorItem(operators.length - 1);
374
- return;
375
- }
376
- if (e.key === "Escape") {
377
- e.preventDefault();
378
- closePopover();
379
- focusOperatorButton();
380
- return;
381
- }
382
- if (e.key === "Tab") {
383
- closePopover();
384
- if (e.shiftKey) {
385
- e.preventDefault();
386
- focusOperatorButton();
387
- } else {
388
- e.preventDefault();
389
- focusNextAfterOperator();
390
- }
391
- }
392
- },
288
+ onClick: () => chooseOperator(operator),
289
+ onKeyDown: (e) => handleListItemKeyDown(e, {
290
+ index,
291
+ count: operators.length,
292
+ choose: () => chooseOperator(operator),
293
+ moveTo: focusOperatorItem
294
+ }),
393
295
  children: [
394
296
  /* @__PURE__ */ jsx(
395
297
  Check,
@@ -411,8 +313,6 @@ OperatorSelectPopover.displayName = "OperatorSelectPopover";
411
313
  function SearchSuggestionPopover() {
412
314
  const {
413
315
  activePopover,
414
- popoverPosition,
415
- closePopover,
416
316
  ids,
417
317
  searchSuggestions,
418
318
  searchSuggestionIndex,
@@ -421,142 +321,54 @@ function SearchSuggestionPopover() {
421
321
  autocompleteFocusMode,
422
322
  setAutocompleteFocusMode
423
323
  } = useColumnFilter();
424
- const popoverRef = React.useRef(null);
324
+ const focusInput = useFocusInput();
425
325
  const suggestionItemRefs = React.useRef([]);
426
- const focusInput = React.useCallback(() => {
427
- requestAnimationFrame(() => {
428
- document.getElementById(ids.inputId)?.focus();
429
- });
430
- }, [ids.inputId]);
431
326
  const focusSearchItem = React.useCallback(
432
327
  (index) => {
433
- if (searchSuggestions.length === 0) return;
434
- const nextIndex = (index % searchSuggestions.length + searchSuggestions.length) % searchSuggestions.length;
435
328
  setAutocompleteFocusMode("option");
436
- setSearchSuggestionIndex(nextIndex);
329
+ setSearchSuggestionIndex(index);
437
330
  requestAnimationFrame(() => {
438
- suggestionItemRefs.current[nextIndex]?.focus();
331
+ suggestionItemRefs.current[index]?.focus();
439
332
  });
440
333
  },
441
- [searchSuggestions.length, setAutocompleteFocusMode, setSearchSuggestionIndex]
334
+ [setAutocompleteFocusMode, setSearchSuggestionIndex]
442
335
  );
443
- const returnFocusToInput = React.useCallback(() => {
444
- setAutocompleteFocusMode("input");
445
- focusInput();
446
- }, [focusInput, setAutocompleteFocusMode]);
447
- React.useEffect(() => {
448
- if (activePopover !== "search") return;
449
- const handleClickOutside = (e) => {
450
- const target = e.target;
451
- if (!target) return;
452
- if (document.getElementById(ids.inputId)?.contains(target)) {
453
- return;
454
- }
455
- if (popoverRef.current && !popoverRef.current.contains(target)) {
456
- closePopover();
457
- }
458
- };
459
- const timer = setTimeout(() => {
460
- document.addEventListener("mousedown", handleClickOutside);
461
- }, 10);
462
- return () => {
463
- clearTimeout(timer);
464
- document.removeEventListener("mousedown", handleClickOutside);
465
- };
466
- }, [activePopover, closePopover, ids.inputId]);
467
- if (activePopover !== "search" || searchSuggestions.length === 0 || !popoverPosition) return null;
468
- return /* @__PURE__ */ jsx(
336
+ if (activePopover !== "search" || searchSuggestions.length === 0) return null;
337
+ return /* @__PURE__ */ jsx(FilterPopoverContent, { "data-slot": "search-suggestion-popover", className: "w-[220px]", children: /* @__PURE__ */ jsx("div", { id: ids.searchListId, role: "listbox", className: tableFilterContentClassName, children: searchSuggestions.map((column, index) => /* @__PURE__ */ jsx(
469
338
  "div",
470
339
  {
471
- ref: popoverRef,
472
- "data-slot": "search-suggestion-popover",
473
- className: cn(popoverContentStyles, "w-[220px] p-[8px]"),
474
- style: {
475
- top: popoverPosition.y + 8,
476
- left: popoverPosition.x
340
+ ref: (node) => {
341
+ suggestionItemRefs.current[index] = node;
477
342
  },
478
- children: /* @__PURE__ */ jsx("div", { id: ids.searchListId, role: "listbox", className: tableFilterContentClassName, children: searchSuggestions.map((column, index) => /* @__PURE__ */ jsx(
479
- "div",
480
- {
481
- ref: (node) => {
482
- suggestionItemRefs.current[index] = node;
483
- },
484
- id: ids.getSearchOptionId(index),
485
- role: "option",
486
- "aria-selected": index === searchSuggestionIndex,
487
- tabIndex: autocompleteFocusMode === "option" && index === searchSuggestionIndex ? 0 : -1,
488
- className: getTableFilterItemClassName({
489
- selected: index === searchSuggestionIndex
490
- }),
491
- onClick: () => selectSearchSuggestion(column.key),
492
- onMouseDown: (e) => e.preventDefault(),
493
- onKeyDown: (e) => {
494
- if (e.key === "Enter" || e.key === " ") {
495
- e.preventDefault();
496
- selectSearchSuggestion(column.key);
497
- return;
498
- }
499
- if (e.key === "ArrowDown" || e.key === "ArrowRight") {
500
- e.preventDefault();
501
- focusSearchItem(index + 1);
502
- return;
503
- }
504
- if (e.key === "ArrowUp" || e.key === "ArrowLeft") {
505
- e.preventDefault();
506
- focusSearchItem(index - 1);
507
- return;
508
- }
509
- if (e.key === "Home") {
510
- e.preventDefault();
511
- focusSearchItem(0);
512
- return;
513
- }
514
- if (e.key === "End") {
515
- e.preventDefault();
516
- focusSearchItem(searchSuggestions.length - 1);
517
- return;
518
- }
519
- if (e.key === "Escape") {
520
- e.preventDefault();
521
- closePopover();
522
- returnFocusToInput();
523
- return;
524
- }
525
- if (e.key === "Tab") {
526
- closePopover();
527
- if (e.shiftKey) {
528
- e.preventDefault();
529
- returnFocusToInput();
530
- }
531
- return;
532
- }
533
- if (e.key.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey) {
534
- e.preventDefault();
535
- returnFocusToInput();
536
- return;
537
- }
538
- if (e.key === "Backspace" || e.key === "Delete") {
539
- e.preventDefault();
540
- returnFocusToInput();
541
- }
542
- },
543
- onMouseEnter: () => setSearchSuggestionIndex(index),
544
- children: /* @__PURE__ */ jsxs("span", { className: getTableFilterTextSlotClassName(), children: [
545
- /* @__PURE__ */ jsx("span", { className: "truncate", children: column.label }),
546
- /* @__PURE__ */ jsx("span", { className: "ml-[4px] shrink-0 text-small-regular text-sys-text-subtler", children: "컬럼으로 필터" })
547
- ] })
548
- },
549
- column.key
550
- )) })
551
- }
552
- );
343
+ id: ids.getSearchOptionId(index),
344
+ role: "option",
345
+ "aria-selected": index === searchSuggestionIndex,
346
+ tabIndex: autocompleteFocusMode === "option" && index === searchSuggestionIndex ? 0 : -1,
347
+ className: getTableFilterItemClassName({
348
+ selected: index === searchSuggestionIndex
349
+ }),
350
+ onClick: () => selectSearchSuggestion(column.key),
351
+ onMouseDown: (e) => e.preventDefault(),
352
+ onKeyDown: (e) => handleListItemKeyDown(e, {
353
+ index,
354
+ count: searchSuggestions.length,
355
+ choose: () => selectSearchSuggestion(column.key),
356
+ moveTo: focusSearchItem,
357
+ backToInput: focusInput
358
+ }),
359
+ onMouseEnter: () => setSearchSuggestionIndex(index),
360
+ children: /* @__PURE__ */ jsxs("span", { className: getTableFilterTextSlotClassName(), children: [
361
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: column.label }),
362
+ /* @__PURE__ */ jsx("span", { className: "ml-[4px] shrink-0 text-small-regular text-sys-text-subtler", children: "컬럼으로 필터" })
363
+ ] })
364
+ },
365
+ column.key
366
+ )) }) });
553
367
  }
554
368
  SearchSuggestionPopover.displayName = "SearchSuggestionPopover";
555
369
  function ValueSuggestionPopover() {
556
370
  const {
557
371
  activePopover,
558
- popoverPosition,
559
- closePopover,
560
372
  ids,
561
373
  valueSuggestions,
562
374
  valueSuggestionsLoading,
@@ -566,75 +378,26 @@ function ValueSuggestionPopover() {
566
378
  autocompleteFocusMode,
567
379
  setAutocompleteFocusMode
568
380
  } = useColumnFilter();
569
- const popoverRef = React.useRef(null);
381
+ const focusInput = useFocusInput();
570
382
  const suggestionItemRefs = React.useRef([]);
571
- const focusInput = React.useCallback(() => {
572
- requestAnimationFrame(() => {
573
- document.getElementById(ids.inputId)?.focus();
574
- });
575
- }, [ids.inputId]);
576
383
  const focusValueItem = React.useCallback(
577
384
  (index) => {
578
- if (valueSuggestions.length === 0) return;
579
- const nextIndex = (index % valueSuggestions.length + valueSuggestions.length) % valueSuggestions.length;
580
385
  setAutocompleteFocusMode("option");
581
- setValueSuggestionIndex(nextIndex);
386
+ setValueSuggestionIndex(index);
582
387
  requestAnimationFrame(() => {
583
- suggestionItemRefs.current[nextIndex]?.focus();
388
+ suggestionItemRefs.current[index]?.focus();
584
389
  });
585
390
  },
586
- [setAutocompleteFocusMode, setValueSuggestionIndex, valueSuggestions.length]
391
+ [setAutocompleteFocusMode, setValueSuggestionIndex]
587
392
  );
588
- const returnFocusToInput = React.useCallback(() => {
589
- setAutocompleteFocusMode("input");
590
- focusInput();
591
- }, [focusInput, setAutocompleteFocusMode]);
592
- React.useEffect(() => {
593
- if (activePopover !== "value") return;
594
- const handleClickOutside = (e) => {
595
- const target = e.target;
596
- if (!target) return;
597
- if (document.getElementById(ids.inputId)?.contains(target)) {
598
- return;
599
- }
600
- if (popoverRef.current && !popoverRef.current.contains(target)) {
601
- closePopover();
602
- }
603
- };
604
- const timer = setTimeout(() => {
605
- document.addEventListener("mousedown", handleClickOutside);
606
- }, 10);
607
- return () => {
608
- clearTimeout(timer);
609
- document.removeEventListener("mousedown", handleClickOutside);
610
- };
611
- }, [activePopover, closePopover, ids.inputId]);
612
- if (activePopover !== "value" || !popoverPosition) return null;
613
- if (valueSuggestionsLoading && valueSuggestions.length === 0) {
614
- return /* @__PURE__ */ jsx(
615
- "div",
616
- {
617
- ref: popoverRef,
618
- "data-slot": "value-suggestion-popover",
619
- className: cn(popoverContentStyles, "w-[220px] p-[8px]"),
620
- style: { top: popoverPosition.y + 8, left: popoverPosition.x },
621
- children: /* @__PURE__ */ jsx(TableFilterLoadingItem, {})
622
- }
623
- );
624
- }
625
- if (valueSuggestions.length === 0) return null;
393
+ const loading = valueSuggestionsLoading && valueSuggestions.length === 0;
394
+ if (activePopover !== "value" || !loading && valueSuggestions.length === 0) return null;
626
395
  return /* @__PURE__ */ jsx(
627
- "div",
396
+ FilterPopoverContent,
628
397
  {
629
- ref: popoverRef,
630
398
  "data-slot": "value-suggestion-popover",
631
- className: cn(
632
- popoverContentStyles,
633
- "w-[220px] max-h-[224px] overflow-y-auto p-[8px]",
634
- tableFilterScrollbarClassName
635
- ),
636
- style: { top: popoverPosition.y + 8, left: popoverPosition.x },
637
- children: /* @__PURE__ */ jsx("div", { id: ids.valueListId, role: "listbox", className: tableFilterContentClassName, children: valueSuggestions.map((suggestion, index) => /* @__PURE__ */ jsx(
399
+ className: cn("w-[220px] max-h-[224px] overflow-y-auto", tableFilterScrollbarClassName),
400
+ children: loading ? /* @__PURE__ */ jsx(TableFilterLoadingItem, {}) : /* @__PURE__ */ jsx("div", { id: ids.valueListId, role: "listbox", className: tableFilterContentClassName, children: valueSuggestions.map((suggestion, index) => /* @__PURE__ */ jsx(
638
401
  "div",
639
402
  {
640
403
  ref: (node) => {
@@ -649,56 +412,13 @@ function ValueSuggestionPopover() {
649
412
  }),
650
413
  onClick: () => selectValueSuggestion(suggestion.value),
651
414
  onMouseDown: (e) => e.preventDefault(),
652
- onKeyDown: (e) => {
653
- if (e.key === "Enter" || e.key === " ") {
654
- e.preventDefault();
655
- selectValueSuggestion(suggestion.value);
656
- return;
657
- }
658
- if (e.key === "ArrowDown" || e.key === "ArrowRight") {
659
- e.preventDefault();
660
- focusValueItem(index + 1);
661
- return;
662
- }
663
- if (e.key === "ArrowUp" || e.key === "ArrowLeft") {
664
- e.preventDefault();
665
- focusValueItem(index - 1);
666
- return;
667
- }
668
- if (e.key === "Home") {
669
- e.preventDefault();
670
- focusValueItem(0);
671
- return;
672
- }
673
- if (e.key === "End") {
674
- e.preventDefault();
675
- focusValueItem(valueSuggestions.length - 1);
676
- return;
677
- }
678
- if (e.key === "Escape") {
679
- e.preventDefault();
680
- closePopover();
681
- returnFocusToInput();
682
- return;
683
- }
684
- if (e.key === "Tab") {
685
- closePopover();
686
- if (e.shiftKey) {
687
- e.preventDefault();
688
- returnFocusToInput();
689
- }
690
- return;
691
- }
692
- if (e.key.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey) {
693
- e.preventDefault();
694
- returnFocusToInput();
695
- return;
696
- }
697
- if (e.key === "Backspace" || e.key === "Delete") {
698
- e.preventDefault();
699
- returnFocusToInput();
700
- }
701
- },
415
+ onKeyDown: (e) => handleListItemKeyDown(e, {
416
+ index,
417
+ count: valueSuggestions.length,
418
+ choose: () => selectValueSuggestion(suggestion.value),
419
+ moveTo: focusValueItem,
420
+ backToInput: focusInput
421
+ }),
702
422
  onMouseEnter: () => setValueSuggestionIndex(index),
703
423
  children: /* @__PURE__ */ jsx("span", { className: getTableFilterTextSlotClassName(), children: /* @__PURE__ */ jsx("span", { className: "truncate", children: suggestion.label }) })
704
424
  },