@telegraph/combobox 0.0.38 → 0.0.40

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,24 +1,26 @@
1
- import { jsx as c, jsxs as S, Fragment as V } from "react/jsx-runtime";
2
- import { useControllableState as G } from "@radix-ui/react-use-controllable-state";
3
- import * as M from "@radix-ui/react-visually-hidden";
4
- import { Button as k } from "@telegraph/button";
5
- import { useComposedRefs as F } from "@telegraph/compose-refs";
6
- import { RefToTgphRef as Y } from "@telegraph/helpers";
7
- import { Lucide as v, Icon as H } from "@telegraph/icon";
8
- import { Input as z } from "@telegraph/input";
9
- import { Stack as E, Box as B } from "@telegraph/layout";
1
+ import { jsx as i, jsxs as S, Fragment as F } from "react/jsx-runtime";
2
+ import { DismissableLayer as M } from "@radix-ui/react-dismissable-layer";
3
+ import { useControllableState as Y } from "@radix-ui/react-use-controllable-state";
4
+ import * as z from "@radix-ui/react-visually-hidden";
5
+ import { Button as E } from "@telegraph/button";
6
+ import { useComposedRefs as H } from "@telegraph/compose-refs";
7
+ import { RefToTgphRef as X } from "@telegraph/helpers";
8
+ import { Lucide as v, Icon as K } from "@telegraph/icon";
9
+ import { Input as q } from "@telegraph/input";
10
+ import { Stack as T, Box as B } from "@telegraph/layout";
10
11
  import { Menu as O } from "@telegraph/menu";
11
12
  import { Tag as D } from "@telegraph/tag";
12
- import { Tooltip as X } from "@telegraph/tooltip";
13
+ import { Tooltip as N } from "@telegraph/tooltip";
13
14
  import { Text as P } from "@telegraph/typography";
14
15
  import { motion as I, AnimatePresence as L } from "framer-motion";
