@kakadu/components 4.3.0 → 4.3.2

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.
@@ -19,7 +19,10 @@ export type ComboboxProperties<Type = string> = Omit<InputLabelControllerPropert
19
19
  readonly isLoading?: boolean;
20
20
  readonly value?: Type;
21
21
  readonly options: Array<ComboboxOption<Type>>;
22
+ /** If `false`, `options` is assumed to be sorted and filtered based on the current search value (eg. by the server).
23
+ * @default true */
24
+ readonly shouldFilterOptions?: boolean;
22
25
  readonly onChange?: (value: string, event?: ChangeEvent<InputType>) => void;
23
26
  readonly onSelect?: (value?: Type) => void;
24
27
  };
25
- export default function Combobox<Type = string>({ isLoading, label, options, error, warning, information, footnote, className, onChange, onSelect, ...properties }: ComboboxProperties<Type>): import("react/jsx-runtime").JSX.Element;
28
+ export default function Combobox<Type = string>({ isLoading, shouldFilterOptions, label, options, error, warning, information, footnote, className, onChange, onSelect, ...properties }: ComboboxProperties<Type>): import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("../jsx-runtime-BB_1_6y_.js"),e=require("react"),K=require("@kuma-ui/core"),te=require("../hooks/use-synchronized-value.js"),se=require("../icons/icon.js"),ne=require("../icons/chevron-up.js"),oe=require("../utilities/search.js"),re=require("./input.js"),B=require("./text.js"),U=require("./flex.js"),ae=require("./skeleton.js");function X(){const{value:o,setValue:p}=te.default("isKeyboardNavigating");return e.useMemo(()=>({isKeyboardNavigating:o,setIsKeyboardNavigating:p}),[o,p])}function _(o){return"text"in o?o.text:o.label}const D="kakadu-components-1144794361",F="kakadu-components-2911184744";function ue({isSelected:o,id:p,value:i,label:k,onSelect:v,onHover:E}){const{isKeyboardNavigating:f}=X(),j=e.useCallback(()=>{v(i)},[v,i]),n=e.useCallback(b=>{f||b.movementX===0&&b.movementY===0||E(i)},[f,E,i]),x=e.useRef(null);return e.useEffect(()=>{const b=x.current;o&&b&&f&&setTimeout(()=>{b.scrollIntoView({behavior:"smooth",block:"nearest"})},0)},[o,f]),c.jsxRuntimeExports.jsx("li",{ref:x,id:p,role:"option","aria-selected":o,tabIndex:-1,className:K.cx(D,"kakadu-components-4130497639",f?"kakadu-components-962373561":"kakadu-components-1109598791"),onClick:j,onMouseMove:n,children:c.jsxRuntimeExports.jsx(B.Span,{className:K.cx(F,typeof k=="string"&&"kakadu-components-154286052"),children:k})})}function ce({isLoading:o,id:p,activeOptionId:i,selectedValue:k,options:v,onSelect:E,onHover:f}){const j=e.useRef(null);return e.useEffect(()=>{const n=j.current;n&&n.scrollIntoView({behavior:"smooth",block:"nearest"})},[]),c.jsxRuntimeExports.jsxs("ul",{ref:j,id:p,role:"listbox","aria-label":"Options",tabIndex:-1,className:"kakadu-components-1951042708",children:[v.length===0?o?null:c.jsxRuntimeExports.jsxs(U.default,{"aria-atomic":!0,as:"li",role:"status","aria-live":"polite",direction:"row",preset:"start",gap:.5,className:D,children:[c.jsxRuntimeExports.jsx(se.default,{size:15,type:"exclamationTriangle"}),c.jsxRuntimeExports.jsx(B.Span,{className:F,children:"No results."})]}):v.map((n,x)=>c.jsxRuntimeExports.jsx(ue,{...n,id:n.value===k?i:void 0,isSelected:n.value===k,onSelect:E,onHover:f},_(n)+x)),o?c.jsxRuntimeExports.jsx(U.default,{as:"li",alignment:"center",className:D,children:c.jsxRuntimeExports.jsx(B.Span,{className:F,children:c.jsxRuntimeExports.jsx(ae.SkeletonInstance,{width:"100%",height:"1.3em"})})}):null]})}function ie({isLoading:o,label:p,options:i,error:k,warning:v,information:E,footnote:f,className:j,onChange:n,onSelect:x,...b}){const O=e.useRef(null),T=e.useId(),H=e.useId(),[g,M]=e.useState(!1),Y=e.useCallback(()=>{M(!0)},[]),$=e.useCallback(t=>{var s;(s=O.current)!=null&&s.contains(t.relatedTarget)||M(!1)},[]),[I,a]=e.useState(!1);e.useEffect(()=>{a(g)},[g]);const[P,V]=e.useState(""),{value:R}=b,[d,y]=e.useState(R),[S,G]=e.useState(R),A=e.useRef(S),u=e.useCallback(t=>{G(t),A.current=t},[]);e.useEffect(()=>{y(R),u(R)},[R,u]);const J=e.useCallback(()=>{d&&(V(""),u(void 0))},[d,u]),Q=e.useCallback((t,s)=>{V(t),n==null||n(t,s),a(!0),y(void 0)},[n]),W=e.useCallback(t=>{var s;(s=O.current)!=null&&s.contains(t.target)&&a(!0)},[]),h=e.useCallback(t=>{const s=t==null?void 0:t.value;u(s),t?V(_(t)):(V(""),n==null||n("")),x==null||x(s)},[u,n,x]),Z=e.useCallback(t=>{const s=i.find(m=>m.value===t);h(s),y(t),a(!1)},[i,h]),ee=e.useCallback(t=>{u(t)},[u]),q=e.useDeferredValue(P),l=e.useMemo(()=>d?i:oe.default(q,i,_),[d,i,q]);e.useEffect(()=>{!d&&q.length>0&&l.length>0&&!l.some(t=>S===t.value)&&u(l[0].value)},[d,q,l,S,u]);const{setIsKeyboardNavigating:N}=X();return e.useEffect(()=>{if(!g)return;const t=s=>{s.movementX===0&&s.movementY===0||N(!1)};return window.addEventListener("mousemove",t,{capture:!0}),()=>{window.removeEventListener("mousemove",t,{capture:!0})}},[g,N]),e.useEffect(()=>{if(!g)return;const t=s=>{var z;let m;const C=l.length,L=l.findIndex(r=>r.value===A.current),w=()=>{s.preventDefault(),s.stopPropagation(),s.stopImmediatePropagation()};switch(s.key){case"Enter":{const r=l[L];r&&(w(),N(!0),a(!1),h(r),y(r.value));break}case"Escape":{if(I)w(),d?u(void 0):h(void 0),a(!1);else if(d)w(),a(!0),h(void 0);else{w(),M(!1);const r=document.activeElement;r instanceof HTMLElement&&((z=O.current)!=null&&z.contains(r))&&r.blur()}return}case"ArrowDown":{m=L+1,a(!0);break}case"ArrowUp":{m=L-1,a(!0),m<0&&(m=C-1);break}case"Home":{a(!0),m=0;break}case"End":{a(!0),m=C-1;break}case"Backspace":{l.some(r=>r.value===d)&&(w(),h(void 0),a(!0));break}}if(m!==void 0&&(w(),N(!0),C>0)){const r=l[m%C];r&&u(r.value)}};return window.addEventListener("keydown",t,{capture:!0}),()=>{window.removeEventListener("keydown",t,{capture:!0})}},[g,l,N,a,h,y,I,d,u]),c.jsxRuntimeExports.jsx(re.default,{...b,ref:O,role:"combobox",autoComplete:"off","aria-controls":T,"aria-expanded":I,"aria-activedescendant":I?H:void 0,label:p,value:P,error:k,warning:v,information:E,footnote:f,attachments:I?c.jsxRuntimeExports.jsx(ce,{isLoading:o,id:T,activeOptionId:H,selectedValue:S,options:l,onSelect:Z,onHover:ee}):null,className:K.cx(j,"kakadu-components-879486679"),onMouseDown:W,onChange:Q,onBeforeInput:J,onFocus:Y,onBlur:$,children:c.jsxRuntimeExports.jsx(ne.default,{width:14,height:14,className:"kakadu-components-158931186"})})}exports.default=ie;exports.getComboboxOptionString=_;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("../jsx-runtime-BB_1_6y_.js"),e=require("react"),K=require("@kuma-ui/core"),se=require("../hooks/use-synchronized-value.js"),ne=require("../icons/icon.js"),oe=require("../icons/chevron-up.js"),ae=require("../utilities/search.js"),re=require("./input.js"),B=require("./text.js"),X=require("./flex.js"),ue=require("./skeleton.js");function Y(){const{value:n,setValue:p}=se.default("isKeyboardNavigating");return e.useMemo(()=>({isKeyboardNavigating:n,setIsKeyboardNavigating:p}),[n,p])}function O(n){return"text"in n?n.text:n.label}const D="kakadu-components-1144794361",T="kakadu-components-2911184744";function ce({isSelected:n,id:p,value:v,label:a,onSelect:h,onHover:j}){const{isKeyboardNavigating:b}=Y(),g=e.useCallback(()=>{h(v)},[h,v]),l=e.useCallback(f=>{b||f.movementX===0&&f.movementY===0||j(v)},[b,j,v]),r=e.useRef(null);return e.useEffect(()=>{const f=r.current;n&&f&&b&&setTimeout(()=>{f.scrollIntoView({behavior:"smooth",block:"nearest"})},0)},[n,b]),i.jsxRuntimeExports.jsx("li",{ref:r,id:p,role:"option","aria-selected":n,tabIndex:-1,className:K.cx(D,"kakadu-components-4130497639",b?"kakadu-components-962373561":"kakadu-components-1109598791"),onClick:g,onMouseMove:l,children:i.jsxRuntimeExports.jsx(B.Span,{className:K.cx(T,typeof a=="string"&&"kakadu-components-154286052"),children:a})})}function ie({isLoading:n,id:p,activeOptionId:v,selectedValue:a,options:h,onSelect:j,onHover:b}){const g=e.useRef(null);return e.useEffect(()=>{const l=g.current;l&&l.scrollIntoView({behavior:"smooth",block:"nearest"})},[]),i.jsxRuntimeExports.jsxs("ul",{ref:g,id:p,role:"listbox","aria-label":"Options",tabIndex:-1,className:"kakadu-components-1951042708",children:[h.length===0?n?null:i.jsxRuntimeExports.jsxs(X.default,{"aria-atomic":!0,as:"li",role:"status","aria-live":"polite",direction:"row",preset:"start",gap:.5,className:D,children:[i.jsxRuntimeExports.jsx(ne.default,{size:15,type:"exclamationTriangle"}),i.jsxRuntimeExports.jsx(B.Span,{className:T,children:"No results."})]}):h.map((l,r)=>i.jsxRuntimeExports.jsx(ce,{...l,id:l.value===a?v:void 0,isSelected:l.value===a,onSelect:j,onHover:b},O(l)+r)),n?i.jsxRuntimeExports.jsx(X.default,{as:"li",alignment:"center",className:D,children:i.jsxRuntimeExports.jsx(B.Span,{className:T,children:i.jsxRuntimeExports.jsx(ue.SkeletonInstance,{width:"100%",height:"1.3em"})})}):null]})}function le({isLoading:n,shouldFilterOptions:p=!0,label:v,options:a,error:h,warning:j,information:b,footnote:g,className:l,onChange:r,onSelect:f,...F}){const S=e.useRef(null),H=e.useId(),P=e.useId(),[w,M]=e.useState(!1),$=e.useCallback(()=>{M(!0)},[]),G=e.useCallback(t=>{var s;(s=S.current)!=null&&s.contains(t.relatedTarget)||M(!1)},[]),[y,u]=e.useState(!1);e.useEffect(()=>{u(w)},[w]);const[A,I]=e.useState(""),{value:k}=F,[m,N]=e.useState(k),[q,J]=e.useState(k),z=e.useRef(q),c=e.useCallback(t=>{J(t),z.current=t},[]);e.useEffect(()=>{N(k),c(k)},[k,c]),e.useEffect(()=>{const t=a.find(s=>s.value===k);t?I(O(t)):k===void 0&&I("")},[k,a]);const Q=e.useCallback(()=>{m&&(I(""),c(void 0))},[m,c]),W=e.useCallback((t,s)=>{I(t),r==null||r(t,s),u(!0),N(void 0)},[r]),Z=e.useCallback(t=>{var s;(s=S.current)!=null&&s.contains(t.target)&&u(!0)},[]),E=e.useCallback(t=>{const s=t==null?void 0:t.value;c(s),t?I(O(t)):(I(""),r==null||r("")),f==null||f(s)},[c,r,f]),ee=e.useCallback(t=>{const s=a.find(x=>x.value===t);E(s),N(t),u(!1)},[a,E]),te=e.useCallback(t=>{c(t)},[c]),C=e.useDeferredValue(A),d=e.useMemo(()=>!p||m?a:ae.default(C,a,O),[p,m,a,C]);e.useEffect(()=>{!m&&C.length>0&&d.length>0&&!d.some(t=>q===t.value)&&c(d[0].value)},[m,C,d,q,c]);const{setIsKeyboardNavigating:V}=Y();return e.useEffect(()=>{if(!w)return;const t=s=>{s.movementX===0&&s.movementY===0||V(!1)};return window.addEventListener("mousemove",t,{capture:!0}),()=>{window.removeEventListener("mousemove",t,{capture:!0})}},[w,V]),e.useEffect(()=>{if(!w)return;const t=s=>{var U;let x;const _=d.length,L=d.findIndex(o=>o.value===z.current),R=()=>{s.preventDefault(),s.stopPropagation(),s.stopImmediatePropagation()};switch(s.key){case"Enter":{const o=d[L];o&&(R(),V(!0),u(!1),E(o),N(o.value));break}case"Escape":{if(y)R(),m?c(void 0):E(void 0),u(!1);else if(m)R(),u(!0),E(void 0);else{R(),M(!1);const o=document.activeElement;o instanceof HTMLElement&&((U=S.current)!=null&&U.contains(o))&&o.blur()}return}case"ArrowDown":{x=L+1,u(!0);break}case"ArrowUp":{x=L-1,u(!0),x<0&&(x=_-1);break}case"Home":{u(!0),x=0;break}case"End":{u(!0),x=_-1;break}case"Backspace":{d.some(o=>o.value===m)&&(R(),E(void 0),u(!0));break}}if(x!==void 0&&(R(),V(!0),_>0)){const o=d[x%_];o&&c(o.value)}};return window.addEventListener("keydown",t,{capture:!0}),()=>{window.removeEventListener("keydown",t,{capture:!0})}},[w,d,V,u,E,N,y,m,c]),i.jsxRuntimeExports.jsx(re.default,{...F,ref:S,role:"combobox",autoComplete:"off","aria-controls":H,"aria-expanded":y,"aria-activedescendant":y?P:void 0,label:v,value:A,error:h,warning:j,information:b,footnote:g,attachments:y?i.jsxRuntimeExports.jsx(ie,{isLoading:n,id:H,activeOptionId:P,selectedValue:q,options:d,onSelect:ee,onHover:te}):null,className:K.cx(l,"kakadu-components-879486679"),onMouseDown:Z,onChange:W,onBeforeInput:Q,onFocus:$,onBlur:G,children:i.jsxRuntimeExports.jsx(oe.default,{width:14,height:14,className:"kakadu-components-158931186"})})}exports.default=le;exports.getComboboxOptionString=O;
@@ -1,144 +1,148 @@
1
- import { j as c } from "../jsx-runtime-B4hRZ52C.mjs";
2
- import { useRef as D, useId as J, useState as L, useCallback as u, useEffect as w, useDeferredValue as ae, useMemo as W } from "react";
3
- import { cx as A } from "@kuma-ui/core";
4
- import ce from "../hooks/use-synchronized-value.mjs";
5
- import ie from "../icons/icon.mjs";
6
- import le from "../icons/chevron-up.mjs";
7
- import ue from "../utilities/search.mjs";
8
- import me from "./input.mjs";
9
- import { Span as P } from "./text.mjs";
10
- import Q from "./flex.mjs";
11
- import { SkeletonInstance as de } from "./skeleton.mjs";
12
- function Z() {
1
+ import { j as i } from "../jsx-runtime-B4hRZ52C.mjs";
2
+ import { useRef as H, useId as Q, useState as K, useCallback as m, useEffect as h, useDeferredValue as ce, useMemo as Z } from "react";
3
+ import { cx as P } from "@kuma-ui/core";
4
+ import ie from "../hooks/use-synchronized-value.mjs";
5
+ import le from "../icons/icon.mjs";
6
+ import ue from "../icons/chevron-up.mjs";
7
+ import me from "../utilities/search.mjs";
8
+ import de from "./input.mjs";
9
+ import { Span as R } from "./text.mjs";
10
+ import W from "./flex.mjs";
11
+ import { SkeletonInstance as fe } from "./skeleton.mjs";
12
+ function _() {
13
13
  const {
14
- value: s,
14
+ value: n,
15
15
  setValue: v
16
- } = ce("isKeyboardNavigating");
17
- return W(() => ({
18
- isKeyboardNavigating: s,
16
+ } = ie("isKeyboardNavigating");
17
+ return Z(() => ({
18
+ isKeyboardNavigating: n,
19
19
  setIsKeyboardNavigating: v
20
- }), [s, v]);
20
+ }), [n, v]);
21
21
  }
22
- function R(s) {
23
- return "text" in s ? s.text : s.label;
22
+ function F(n) {
23
+ return "text" in n ? n.text : n.label;
24
24
  }
25
25
  const z = "kakadu-components-1144794361", U = "kakadu-components-2911184744";
26
- function fe({
27
- isSelected: s,
26
+ function pe({
27
+ isSelected: n,
28
28
  id: v,
29
- value: i,
30
- label: x,
31
- onSelect: k,
32
- onHover: I
29
+ value: x,
30
+ label: o,
31
+ onSelect: w,
32
+ onHover: g
33
33
  }) {
34
34
  const {
35
- isKeyboardNavigating: f
36
- } = Z(), g = u(() => {
37
- k(i);
38
- }, [k, i]), n = u((b) => {
39
- f || b.movementX === 0 && b.movementY === 0 || I(i);
40
- }, [f, I, i]), p = D(null);
41
- return w(() => {
42
- const b = p.current;
43
- s && b && f && setTimeout(() => {
44
- b.scrollIntoView({
35
+ isKeyboardNavigating: b
36
+ } = _(), N = m(() => {
37
+ w(x);
38
+ }, [w, x]), l = m((d) => {
39
+ b || d.movementX === 0 && d.movementY === 0 || g(x);
40
+ }, [b, g, x]), r = H(null);
41
+ return h(() => {
42
+ const d = r.current;
43
+ n && d && b && setTimeout(() => {
44
+ d.scrollIntoView({
45
45
  behavior: "smooth",
46
46
  block: "nearest"
47
47
  });
48
48
  }, 0);
49
- }, [s, f]), /* @__PURE__ */ c.jsx("li", { ref: p, id: v, role: "option", "aria-selected": s, tabIndex: -1, className: A(z, "kakadu-components-4130497639", f ? "kakadu-components-962373561" : "kakadu-components-1109598791"), onClick: g, onMouseMove: n, children: /* @__PURE__ */ c.jsx(P, { className: A(U, typeof x == "string" && "kakadu-components-154286052"), children: x }) });
49
+ }, [n, b]), /* @__PURE__ */ i.jsx("li", { ref: r, id: v, role: "option", "aria-selected": n, tabIndex: -1, className: P(z, "kakadu-components-4130497639", b ? "kakadu-components-962373561" : "kakadu-components-1109598791"), onClick: N, onMouseMove: l, children: /* @__PURE__ */ i.jsx(R, { className: P(U, typeof o == "string" && "kakadu-components-154286052"), children: o }) });
50
50
  }
51
- function pe({
52
- isLoading: s,
51
+ function ve({
52
+ isLoading: n,
53
53
  id: v,
54
- activeOptionId: i,
55
- selectedValue: x,
56
- options: k,
57
- onSelect: I,
58
- onHover: f
54
+ activeOptionId: x,
55
+ selectedValue: o,
56
+ options: w,
57
+ onSelect: g,
58
+ onHover: b
59
59
  }) {
60
- const g = D(null);
61
- return w(() => {
62
- const n = g.current;
63
- n && n.scrollIntoView({
60
+ const N = H(null);
61
+ return h(() => {
62
+ const l = N.current;
63
+ l && l.scrollIntoView({
64
64
  behavior: "smooth",
65
65
  block: "nearest"
66
66
  });
67
- }, []), /* @__PURE__ */ c.jsxs("ul", { ref: g, id: v, role: "listbox", "aria-label": "Options", tabIndex: -1, className: "kakadu-components-1951042708", children: [
68
- k.length === 0 ? s ? null : /* @__PURE__ */ c.jsxs(Q, { "aria-atomic": !0, as: "li", role: "status", "aria-live": "polite", direction: "row", preset: "start", gap: 0.5, className: z, children: [
69
- /* @__PURE__ */ c.jsx(ie, { size: 15, type: "exclamationTriangle" }),
70
- /* @__PURE__ */ c.jsx(P, { className: U, children: "No results." })
71
- ] }) : k.map((n, p) => /* @__PURE__ */ c.jsx(
72
- fe,
67
+ }, []), /* @__PURE__ */ i.jsxs("ul", { ref: N, id: v, role: "listbox", "aria-label": "Options", tabIndex: -1, className: "kakadu-components-1951042708", children: [
68
+ w.length === 0 ? n ? null : /* @__PURE__ */ i.jsxs(W, { "aria-atomic": !0, as: "li", role: "status", "aria-live": "polite", direction: "row", preset: "start", gap: 0.5, className: z, children: [
69
+ /* @__PURE__ */ i.jsx(le, { size: 15, type: "exclamationTriangle" }),
70
+ /* @__PURE__ */ i.jsx(R, { className: U, children: "No results." })
71
+ ] }) : w.map((l, r) => /* @__PURE__ */ i.jsx(
72
+ pe,
73
73
  {
74
- ...n,
75
- id: n.value === x ? i : void 0,
76
- isSelected: n.value === x,
77
- onSelect: I,
78
- onHover: f
74
+ ...l,
75
+ id: l.value === o ? x : void 0,
76
+ isSelected: l.value === o,
77
+ onSelect: g,
78
+ onHover: b
79
79
  },
80
- R(n) + p
80
+ F(l) + r
81
81
  )),
82
- s ? /* @__PURE__ */ c.jsx(Q, { as: "li", alignment: "center", className: z, children: /* @__PURE__ */ c.jsx(P, { className: U, children: /* @__PURE__ */ c.jsx(de, { width: "100%", height: "1.3em" }) }) }) : null
82
+ n ? /* @__PURE__ */ i.jsx(W, { as: "li", alignment: "center", className: z, children: /* @__PURE__ */ i.jsx(R, { className: U, children: /* @__PURE__ */ i.jsx(fe, { width: "100%", height: "1.3em" }) }) }) : null
83
83
  ] });
84
84
  }
85
- function ye({
86
- isLoading: s,
87
- label: v,
88
- options: i,
89
- error: x,
90
- warning: k,
91
- information: I,
92
- footnote: f,
93
- className: g,
94
- onChange: n,
95
- onSelect: p,
96
- ...b
85
+ function Oe({
86
+ isLoading: n,
87
+ shouldFilterOptions: v = !0,
88
+ label: x,
89
+ options: o,
90
+ error: w,
91
+ warning: g,
92
+ information: b,
93
+ footnote: N,
94
+ className: l,
95
+ onChange: r,
96
+ onSelect: d,
97
+ ...X
97
98
  }) {
98
- const F = D(null), X = J(), Y = J(), [N, H] = L(!1), _ = u(() => {
99
- H(!0);
100
- }, []), $ = u((e) => {
99
+ const M = H(null), Y = Q(), q = Q(), [V, T] = K(!1), $ = m(() => {
100
+ T(!0);
101
+ }, []), ee = m((e) => {
101
102
  var t;
102
- (t = F.current) != null && t.contains(e.relatedTarget) || H(!1);
103
- }, []), [j, r] = L(!1);
104
- w(() => {
105
- r(N);
106
- }, [N]);
107
- const [q, K] = L(""), {
108
- value: y
109
- } = b, [m, O] = L(y), [M, ee] = L(y), C = D(M), a = u((e) => {
110
- ee(e), C.current = e;
103
+ (t = M.current) != null && t.contains(e.relatedTarget) || T(!1);
104
+ }, []), [O, a] = K(!1);
105
+ h(() => {
106
+ a(V);
107
+ }, [V]);
108
+ const [C, j] = K(""), {
109
+ value: k
110
+ } = X, [f, E] = K(k), [S, te] = K(k), G = H(S), c = m((e) => {
111
+ te(e), G.current = e;
111
112
  }, []);
112
- w(() => {
113
- O(y), a(y);
114
- }, [y, a]);
115
- const te = u(() => {
116
- m && (K(""), a(void 0));
117
- }, [m, a]), ne = u((e, t) => {
118
- K(e), n == null || n(e, t), r(!0), O(void 0);
119
- }, [n]), se = u((e) => {
113
+ h(() => {
114
+ E(k), c(k);
115
+ }, [k, c]), h(() => {
116
+ const e = o.find((t) => t.value === k);
117
+ e ? j(F(e)) : k === void 0 && j("");
118
+ }, [k, o]);
119
+ const ne = m(() => {
120
+ f && (j(""), c(void 0));
121
+ }, [f, c]), se = m((e, t) => {
122
+ j(e), r == null || r(e, t), a(!0), E(void 0);
123
+ }, [r]), oe = m((e) => {
120
124
  var t;
121
- (t = F.current) != null && t.contains(e.target) && r(!0);
122
- }, []), h = u((e) => {
125
+ (t = M.current) != null && t.contains(e.target) && a(!0);
126
+ }, []), I = m((e) => {
123
127
  const t = e == null ? void 0 : e.value;
124
- a(t), e ? K(R(e)) : (K(""), n == null || n("")), p == null || p(t);
125
- }, [a, n, p]), oe = u((e) => {
126
- const t = i.find((d) => d.value === e);
127
- h(t), O(e), r(!1);
128
- }, [i, h]), re = u((e) => {
129
- a(e);
130
- }, [a]), S = ae(q), l = W(() => m ? i : ue(S, i, R), [m, i, S]);
131
- w(() => {
132
- !m && S.length > 0 && l.length > 0 && !l.some((e) => M === e.value) && a(l[0].value);
133
- }, [m, S, l, M, a]);
128
+ c(t), e ? j(F(e)) : (j(""), r == null || r("")), d == null || d(t);
129
+ }, [c, r, d]), re = m((e) => {
130
+ const t = o.find((p) => p.value === e);
131
+ I(t), E(e), a(!1);
132
+ }, [o, I]), ae = m((e) => {
133
+ c(e);
134
+ }, [c]), B = ce(C), u = Z(() => !v || f ? o : me(B, o, F), [v, f, o, B]);
135
+ h(() => {
136
+ !f && B.length > 0 && u.length > 0 && !u.some((e) => S === e.value) && c(u[0].value);
137
+ }, [f, B, u, S, c]);
134
138
  const {
135
- setIsKeyboardNavigating: E
136
- } = Z();
137
- return w(() => {
138
- if (!N)
139
+ setIsKeyboardNavigating: L
140
+ } = _();
141
+ return h(() => {
142
+ if (!V)
139
143
  return;
140
144
  const e = (t) => {
141
- t.movementX === 0 && t.movementY === 0 || E(!1);
145
+ t.movementX === 0 && t.movementY === 0 || L(!1);
142
146
  };
143
147
  return window.addEventListener("mousemove", e, {
144
148
  capture: !0
@@ -147,57 +151,57 @@ function ye({
147
151
  capture: !0
148
152
  });
149
153
  };
150
- }, [N, E]), w(() => {
151
- if (!N)
154
+ }, [V, L]), h(() => {
155
+ if (!V)
152
156
  return;
153
157
  const e = (t) => {
154
- var G;
155
- let d;
156
- const B = l.length, T = l.findIndex((o) => o.value === C.current), V = () => {
158
+ var J;
159
+ let p;
160
+ const D = u.length, A = u.findIndex((s) => s.value === G.current), y = () => {
157
161
  t.preventDefault(), t.stopPropagation(), t.stopImmediatePropagation();
158
162
  };
159
163
  switch (t.key) {
160
164
  case "Enter": {
161
- const o = l[T];
162
- o && (V(), E(!0), r(!1), h(o), O(o.value));
165
+ const s = u[A];
166
+ s && (y(), L(!0), a(!1), I(s), E(s.value));
163
167
  break;
164
168
  }
165
169
  case "Escape": {
166
- if (j)
167
- V(), m ? a(void 0) : h(void 0), r(!1);
168
- else if (m)
169
- V(), r(!0), h(void 0);
170
+ if (O)
171
+ y(), f ? c(void 0) : I(void 0), a(!1);
172
+ else if (f)
173
+ y(), a(!0), I(void 0);
170
174
  else {
171
- V(), H(!1);
172
- const o = document.activeElement;
173
- o instanceof HTMLElement && ((G = F.current) != null && G.contains(o)) && o.blur();
175
+ y(), T(!1);
176
+ const s = document.activeElement;
177
+ s instanceof HTMLElement && ((J = M.current) != null && J.contains(s)) && s.blur();
174
178
  }
175
179
  return;
176
180
  }
177
181
  case "ArrowDown": {
178
- d = T + 1, r(!0);
182
+ p = A + 1, a(!0);
179
183
  break;
180
184
  }
181
185
  case "ArrowUp": {
182
- d = T - 1, r(!0), d < 0 && (d = B - 1);
186
+ p = A - 1, a(!0), p < 0 && (p = D - 1);
183
187
  break;
184
188
  }
185
189
  case "Home": {
186
- r(!0), d = 0;
190
+ a(!0), p = 0;
187
191
  break;
188
192
  }
189
193
  case "End": {
190
- r(!0), d = B - 1;
194
+ a(!0), p = D - 1;
191
195
  break;
192
196
  }
193
197
  case "Backspace": {
194
- l.some((o) => o.value === m) && (V(), h(void 0), r(!0));
198
+ u.some((s) => s.value === f) && (y(), I(void 0), a(!0));
195
199
  break;
196
200
  }
197
201
  }
198
- if (d !== void 0 && (V(), E(!0), B > 0)) {
199
- const o = l[d % B];
200
- o && a(o.value);
202
+ if (p !== void 0 && (y(), L(!0), D > 0)) {
203
+ const s = u[p % D];
204
+ s && c(s.value);
201
205
  }
202
206
  };
203
207
  return window.addEventListener("keydown", e, {
@@ -207,9 +211,9 @@ function ye({
207
211
  capture: !0
208
212
  });
209
213
  };
210
- }, [N, l, E, r, h, O, j, m, a]), /* @__PURE__ */ c.jsx(me, { ...b, ref: F, role: "combobox", autoComplete: "off", "aria-controls": X, "aria-expanded": j, "aria-activedescendant": j ? Y : void 0, label: v, value: q, error: x, warning: k, information: I, footnote: f, attachments: j ? /* @__PURE__ */ c.jsx(pe, { isLoading: s, id: X, activeOptionId: Y, selectedValue: M, options: l, onSelect: oe, onHover: re }) : null, className: A(g, "kakadu-components-879486679"), onMouseDown: se, onChange: ne, onBeforeInput: te, onFocus: _, onBlur: $, children: /* @__PURE__ */ c.jsx(le, { width: 14, height: 14, className: "kakadu-components-158931186" }) });
214
+ }, [V, u, L, a, I, E, O, f, c]), /* @__PURE__ */ i.jsx(de, { ...X, ref: M, role: "combobox", autoComplete: "off", "aria-controls": Y, "aria-expanded": O, "aria-activedescendant": O ? q : void 0, label: x, value: C, error: w, warning: g, information: b, footnote: N, attachments: O ? /* @__PURE__ */ i.jsx(ve, { isLoading: n, id: Y, activeOptionId: q, selectedValue: S, options: u, onSelect: re, onHover: ae }) : null, className: P(l, "kakadu-components-879486679"), onMouseDown: oe, onChange: se, onBeforeInput: ne, onFocus: $, onBlur: ee, children: /* @__PURE__ */ i.jsx(ue, { width: 14, height: 14, className: "kakadu-components-158931186" }) });
211
215
  }
212
216
  export {
213
- ye as default,
214
- R as getComboboxOptionString
217
+ Oe as default,
218
+ F as getComboboxOptionString
215
219
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kakadu/components",
3
- "version": "4.3.0",
3
+ "version": "4.3.2",
4
4
  "description": "Kakadu components library",
5
5
  "license": "MIT",
6
6
  "main": "./build/index.js",