15
- import i from "react";
16
- const q = {
16
+ import c from "react";
17
+ const U = {
17
18
  0: "5",
18
19
  1: "6",
19
20
  2: "8",
20
21
  3: "10"
21
- }, R = (t) => Array.isArray(t), T = (t) => typeof t == "object" && !Array.isArray(t) || !t, N = ["ArrowDown", "PageUp", "Home"], U = ["ArrowUp", "PageDown", "End"], K = ["Enter", " "], x = i.createContext({
22
+ }, R = (t) => Array.isArray(t), k = (t) => typeof t == "object" && !Array.isArray(t) || !t, J = ["ArrowDown", "PageUp", "Home"], W = ["ArrowUp", "PageDown", "End"], j = ["Enter", " "], x = c.createContext({
23
+ value: void 0,
22
24
  onValueChange: () => {
23
25
  },
24
26
  contentId: "",
@@ -28,65 +30,71 @@ const q = {
28
30
  },
29
31
  onOpenToggle: () => {
30
32
  },
31
- clearable: !1
32
- }), J = ({
33
+ clearable: !1,
34
+ disabled: !1
35
+ }), Z = ({
33
36
  modal: t = !0,
34
37
  closeOnSelect: l = !0,
35
38
  clearable: e = !1,
36
- open: u,
37
- onOpenChange: s,
38
- defaultOpen: r,
39
- value: n,
40
- onValueChange: o,
41
- errored: a,
42
- placeholder: b,
43
- layout: d,
44
- ...y
39
+ disabled: u = !1,
40
+ open: s,
41
+ onOpenChange: r,
42
+ defaultOpen: n,
43
+ value: o,
44
+ onValueChange: a,
45
+ errored: b,
46
+ placeholder: d,
47
+ layout: y,
48
+ ...p
45
49
  }) => {
46
- const p = i.useId(), g = i.useId(), h = i.useRef(null), m = i.useRef(null), f = i.useRef(null), [C, w] = i.useState(""), [Q = !1, A] = G({
47
- prop: u,
48
- defaultProp: r,
49
- onChange: s
50
- }), _ = i.useCallback(() => {
51
- A(($) => !$);
50
+ const g = c.useId(), f = c.useId(), m = c.useRef(null), h = c.useRef(null), C = c.useRef(null), [w, V] = c.useState(""), [Q = !1, A] = Y({
51
+ prop: s,
52
+ defaultProp: n,
53
+ onChange: r
54
+ }), $ = c.useCallback(() => {
55
+ A((G) => !G);
52
56
  }, [A]);
53
- return i.useEffect(() => {
54
- Q || w("");
55
- }, [Q]), /* @__PURE__ */ c(
57
+ return c.useEffect(() => {
58
+ Q || V("");
59
+ }, [Q]), /* @__PURE__ */ i(
56
60
  x.Provider,
57
61
  {
58
62
  value: {
59
- contentId: p,
60
- triggerId: g,
61
- value: n,
62
- onValueChange: o,
63
- placeholder: b,
63
+ contentId: g,
64
+ triggerId: f,
65
+ value: o,
66
+ // Need to cast this to avoid type errors
67
+ // because the type of onValueChange is not
68
+ // consistent with the value type
69
+ onValueChange: a,
70
+ placeholder: d,
64
71
  open: Q,
65
72
  setOpen: A,
66
- onOpenToggle: _,
73
+ onOpenToggle: $,
67
74
  closeOnSelect: l,
68
75
  clearable: e,
69
- searchQuery: C,
70
- setSearchQuery: w,
71
- triggerRef: h,
72
- searchRef: m,
73
- contentRef: f,
74
- errored: a,
75
- layout: d
76
+ disabled: u,
77
+ searchQuery: w,
78
+ setSearchQuery: V,
79
+ triggerRef: m,
80
+ searchRef: h,
81
+ contentRef: C,
82
+ errored: b,
83
+ layout: y
76
84
  },
77
- children: /* @__PURE__ */ c(
85
+ children: /* @__PURE__ */ i(
78
86
  O.Root,
79
87
  {
80
88
  open: Q,
81
89
  onOpenChange: A,
82
90
  modal: t,
83
- ...y
91
+ ...p
84
92
  }
85
93
  )
86
94
  }
87
95
  );
88
- }, W = ({ label: t, value: l, ...e }) => {
89
- const u = i.useContext(x);
96
+ }, ee = ({ label: t, value: l, ...e }) => {
97
+ const u = c.useContext(x);
90
98
  return /* @__PURE__ */ S(
91
99
  D.Root,
92
100
  {
@@ -108,8 +116,8 @@ const q = {
108
116
  },
109
117
  ...e,
110
118
  children: [
111
- /* @__PURE__ */ c(D.Text, { children: t || l }),
112
- /* @__PURE__ */ c(
119
+ /* @__PURE__ */ i(D.Text, { children: t || l }),
120
+ /* @__PURE__ */ i(
113
121
  D.Button,
114
122
  {
115
123
  icon: { icon: v.X, alt: `Remove ${l}` },
@@ -123,13 +131,13 @@ const q = {
123
131
  ]
124
132
  }
125
133
  );
126
- }, Z = () => {
134
+ }, te = () => {
127
135
  var l, e;
128
- const t = i.useContext(x);
136
+ const t = c.useContext(x);
129
137
  if (t.value && R(t.value)) {
130
138
  const u = t.layout || "truncate", s = t.value.length - 2, r = s.toString().split("");
131
- return t.value.length === 0 ? /* @__PURE__ */ c(k.Text, { color: "gray", children: t.placeholder }) : /* @__PURE__ */ S(
132
- E,
139
+ return t.value.length === 0 ? /* @__PURE__ */ i(E.Text, { color: "gray", children: t.placeholder }) : /* @__PURE__ */ S(
140
+ T,
133
141
  {
134
142
  gap: "1",
135
143
  w: "full",
@@ -140,12 +148,12 @@ const q = {
140
148
  flexGrow: 1
141
149
  },
142
150
  children: [
143
- /* @__PURE__ */ c(L, { initial: !1, mode: "popLayout", children: t.value.map((n, o) => {
151
+ /* @__PURE__ */ i(L, { initial: !1, mode: "popLayout", children: t.value.map((n, o) => {
144
152
  if (n != null && n.value && (u === "truncate" && o <= 1 || u === "wrap"))
145
- return /* @__PURE__ */ c(Y, { children: /* @__PURE__ */ c(W, { ...n }) }, n.value);
153
+ return /* @__PURE__ */ i(X, { children: /* @__PURE__ */ i(ee, { ...n }) }, n.value);
146
154
  }) }),
147
- /* @__PURE__ */ c(L, { children: u === "truncate" && t.value.length > 2 && /* @__PURE__ */ c(
148
- E,
155
+ /* @__PURE__ */ i(L, { children: u === "truncate" && t.value.length > 2 && /* @__PURE__ */ i(
156
+ T,
149
157
  {
150
158
  as: I.div,
151
159
  initial: { opacity: 0 },
@@ -164,7 +172,7 @@ const q = {
164
172
  },
165
173
  children: /* @__PURE__ */ S(P, { as: "span", size: "1", style: { whiteSpace: "nowrap" }, children: [
166
174
  "+",
167
- /* @__PURE__ */ c(L, { mode: "wait", initial: !1, children: r.map((n) => /* @__PURE__ */ c(
175
+ /* @__PURE__ */ i(L, { mode: "wait", initial: !1, children: r.map((n) => /* @__PURE__ */ i(
168
176
  B,
169
177
  {
170
178
  as: I.span,
@@ -194,16 +202,16 @@ const q = {
194
202
  }
195
203
  );
196
204
  }
197
- return /* @__PURE__ */ c(k.Text, { color: t.value ? "default" : "gray", children: ((l = t == null ? void 0 : t.value) == null ? void 0 : l.label) || ((e = t == null ? void 0 : t.value) == null ? void 0 : e.value) || t.placeholder });
198
- }, ee = ({ size: t = "2", ...l }) => {
199
- const e = i.useContext(x), u = i.useCallback(() => {
205
+ return /* @__PURE__ */ i(E.Text, { color: t.value ? "default" : "gray", children: ((l = t == null ? void 0 : t.value) == null ? void 0 : l.label) || ((e = t == null ? void 0 : t.value) == null ? void 0 : e.value) || t.placeholder });
206
+ }, oe = ({ size: t = "2", ...l }) => {
207
+ const e = c.useContext(x), u = c.useCallback(() => {
200
208
  var n, o, a;
201
- return e.value ? T(e.value) ? ((n = e.value) == null ? void 0 : n.label) || ((o = e.value) == null ? void 0 : o.value) || e.placeholder : ((a = e.value) == null ? void 0 : a.map((b) => b == null ? void 0 : b.label).join(", ")) || e.placeholder : e.placeholder;
202
- }, [e.value, e.placeholder]), s = i.useMemo(() => {
209
+ return e.value ? k(e.value) ? ((n = e.value) == null ? void 0 : n.label) || ((o = e.value) == null ? void 0 : o.value) || e.placeholder : ((a = e.value) == null ? void 0 : a.map((b) => b == null ? void 0 : b.label).join(", ")) || e.placeholder : e.placeholder;
210
+ }, [e.value, e.placeholder]), s = c.useMemo(() => {
203
211
  var n;
204
212
  if (R(e.value))
205
213
  return e.clearable && ((n = e.value) == null ? void 0 : n.length) > 0;
206
- if (T(e.value))
214
+ if (k(e.value))
207
215
  return e.clearable && e.value;
208
216
  }, [e.clearable, e.value]), r = () => {
209
217
  var n, o;
@@ -211,13 +219,13 @@ const q = {
211
219
  const a = e.onValueChange;
212
220
  a == null || a([]);
213
221
  }
214
- if (T(e.value)) {
222
+ if (k(e.value)) {
215
223
  const a = e.onValueChange;
216
224
  a == null || a(void 0);
217
225
  }
218
226
  (o = (n = e.triggerRef) == null ? void 0 : n.current) == null || o.focus();
219
227
  };
220
- return /* @__PURE__ */ c(
228
+ return /* @__PURE__ */ i(
221
229
  O.Trigger,
222
230
  {
223
231
  ...l,
@@ -231,7 +239,7 @@ const q = {
231
239
  n.stopPropagation();
232
240
  return;
233
241
  }
234
- if (K.includes(n.key)) {
242
+ if (j.includes(n.key)) {
235
243
  n.preventDefault();
236
244
  return;
237
245
  }
@@ -242,14 +250,14 @@ const q = {
242
250
  },
243
251
  tgphRef: e.triggerRef,
244
252
  children: /* @__PURE__ */ S(
245
- k.Root,
253
+ E.Root,
246
254
  {
247
255
  id: e.triggerId,
248
256
  type: "button",
249
257
  bg: "surface-1",
250
258
  variant: "outline",
251
259
  align: "center",
252
- minH: q[t],
260
+ minH: U[t],
253
261
  h: "full",
254
262
  w: "full",
255
263
  py: "1",
@@ -263,11 +271,12 @@ const q = {
263
271
  "aria-haspopup": "listbox",
264
272
  "data-tgph-combobox-trigger": !0,
265
273
  "data-tgph-comobox-trigger-open": e.open,
274
+ disabled: e.disabled,
266
275
  children: [
267
- /* @__PURE__ */ c(Z, {}),
268
- /* @__PURE__ */ S(E, { align: "center", gap: "1", children: [
269
- s && /* @__PURE__ */ c(X, { label: "Clear field", children: /* @__PURE__ */ c(
270
- k,
276
+ /* @__PURE__ */ i(te, {}),
277
+ /* @__PURE__ */ S(T, { align: "center", gap: "1", children: [
278
+ s && /* @__PURE__ */ i(N, { label: "Clear field", children: /* @__PURE__ */ i(
279
+ E,
271
280
  {
272
281
  type: "button",
273
282
  icon: { icon: v.X, alt: "Clear field" },
@@ -288,8 +297,8 @@ const q = {
288
297
  }
289
298
  }
290
299
  ) }),
291
- /* @__PURE__ */ c(
292
- k.Icon,
300
+ /* @__PURE__ */ i(
301
+ E.Icon,
293
302
  {
294
303
  as: I.div,
295
304
  icon: v.ChevronDown,
@@ -304,88 +313,98 @@ const q = {
304
313
  )
305
314
  }
306
315
  );
307
- }, te = ({
316
+ }, ne = ({
308
317
  tgphRef: t,
309
318
  style: l,
310
319
  children: e,
311
320
  ...u
312
321
  }) => {
313
- const s = i.useContext(x), r = i.useRef(!1), n = F(t, s.contentRef), o = i.useRef(null), [a, b] = i.useState(0), [d, y] = i.useState(!1), p = i.useCallback(
322
+ const s = c.useContext(x), r = c.useRef(!1), n = H(t, s.contentRef), o = c.useRef(null), [a, b] = c.useState(0), [d, y] = c.useState(!1), p = c.useCallback(
314
323
  (g) => {
315
- const h = g.getBoundingClientRect();
316
- h && b(h.height), d || y(!0);
324
+ const f = g.getBoundingClientRect();
325
+ f && b(f.height), d || y(!0);
317
326
  },
318
327
  [d]
319
328
  );
320
- return i.useEffect(() => {
321
- const g = new ResizeObserver((h) => {
322
- for (const m of h) {
323
- const f = m.target;
324
- p(f);
329
+ return c.useEffect(() => {
330
+ const g = new ResizeObserver((f) => {
331
+ for (const m of f) {
332
+ const h = m.target;
333
+ p(h);
325
334
  }
326
335
  });
327
336
  return o.current && d && g.observe(o.current), () => g.disconnect();
328
- }, [d, p]), i.useEffect(() => {
337
+ }, [d, p]), c.useEffect(() => {
329
338
  d === !0 && s.open === !1 && y(!1);
330
- }, [s.open, d]), /* @__PURE__ */ c(
331
- O.Content,
339
+ }, [s.open, d]), // We add radix's dismissable layer here so that we can swallow any escape key
340
+ // presses to prevent cases like a modal closing when we close the combobox
341
+ /* @__PURE__ */ i(
342
+ M,
332
343
  {
333
- as: I.div,
334
- mt: "1",
335
- initial: {
336
- opacity: 0,
337
- scale: 0.8,
338
- height: "auto"
339
- },
340
- animate: {
341
- opacity: 1,
342
- scale: 1,
343
- // Set height based on the internalContentRef so that
344
- // we get smooth animations when the content changes
345
- minHeight: a ? `${a}px` : "0"
344
+ onEscapeKeyDown: (g) => {
345
+ s.open && (g.preventDefault(), s.setOpen(!1));
346
346
  },
347
- exit: { opacity: 0, scale: 0 },
348
- transition: { duration: 0.2, type: "spring", bounce: 0 },
349
- onAnimationComplete: () => {
350
- if (!d && o) {
351
- const g = o.current;
352
- p(g);
347
+ children: /* @__PURE__ */ i(
348
+ O.Content,
349
+ {
350
+ as: I.div,
351
+ mt: "1",
352
+ initial: {
353
+ opacity: 0,
354
+ scale: 0.8,
355
+ height: "auto"
356
+ },
357
+ animate: {
358
+ opacity: 1,
359
+ scale: 1,
360
+ // Set height based on the internalContentRef so that
361
+ // we get smooth animations when the content changes
362
+ minHeight: a ? `${a}px` : "0"
363
+ },
364
+ exit: { opacity: 0, scale: 0 },
365
+ transition: { duration: 0.2, type: "spring", bounce: 0 },
366
+ onAnimationComplete: () => {
367
+ if (!d && o) {
368
+ const g = o.current;
369
+ p(g);
370
+ }
371
+ },
372
+ onCloseAutoFocus: (g) => {
373
+ var f, m;
374
+ r.current || (m = (f = s.triggerRef) == null ? void 0 : f.current) == null || m.focus(), r.current = !1, g.preventDefault();
375
+ },
376
+ onKeyDown: (g) => {
377
+ var m, h, C, w;
378
+ const f = (h = (m = s.contentRef) == null ? void 0 : m.current) == null ? void 0 : h.querySelectorAll(
379
+ "[data-tgph-combobox-option]"
380
+ );
381
+ document.activeElement === (f == null ? void 0 : f[0]) && W.includes(g.key) && ((w = (C = s.searchRef) == null ? void 0 : C.current) == null || w.focus());
382
+ },
383
+ bg: "surface-1",
384
+ style: {
385
+ width: "var(--tgph-comobobox-trigger-width)",
386
+ ...l,
387
+ "--tgph-comobobox-content-transform-origin": "var(--radix-popper-transform-origin)",
388
+ "--tgph-combobox-content-available-width": "var(--radix-popper-available-width)",
389
+ "--tgph-combobox-content-available-height": "calc(var(--radix-popper-available-height) - var(--tgph-spacing-8))",
390
+ "--tgph-comobobox-trigger-width": "var(--radix-popper-anchor-width)",
391
+ "--tgph-combobox-trigger-height": "var(--radix-popper-anchor-height)"
392
+ },
393
+ ...u,
394
+ tgphRef: n,
395
+ "data-tgph-combobox-content": !0,
396
+ "data-tgph-combobox-content-open": d,
397
+ role: void 0,
398
+ "aria-orientation": void 0,
399
+ children: /* @__PURE__ */ i(T, { direction: "column", gap: "1", tgphRef: o, children: e })
353
400
  }
354
- },
355
- onCloseAutoFocus: (g) => {
356
- var h, m;
357
- r.current || (m = (h = s.triggerRef) == null ? void 0 : h.current) == null || m.focus(), r.current = !1, g.preventDefault();
358
- },
359
- onKeyDown: (g) => {
360
- var m, f, C, w;
361
- const h = (f = (m = s.contentRef) == null ? void 0 : m.current) == null ? void 0 : f.querySelectorAll(
362
- "[data-tgph-combobox-option]"
363
- );
364
- document.activeElement === (h == null ? void 0 : h[0]) && U.includes(g.key) && ((w = (C = s.searchRef) == null ? void 0 : C.current) == null || w.focus()), g.key === "Escape" && s.setOpen(!1), g.stopPropagation();
365
- },
366
- bg: "surface-1",
367
- style: {
368
- width: "var(--tgph-comobobox-trigger-width)",
369
- ...l,
370
- "--tgph-comobobox-content-transform-origin": "var(--radix-popper-transform-origin)",
371
- "--tgph-combobox-content-available-width": "var(--radix-popper-available-width)",
372
- "--tgph-combobox-content-available-height": "calc(var(--radix-popper-available-height) - var(--tgph-spacing-8))",
373
- "--tgph-comobobox-trigger-width": "var(--radix-popper-anchor-width)",
374
- "--tgph-combobox-trigger-height": "var(--radix-popper-anchor-height)"
375
- },
376
- ...u,
377
- tgphRef: n,
378
- "data-tgph-combobox-content": !0,
379
- "data-tgph-combobox-content-open": d,
380
- role: void 0,
381
- "aria-orientation": void 0,
382
- children: /* @__PURE__ */ c(E, { direction: "column", gap: "1", tgphRef: o, children: e })
401
+ )
383
402
  }
384
403
  );
385
- }, oe = ({ ...t }) => {
386
- const l = i.useContext(x);
387
- return /* @__PURE__ */ c(
388
- E,
404
+ }, re = ({ ...t }) => {
405
+ const l = c.useContext(x);
406
+ return /* @__PURE__ */ i(
407
+ T,
389
408
  {
390
409
  id: l.contentId,
391
410
  direction: "column",
@@ -399,31 +418,31 @@ const q = {
399
418
  ...t
400
419
  }
401
420
  );
402
- }, j = ({
421
+ }, _ = ({
403
422
  value: t,
404
423
  label: l,
405
424
  selected: e,
406
425
  onSelect: u,
407
426
  ...s
408
427
  }) => {
409
- const r = i.useContext(x), [n, o] = i.useState(!1), a = r.value, b = (R(a), !r.searchQuery || t.toLowerCase().includes(r.searchQuery.toLowerCase())), d = R(a) ? a.some((p) => (p == null ? void 0 : p.value) === t) : (a == null ? void 0 : a.value) === t, y = (p) => {
410
- var h, m;
428
+ const r = c.useContext(x), [n, o] = c.useState(!1), a = r.value, b = (R(a), !r.searchQuery || t.toLowerCase().includes(r.searchQuery.toLowerCase())), d = R(a) ? a.some((p) => (p == null ? void 0 : p.value) === t) : (a == null ? void 0 : a.value) === t, y = (p) => {
429
+ var f, m;
411
430
  const g = p;
412
- if (!(g.key && !K.includes(g.key))) {
431
+ if (!(g.key && !j.includes(g.key))) {
413
432
  if (p.stopPropagation(), p.preventDefault(), r.closeOnSelect === !0 && r.setOpen(!1), u)
414
433
  return u(p);
415
- if (T(a)) {
416
- const f = r.onValueChange;
417
- f == null || f({ value: t, label: l });
434
+ if (k(a)) {
435
+ const h = r.onValueChange;
436
+ h == null || h({ value: t, label: l });
418
437
  } else if (R(a)) {
419
- const f = r.onValueChange, C = d ? a.filter((w) => (w == null ? void 0 : w.value) !== t) : [...a, { value: t, label: l }];
420
- f == null || f(C);
438
+ const h = r.onValueChange, C = d ? a.filter((w) => (w == null ? void 0 : w.value) !== t) : [...a, { value: t, label: l }];
439
+ h == null || h(C);
421
440
  }
422
- (m = (h = r.triggerRef) == null ? void 0 : h.current) == null || m.focus();
441
+ (m = (f = r.triggerRef) == null ? void 0 : f.current) == null || m.focus();
423
442
  }
424
443
  };
425
444
  if (b)
426
- return /* @__PURE__ */ c(
445
+ return /* @__PURE__ */ i(
427
446
  O.Button,
428
447
  {
429
448
  type: "button",
@@ -442,7 +461,7 @@ const q = {
442
461
  children: l || t
443
462
  }
444
463
  );
445
- }, ne = ({
464
+ }, ae = ({
446
465
  label: t = "Search",
447
466
  placeholder: l = "Search",
448
467
  tgphRef: e,
@@ -451,21 +470,21 @@ const q = {
451
470
  ...r
452
471
  }) => {
453
472
  var y;
454
- const n = i.useId(), o = i.useContext(x), a = F(e, o.searchRef), b = u ?? o.searchQuery, d = s ?? o.setSearchQuery;
455
- return i.useEffect(() => {
456
- var h;
473
+ const n = c.useId(), o = c.useContext(x), a = H(e, o.searchRef), b = u ?? o.searchQuery, d = s ?? o.setSearchQuery;
474
+ return c.useEffect(() => {
475
+ var f;
457
476
  const p = (m) => {
458
- var f, C;
459
- N.includes(m.key) && ((C = (f = o.contentRef) == null ? void 0 : f.current) == null || C.focus({ preventScroll: !0 })), m.key === "Escape" && o.setOpen(!1), m.stopPropagation();
460
- }, g = (h = o.searchRef) == null ? void 0 : h.current;
477
+ var h, C;
478
+ J.includes(m.key) && ((C = (h = o.contentRef) == null ? void 0 : h.current) == null || C.focus({ preventScroll: !0 })), m.key === "Escape" && o.setOpen(!1), m.stopPropagation();
479
+ }, g = (f = o.searchRef) == null ? void 0 : f.current;
461
480
  if (g)
462
481
  return g.addEventListener("keydown", p), () => {
463
482
  g.removeEventListener("keydown", p);
464
483
  };
465
484
  }, [o]), /* @__PURE__ */ S(B, { borderBottom: "px", px: "1", pb: "1", children: [
466
- /* @__PURE__ */ c(M.Root, { children: /* @__PURE__ */ c(P, { as: "label", htmlFor: n, children: t }) }),
467
- /* @__PURE__ */ c(
468
- z,
485
+ /* @__PURE__ */ i(z.Root, { children: /* @__PURE__ */ i(P, { as: "label", htmlFor: n, children: t }) }),
486
+ /* @__PURE__ */ i(
487
+ q,
469
488
  {
470
489
  id: n,
471
490
  variant: "ghost",
@@ -474,9 +493,9 @@ const q = {
474
493
  onChange: (p) => {
475
494
  d(p.target.value);
476
495
  },
477
- LeadingComponent: /* @__PURE__ */ c(H, { icon: v.Search, alt: "Search Icon" }),
478
- TrailingComponent: o != null && o.searchQuery && ((y = o == null ? void 0 : o.searchQuery) == null ? void 0 : y.length) > 0 ? /* @__PURE__ */ c(
479
- k,
496
+ LeadingComponent: /* @__PURE__ */ i(K, { icon: v.Search, alt: "Search Icon" }),
497
+ TrailingComponent: o != null && o.searchQuery && ((y = o == null ? void 0 : o.searchQuery) == null ? void 0 : y.length) > 0 ? /* @__PURE__ */ i(
498
+ E,
480
499
  {
481
500
  as: I.button,
482
501
  initial: { opacity: 0 },
@@ -499,14 +518,14 @@ const q = {
499
518
  }
500
519
  )
501
520
  ] });
502
- }, re = ({
521
+ }, ie = ({
503
522
  icon: t = { icon: v.Search, alt: "Search Icon" },
504
523
  message: l = "No results found",
505
524
  children: e,
506
525
  ...u
507
526
  }) => {
508
- const s = i.useContext(x), [r, n] = i.useState(!1);
509
- if (i.useEffect(() => {
527
+ const s = c.useContext(x), [r, n] = c.useState(!1);
528
+ if (c.useEffect(() => {
510
529
  var a, b;
511
530
  const o = (b = (a = s.contentRef) == null ? void 0 : a.current) == null ? void 0 : b.querySelectorAll(
512
531
  "[data-tgph-combobox-option]"
@@ -514,7 +533,7 @@ const q = {
514
533
  (o == null ? void 0 : o.length) === 0 ? n(!0) : n(!1);
515
534
  }, [s.searchQuery, s.contentRef, e]), r)
516
535
  return /* @__PURE__ */ S(
517
- E,
536
+ T,
518
537
  {
519
538
  as: I.div,
520
539
  initial: { opacity: 0, scale: 0.8 },
@@ -528,25 +547,25 @@ const q = {
528
547
  "data-tgph-combobox-empty": !0,
529
548
  ...u,
530
549
  children: [
531
- t === null ? /* @__PURE__ */ c(V, {}) : /* @__PURE__ */ c(H, { ...t }),
532
- l === null ? /* @__PURE__ */ c(V, {}) : /* @__PURE__ */ c(P, { as: "span", children: l })
550
+ t === null ? /* @__PURE__ */ i(F, {}) : /* @__PURE__ */ i(K, { ...t }),
551
+ l === null ? /* @__PURE__ */ i(F, {}) : /* @__PURE__ */ i(P, { as: "span", children: l })
533
552
  ]
534
553
  }
535
554
  );
536
- }, ae = ({
555
+ }, ce = ({
537
556
  leadingText: t = "Create",
538
557
  values: l,
539
558
  onCreate: e,
540
559
  selected: u = null,
541
560
  ...s
542
561
  }) => {
543
- const r = i.useContext(x), n = i.useCallback(
562
+ const r = c.useContext(x), n = c.useCallback(
544
563
  (o) => !l || (l == null ? void 0 : l.length) === 0 ? !1 : l.some((a) => (a == null ? void 0 : a.value) === o),
545
564
  [l]
546
565
  );
547
566
  if (r.searchQuery && !n(r.searchQuery))
548
- return /* @__PURE__ */ c(
549
- j,
567
+ return /* @__PURE__ */ i(
568
+ _,
550
569
  {
551
570
  leadingIcon: { icon: v.Plus, "aria-hidden": !0 },
552
571
  mx: "1",
@@ -555,23 +574,23 @@ const q = {
555
574
  selected: u,
556
575
  onSelect: () => {
557
576
  var o;
558
- e && r.value && r.searchQuery && (T(r.value) && e({ value: r.searchQuery }), R(r.value) && e({ value: r.searchQuery }), (o = r.setSearchQuery) == null || o.call(r, ""));
577
+ e && r.value && r.searchQuery && (k(r.value) && e({ value: r.searchQuery }), R(r.value) && e({ value: r.searchQuery }), (o = r.setSearchQuery) == null || o.call(r, ""));
559
578
  },
560
579
  ...s
561
580
  }
562
581
  );
563
- }, ie = {};
564
- Object.assign(ie, {
565
- Root: J,
566
- Trigger: ee,
567
- Content: te,
568
- Options: oe,
569
- Option: j,
570
- Search: ne,
571
- Empty: re,
572
- Create: ae
582
+ }, le = {};
583
+ Object.assign(le, {
584
+ Root: Z,
585
+ Trigger: oe,
586
+ Content: ne,
587
+ Options: re,
588
+ Option: _,
589
+ Search: ae,
590
+ Empty: ie,
591
+ Create: ce
573
592
  });
574
593
  export {
575
- ie as Combobox
594
+ le as Combobox
576
595
  };
577
596
  //# sourceMappingURL=index.mjs.map