@sikt/sds-combobox 3.2.1 → 3.3.0

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [3.3.0](https://gitlab.sikt.no/designsystem/sds-komponentbibliotek/compare/@sikt/sds-combobox@3.2.1...@sikt/sds-combobox@3.3.0) (2026-01-14)
6
+
7
+ ### Features
8
+
9
+ - **combobox:** add input props ([a4b1c38](https://gitlab.sikt.no/designsystem/sds-komponentbibliotek/commit/a4b1c38d58c52129f68bdbed591a0c092e72d483))
10
+
11
+ ### Bug Fixes
12
+
13
+ - **deps:** update dependency react-aria-components to ^1.13.0 ([2171536](https://gitlab.sikt.no/designsystem/sds-komponentbibliotek/commit/2171536113068938f1701912ddd0e03ff5cc773f))
14
+ - **deps:** update dependency react-aria-components to ^1.14.0 ([323d4b6](https://gitlab.sikt.no/designsystem/sds-komponentbibliotek/commit/323d4b610cb823a48b66ee99d0090300d719e275))
15
+
5
16
  ## [3.2.1](https://gitlab.sikt.no/designsystem/sds-komponentbibliotek/compare/@sikt/sds-combobox@3.2.0...@sikt/sds-combobox@3.2.1) (2025-10-09)
6
17
 
7
18
  ### Bug Fixes
package/dist/index.d.mts CHANGED
@@ -1,31 +1,53 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
2
+ import { ReactNode, InputHTMLAttributes } from 'react';
3
3
  import { ComboBoxProps, PopoverProps, ListBoxItemProps } from 'react-aria-components';
4
4
 
5
5
  interface ComboboxBaseProps<T extends object> extends Omit<ComboBoxProps<T>, "children" | "menuTrigger" | "aria-label" | "aria-labelledby"> {
6
6
  children: ReactNode | ((item: T) => ReactNode);
7
7
  className?: string;
8
+ /**
9
+ * Text to show when the input is invalid to help the user enter correct value. This also sets `aria-invalid` & `aria-errormessage`.
10
+ */
8
11
  errorText?: ReactNode;
12
+ /**
13
+ * Text to show to help the user enter correct value. It's a better pattern to have enough information in the `label`.
14
+ */
9
15
  helpText?: ReactNode;
10
16
  menuTrigger?: "focus" | "manual" | "input";
11
17
  popoverProps?: PopoverProps;
18
+ inputProps?: InputHTMLAttributes<HTMLInputElement>;
12
19
  }
13
20
  type ComboboxProps<T extends object> = ComboboxBaseProps<T> & ({
14
21
  label: NonNullable<ReactNode>;
15
22
  "aria-labelledby"?: never;
16
23
  } | {
17
24
  label?: never;
25
+ /**
26
+ * Id (or id's) that identifies the element (or elements) that labels the element it is applied to. For accessibility these should NOT be visually hidden.
27
+ */
18
28
  "aria-labelledby": string;
19
29
  });
20
- declare function Combobox<T extends object>({ children, className, errorText, helpText, label, "aria-labelledby": ariaLabelledBy, menuTrigger, popoverProps, ...props }: ComboboxProps<T>): react_jsx_runtime.JSX.Element;
30
+ declare function Combobox<T extends object>({ children, className, errorText, helpText, label, "aria-labelledby": ariaLabelledBy, menuTrigger, popoverProps, inputProps, ...props }: ComboboxProps<T>): react_jsx_runtime.JSX.Element;
31
+ declare namespace Combobox {
32
+ var displayName: string;
33
+ }
21
34
  declare function ComboboxItem({ className, ...props }: ListBoxItemProps & {
22
35
  className?: string;
23
36
  }): react_jsx_runtime.JSX.Element;
37
+ declare namespace ComboboxItem {
38
+ var displayName: string;
39
+ }
24
40
  declare function ComboboxHeader({ children }: {
25
41
  children: ReactNode;
26
42
  }): react_jsx_runtime.JSX.Element;
43
+ declare namespace ComboboxHeader {
44
+ var displayName: string;
45
+ }
27
46
  declare function ComboboxSection({ children }: {
28
47
  children: ReactNode;
29
48
  }): react_jsx_runtime.JSX.Element;
49
+ declare namespace ComboboxSection {
50
+ var displayName: string;
51
+ }
30
52
 
31
53
  export { Combobox, ComboboxHeader, ComboboxItem, type ComboboxProps, ComboboxSection };
package/dist/index.d.ts CHANGED
@@ -1,31 +1,53 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
2
+ import { ReactNode, InputHTMLAttributes } from 'react';
3
3
  import { ComboBoxProps, PopoverProps, ListBoxItemProps } from 'react-aria-components';
4
4
 
5
5
  interface ComboboxBaseProps<T extends object> extends Omit<ComboBoxProps<T>, "children" | "menuTrigger" | "aria-label" | "aria-labelledby"> {
6
6
  children: ReactNode | ((item: T) => ReactNode);
7
7
  className?: string;
8
+ /**
9
+ * Text to show when the input is invalid to help the user enter correct value. This also sets `aria-invalid` & `aria-errormessage`.
10
+ */
8
11
  errorText?: ReactNode;
12
+ /**
13
+ * Text to show to help the user enter correct value. It's a better pattern to have enough information in the `label`.
14
+ */
9
15
  helpText?: ReactNode;
10
16
  menuTrigger?: "focus" | "manual" | "input";
11
17
  popoverProps?: PopoverProps;
18
+ inputProps?: InputHTMLAttributes<HTMLInputElement>;
12
19
  }
13
20
  type ComboboxProps<T extends object> = ComboboxBaseProps<T> & ({
14
21
  label: NonNullable<ReactNode>;
15
22
  "aria-labelledby"?: never;
16
23
  } | {
17
24
  label?: never;
25
+ /**
26
+ * Id (or id's) that identifies the element (or elements) that labels the element it is applied to. For accessibility these should NOT be visually hidden.
27
+ */
18
28
  "aria-labelledby": string;
19
29
  });
20
- declare function Combobox<T extends object>({ children, className, errorText, helpText, label, "aria-labelledby": ariaLabelledBy, menuTrigger, popoverProps, ...props }: ComboboxProps<T>): react_jsx_runtime.JSX.Element;
30
+ declare function Combobox<T extends object>({ children, className, errorText, helpText, label, "aria-labelledby": ariaLabelledBy, menuTrigger, popoverProps, inputProps, ...props }: ComboboxProps<T>): react_jsx_runtime.JSX.Element;
31
+ declare namespace Combobox {
32
+ var displayName: string;
33
+ }
21
34
  declare function ComboboxItem({ className, ...props }: ListBoxItemProps & {
22
35
  className?: string;
23
36
  }): react_jsx_runtime.JSX.Element;
37
+ declare namespace ComboboxItem {
38
+ var displayName: string;
39
+ }
24
40
  declare function ComboboxHeader({ children }: {
25
41
  children: ReactNode;
26
42
  }): react_jsx_runtime.JSX.Element;
43
+ declare namespace ComboboxHeader {
44
+ var displayName: string;
45
+ }
27
46
  declare function ComboboxSection({ children }: {
28
47
  children: ReactNode;
29
48
  }): react_jsx_runtime.JSX.Element;
49
+ declare namespace ComboboxSection {
50
+ var displayName: string;
51
+ }
30
52
 
31
53
  export { Combobox, ComboboxHeader, ComboboxItem, type ComboboxProps, ComboboxSection };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("@sikt/sds-form"),r=require("@sikt/sds-icons"),o=require("clsx/lite"),s=require("react"),t=require("react-aria-components"),a=require("react/jsx-runtime"),l=Object.defineProperty,i=Object.defineProperties,c=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,b=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,d=(e,r,o)=>r in e?l(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,m=(e,r)=>{for(var o in r||(r={}))b.call(r,o)&&d(e,o,r[o]);if(n)for(var o of n(r))x.call(r,o)&&d(e,o,r[o]);return e},p=(e,r)=>i(e,c(r)),u=(e,r)=>{var o={};for(var s in e)b.call(e,s)&&r.indexOf(s)<0&&(o[s]=e[s]);if(null!=e&&n)for(var s of n(e))r.indexOf(s)<0&&x.call(e,s)&&(o[s]=e[s]);return o},f=e=>{let r="";return"string"==typeof e?r=e:"number"==typeof e?r=e.toString():e instanceof Array?e.forEach(e=>{r+=f(e)}):s.isValidElement(e)&&(r+=f(e.props.children)),r};exports.Combobox=function(l){var i=l,{children:c,className:n,errorText:b,helpText:x,label:d,"aria-labelledby":h,menuTrigger:j="focus",popoverProps:v}=i,y=u(i,["children","className","errorText","helpText","label","aria-labelledby","menuTrigger","popoverProps"]);const _=s.useId(),g="".concat(_,"-error-text"),N="".concat(_,"-help-text"),O=f(d),T=[b&&g,x&&N].filter(Boolean).join(" ")||void 0;return a.jsx(e.FormField,{className:o.clsx("sds-combobox",b&&"sds-combobox--invalid",n),label:d,errorText:b,errorTextId:g,helpText:x,helpTextId:N,htmlFor:_,children:a.jsxs(t.ComboBox,p(m({menuTrigger:j,id:_,"aria-label":O,"aria-labelledby":h},y),{children:[a.jsxs("div",{className:"sds-combobox__combobox",children:[a.jsx(t.Input,{className:"sds-combobox__combobox-input","aria-describedby":T,"aria-invalid":Boolean(b),"aria-errormessage":b?g:void 0}),a.jsx(t.Button,{className:"sds-combobox__combobox-button",children:a.jsx(r.ExpandShowAltIcon,{})})]}),a.jsx(t.Popover,p(m({className:"sds-combobox__popover"},v),{children:a.jsx(t.ListBox,{className:"sds-combobox__listbox",children:c})}))]}))})},exports.ComboboxHeader=function({children:e}){return a.jsx(t.Header,{className:"sds-combobox__header",children:e})},exports.ComboboxItem=function(e){var r=e,{className:s}=r,l=u(r,["className"]);return a.jsx(t.ListBoxItem,m({className:o.clsx("sds-combobox__item",s)},l))},exports.ComboboxSection=function({children:e}){return a.jsx(t.ListBoxSection,{children:e})};//# sourceMappingURL=index.js.map
1
+ "use strict";var e=require("@sikt/sds-form"),o=require("@sikt/sds-icons"),r=require("clsx/lite"),s=require("react"),a=require("react-aria-components"),t=require("react/jsx-runtime"),i=Object.defineProperty,l=Object.defineProperties,c=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,b=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,m=(e,o,r)=>o in e?i(e,o,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[o]=r,d=(e,o)=>{for(var r in o||(o={}))b.call(o,r)&&m(e,r,o[r]);if(n)for(var r of n(o))x.call(o,r)&&m(e,r,o[r]);return e},p=(e,o)=>l(e,c(o)),u=(e,o)=>{var r={};for(var s in e)b.call(e,s)&&o.indexOf(s)<0&&(r[s]=e[s]);if(null!=e&&n)for(var s of n(e))o.indexOf(s)<0&&x.call(e,s)&&(r[s]=e[s]);return r},f=e=>{let o="";return"string"==typeof e?o=e:"number"==typeof e?o=e.toString():e instanceof Array?e.forEach(e=>{o+=f(e)}):s.isValidElement(e)&&(o+=f(e.props.children)),o};function h(i){var l=i,{children:c,className:n,errorText:b,helpText:x,label:m,"aria-labelledby":h,menuTrigger:j="focus",popoverProps:y,inputProps:v}=l,N=u(l,["children","className","errorText","helpText","label","aria-labelledby","menuTrigger","popoverProps","inputProps"]);const _=s.useId(),g="".concat(_,"-error-text"),O="".concat(_,"-help-text"),T=f(m),P=[b&&g,x&&O].filter(Boolean).join(" ")||void 0;return t.jsx(e.FormField,{className:r.clsx("sds-combobox",b&&"sds-combobox--invalid",n),label:m,errorText:b,errorTextId:g,helpText:x,helpTextId:O,htmlFor:_,children:t.jsxs(a.ComboBox,p(d({menuTrigger:j,id:_,"aria-label":T,"aria-labelledby":h},N),{children:[t.jsxs("div",{className:"sds-combobox__combobox",children:[t.jsx(a.Input,d({className:"sds-combobox__combobox-input","aria-describedby":P,"aria-invalid":Boolean(b),"aria-errormessage":b?g:void 0},v)),t.jsx(a.Button,{className:"sds-combobox__combobox-button",children:t.jsx(o.ExpandShowAltIcon,{})})]}),t.jsx(a.Popover,p(d({className:"sds-combobox__popover"},y),{children:t.jsx(a.ListBox,{className:"sds-combobox__listbox",children:c})}))]}))})}function j(e){var o=e,{className:s}=o,i=u(o,["className"]);return t.jsx(a.ListBoxItem,d({className:r.clsx("sds-combobox__item",s)},i))}function y({children:e}){return t.jsx(a.Header,{className:"sds-combobox__header",children:e})}function v({children:e}){return t.jsx(a.ListBoxSection,{children:e})}h.displayName="Combobox",j.displayName="ComboboxItem",y.displayName="ComboboxHeader",v.displayName="ComboboxSection",exports.Combobox=h,exports.ComboboxHeader=y,exports.ComboboxItem=j,exports.ComboboxSection=v;//# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/reactNodeToString.ts","../src/Combobox.tsx"],"names":["isValidElement","useId","jsx","FormField","clsx","jsxs","AriaCombobox","Input","Button","ExpandShowAltIcon","Popover","ListBox","ListBoxItem","Header","ListBoxSection"],"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,EAAA,SAAA,EAAU,uBAA4B,EAAA,EAAA,YAAA,CAAA,EAA9C,EACC,QAAA,kBAAAR,cAAA,CAACS,2BAAQ,EAAA,EAAA,SAAA,EAAU,uBAAyB,EAAA,QAAA,EAAS,CACvD,EAAA,CAAA;AAAA;AAAA,SAAA;AAAA;AACF;AAAA,GACF;AAEJ;AAEO,SAAS,aAAa,EAGiB,EAAA;AAHjB,EAC3B,IAAA,EAAA,GAAA,EAAA,EAAA;AAAA,IAAA;AAAA,GA3GF,GA0G6B,EAExB,EAAA,KAAA,GAAA,SAAA,CAFwB,EAExB,EAAA;AAAA,IADH;AAAA,GAAA,CAAA;AAGA,EAAA,sCACGC,+BAAY,EAAA,cAAA,CAAA,EAAA,SAAA,EAAWR,UAAK,oBAAsB,EAAA,SAAS,KAAO,KAAO,CAAA,CAAA;AAE9E;AAEO,SAAS,cAAA,CAAe,EAAE,QAAA,EAAqC,EAAA;AACpE,EAAA,uBAAQF,cAAA,CAAAW,0BAAA,EAAA,EAAO,SAAU,EAAA,sBAAA,EAAwB,QAAS,EAAA,CAAA;AAC5D;AAEO,SAAS,eAAA,CAAgB,EAAE,QAAA,EAAqC,EAAA;AACrE,EAAO,uBAAAX,cAAA,CAACY,sCAAgB,QAAS,EAAA,CAAA;AACnC","file":"index.js","sourcesContent":["import { isValidElement, ReactNode } from \"react\";\n\nexport const reactNodeToString = (reactNode: ReactNode): string => {\n let string = \"\";\n if (typeof reactNode === \"string\") {\n string = reactNode;\n } else if (typeof reactNode === \"number\") {\n string = reactNode.toString();\n } else if (reactNode instanceof Array) {\n reactNode.forEach((child) => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n string += reactNodeToString(child);\n });\n } else if (isValidElement(reactNode)) {\n // @ts-expect-error is of type unknown\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n string += reactNodeToString(reactNode.props.children);\n }\n return string;\n};\n","import { FormField } from \"@sikt/sds-form\";\nimport { ExpandShowAltIcon } from \"@sikt/sds-icons\";\nimport { clsx } from \"clsx/lite\";\nimport { ReactNode, useId } from \"react\";\nimport {\n ComboBox as AriaCombobox,\n ComboBoxProps as AriaComboboxProps,\n Button,\n Header,\n Input,\n ListBox,\n ListBoxItem,\n ListBoxItemProps,\n ListBoxSection,\n Popover,\n PopoverProps,\n} from \"react-aria-components\";\nimport \"./combobox.pcss\";\nimport { reactNodeToString } from \"./reactNodeToString\";\n\ninterface ComboboxBaseProps<T extends object>\n extends Omit<\n AriaComboboxProps<T>,\n \"children\" | \"menuTrigger\" | \"aria-label\" | \"aria-labelledby\"\n > {\n children: ReactNode | ((item: T) => ReactNode);\n className?: string;\n errorText?: ReactNode;\n helpText?: ReactNode;\n menuTrigger?: \"focus\" | \"manual\" | \"input\";\n popoverProps?: PopoverProps;\n}\n\nexport type ComboboxProps<T extends object> = ComboboxBaseProps<T> &\n (\n | {\n label: NonNullable<ReactNode>;\n \"aria-labelledby\"?: never;\n }\n | {\n label?: never;\n \"aria-labelledby\": string;\n }\n );\n\nexport function Combobox<T extends object>({\n children,\n className,\n errorText,\n helpText,\n label,\n \"aria-labelledby\": ariaLabelledBy,\n menuTrigger = \"focus\",\n popoverProps,\n ...props\n}: ComboboxProps<T>) {\n const id = useId();\n const errorTextId = `${id}-error-text`;\n const helpTextId = `${id}-help-text`;\n\n const ariaLabel = reactNodeToString(label);\n const ariaDescribedBy =\n [errorText && errorTextId, helpText && helpTextId]\n .filter(Boolean)\n .join(\" \") || undefined;\n\n return (\n <FormField\n className={clsx(\n \"sds-combobox\",\n errorText && \"sds-combobox--invalid\",\n className,\n )}\n label={label}\n errorText={errorText}\n errorTextId={errorTextId}\n helpText={helpText}\n helpTextId={helpTextId}\n htmlFor={id}\n >\n <AriaCombobox\n menuTrigger={menuTrigger}\n id={id}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n {...props}\n >\n <div className=\"sds-combobox__combobox\">\n <Input\n className=\"sds-combobox__combobox-input\"\n aria-describedby={ariaDescribedBy}\n aria-invalid={Boolean(errorText)}\n aria-errormessage={errorText ? errorTextId : undefined}\n />\n <Button className=\"sds-combobox__combobox-button\">\n <ExpandShowAltIcon />\n </Button>\n </div>\n <Popover className=\"sds-combobox__popover\" {...popoverProps}>\n <ListBox className=\"sds-combobox__listbox\">{children}</ListBox>\n </Popover>\n </AriaCombobox>\n </FormField>\n );\n}\n\nexport function ComboboxItem({\n className,\n ...props\n}: ListBoxItemProps & { className?: string }) {\n return (\n <ListBoxItem className={clsx(\"sds-combobox__item\", className)} {...props} />\n );\n}\n\nexport function ComboboxHeader({ children }: { children: ReactNode }) {\n return <Header className=\"sds-combobox__header\">{children}</Header>;\n}\n\nexport function ComboboxSection({ children }: { children: ReactNode }) {\n return <ListBoxSection>{children}</ListBoxSection>;\n}\n"]}
1
+ {"version":3,"sources":["../../core/src/utils/reactNodeToString.ts","../src/Combobox.tsx"],"names":["isValidElement","useId","jsx","FormField","clsx","jsxs","AriaCombobox","Input","Button","ExpandShowAltIcon","Popover","ListBox","ListBoxItem","Header","ListBoxSection"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,IAAM,iBAAA,GAAoB,CAAC,SAAiC,KAAA;AACjE,EAAA,IAAI,MAAS,GAAA,EAAA;AACb,EAAI,IAAA,OAAO,cAAc,QAAU,EAAA;AACjC,IAAS,MAAA,GAAA,SAAA;AAAA,GACX,MAAA,IAAW,OAAO,SAAA,KAAc,QAAU,EAAA;AACxC,IAAA,MAAA,GAAS,UAAU,QAAS,EAAA;AAAA,GAC9B,MAAA,IAAW,qBAAqB,KAAO,EAAA;AACrC,IAAU,SAAA,CAAA,OAAA,CAAQ,CAAC,KAAU,KAAA;AAE3B,MAAA,MAAA,IAAU,kBAAkB,KAAK,CAAA;AAAA,KAClC,CAAA;AAAA,GACH,MAAA,IAAWA,oBAAe,CAAA,SAAS,CAAG,EAAA;AAGpC,IAAU,MAAA,IAAA,iBAAA,CAAkB,SAAU,CAAA,KAAA,CAAM,QAAQ,CAAA;A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,SAAS,KAAO,KAAO,CAAA,CAAA;AAE9E;AACA,YAAA,CAAa,WAAc,GAAA,cAAA;AAEpB,SAAS,cAAA,CAAe,EAAE,QAAA,EAAqC,EAAA;AACpE,EAAA,uBAAQF,cAAA,CAAAW,0BAAA,EAAA,EAAO,SAAU,EAAA,sBAAA,EAAwB,QAAS,EAAA,CAAA;AAC5D;AACA,cAAA,CAAe,WAAc,GAAA,gBAAA;AAEtB,SAAS,eAAA,CAAgB,EAAE,QAAA,EAAqC,EAAA;AACrE,EAAO,uBAAAX,cAAA,CAACY,sCAAgB,QAAS,EAAA,CAAA;AACnC;AACA,eAAA,CAAgB,WAAc,GAAA,iBAAA","file":"index.js","sourcesContent":["import { isValidElement, ReactNode } from \"react\";\n\nexport const reactNodeToString = (reactNode: ReactNode): string => {\n let string = \"\";\n if (typeof reactNode === \"string\") {\n string = reactNode;\n } else if (typeof reactNode === \"number\") {\n string = reactNode.toString();\n } else if (reactNode instanceof Array) {\n reactNode.forEach((child) => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n string += reactNodeToString(child);\n });\n } else if (isValidElement(reactNode)) {\n // @ts-expect-error is of type unknown\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n string += reactNodeToString(reactNode.props.children);\n }\n return string;\n};\n","import { FormField } from \"@sikt/sds-form\";\nimport { ExpandShowAltIcon } from \"@sikt/sds-icons\";\nimport { clsx } from \"clsx/lite\";\nimport { InputHTMLAttributes, ReactNode, useId } from \"react\";\nimport {\n ComboBox as AriaCombobox,\n ComboBoxProps as AriaComboboxProps,\n Button,\n Header,\n Input,\n ListBox,\n ListBoxItem,\n ListBoxItemProps,\n ListBoxSection,\n Popover,\n PopoverProps,\n} from \"react-aria-components\";\nimport \"./combobox.pcss\";\nimport { reactNodeToString } from \"../../core/src/utils/reactNodeToString\";\n\ninterface ComboboxBaseProps<T extends object> extends Omit<\n AriaComboboxProps<T>,\n \"children\" | \"menuTrigger\" | \"aria-label\" | \"aria-labelledby\"\n> {\n children: ReactNode | ((item: T) => ReactNode);\n className?: string;\n /**\n * Text to show when the input is invalid to help the user enter correct value. This also sets `aria-invalid` & `aria-errormessage`.\n */\n errorText?: ReactNode;\n /**\n * Text to show to help the user enter correct value. It's a better pattern to have enough information in the `label`.\n */\n helpText?: ReactNode;\n menuTrigger?: \"focus\" | \"manual\" | \"input\";\n popoverProps?: PopoverProps;\n inputProps?: InputHTMLAttributes<HTMLInputElement>;\n}\n\nexport type ComboboxProps<T extends object> = ComboboxBaseProps<T> &\n (\n | {\n label: NonNullable<ReactNode>;\n \"aria-labelledby\"?: never;\n }\n | {\n label?: never;\n /**\n * Id (or id's) that identifies the element (or elements) that labels the element it is applied to. For accessibility these should NOT be visually hidden.\n */\n \"aria-labelledby\": string;\n }\n );\n\nexport function Combobox<T extends object>({\n children,\n className,\n errorText,\n helpText,\n label,\n \"aria-labelledby\": ariaLabelledBy,\n menuTrigger = \"focus\",\n popoverProps,\n inputProps,\n ...props\n}: ComboboxProps<T>) {\n const id = useId();\n const errorTextId = `${id}-error-text`;\n const helpTextId = `${id}-help-text`;\n\n const ariaLabel = reactNodeToString(label);\n const ariaDescribedBy =\n [errorText && errorTextId, helpText && helpTextId]\n .filter(Boolean)\n .join(\" \") || undefined;\n\n return (\n <FormField\n className={clsx(\n \"sds-combobox\",\n errorText && \"sds-combobox--invalid\",\n className,\n )}\n label={label}\n errorText={errorText}\n errorTextId={errorTextId}\n helpText={helpText}\n helpTextId={helpTextId}\n htmlFor={id}\n >\n <AriaCombobox\n menuTrigger={menuTrigger}\n id={id}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n {...props}\n >\n <div className=\"sds-combobox__combobox\">\n <Input\n className=\"sds-combobox__combobox-input\"\n aria-describedby={ariaDescribedBy}\n aria-invalid={Boolean(errorText)}\n aria-errormessage={errorText ? errorTextId : undefined}\n {...inputProps}\n />\n <Button className=\"sds-combobox__combobox-button\">\n <ExpandShowAltIcon />\n </Button>\n </div>\n <Popover className=\"sds-combobox__popover\" {...popoverProps}>\n <ListBox className=\"sds-combobox__listbox\">{children}</ListBox>\n </Popover>\n </AriaCombobox>\n </FormField>\n );\n}\nCombobox.displayName = \"Combobox\";\n\nexport function ComboboxItem({\n className,\n ...props\n}: ListBoxItemProps & { className?: string }) {\n return (\n <ListBoxItem className={clsx(\"sds-combobox__item\", className)} {...props} />\n );\n}\nComboboxItem.displayName = \"ComboboxItem\";\n\nexport function ComboboxHeader({ children }: { children: ReactNode }) {\n return <Header className=\"sds-combobox__header\">{children}</Header>;\n}\nComboboxHeader.displayName = \"ComboboxHeader\";\n\nexport function ComboboxSection({ children }: { children: ReactNode }) {\n return <ListBoxSection>{children}</ListBoxSection>;\n}\nComboboxSection.displayName = \"ComboboxSection\";\n"]}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{FormField as e}from"@sikt/sds-form";import{ExpandShowAltIcon as r}from"@sikt/sds-icons";import{clsx as o}from"clsx/lite";import{useId as a,isValidElement as t}from"react";import{ComboBox as l,Input as i,Button as s,Popover as c,ListBox as n,ListBoxItem as b,Header as m,ListBoxSection as d}from"react-aria-components";import{jsx as p,jsxs as f}from"react/jsx-runtime";var x=Object.defineProperty,u=Object.defineProperties,h=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,y=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable,g=(e,r,o)=>r in e?x(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,N=(e,r)=>{for(var o in r||(r={}))y.call(r,o)&&g(e,o,r[o]);if(v)for(var o of v(r))_.call(r,o)&&g(e,o,r[o]);return e},O=(e,r)=>u(e,h(r)),T=(e,r)=>{var o={};for(var a in e)y.call(e,a)&&r.indexOf(a)<0&&(o[a]=e[a]);if(null!=e&&v)for(var a of v(e))r.indexOf(a)<0&&_.call(e,a)&&(o[a]=e[a]);return o},j=e=>{let r="";return"string"==typeof e?r=e:"number"==typeof e?r=e.toString():e instanceof Array?e.forEach(e=>{r+=j(e)}):t(e)&&(r+=j(e.props.children)),r};function P(t){var b=t,{children:m,className:d,errorText:x,helpText:u,label:h,"aria-labelledby":v,menuTrigger:y="focus",popoverProps:_}=b,g=T(b,["children","className","errorText","helpText","label","aria-labelledby","menuTrigger","popoverProps"]);const P=a(),w="".concat(P,"-error-text"),I="".concat(P,"-help-text"),k=j(h),B=[x&&w,u&&I].filter(Boolean).join(" ")||void 0;return p(e,{className:o("sds-combobox",x&&"sds-combobox--invalid",d),label:h,errorText:x,errorTextId:w,helpText:u,helpTextId:I,htmlFor:P,children:f(l,O(N({menuTrigger:y,id:P,"aria-label":k,"aria-labelledby":v},g),{children:[f("div",{className:"sds-combobox__combobox",children:[p(i,{className:"sds-combobox__combobox-input","aria-describedby":B,"aria-invalid":Boolean(x),"aria-errormessage":x?w:void 0}),p(s,{className:"sds-combobox__combobox-button",children:p(r,{})})]}),p(c,O(N({className:"sds-combobox__popover"},_),{children:p(n,{className:"sds-combobox__listbox",children:m})}))]}))})}function w(e){var r=e,{className:a}=r,t=T(r,["className"]);return p(b,N({className:o("sds-combobox__item",a)},t))}function I({children:e}){return p(m,{className:"sds-combobox__header",children:e})}function k({children:e}){return p(d,{children:e})}export{P as Combobox,I as ComboboxHeader,w as ComboboxItem,k as ComboboxSection};//# sourceMappingURL=index.mjs.map
1
+ import{FormField as e}from"@sikt/sds-form";import{ExpandShowAltIcon as r}from"@sikt/sds-icons";import{clsx as o}from"clsx/lite";import{useId as a,isValidElement as t}from"react";import{ComboBox as l,Input as i,Button as s,Popover as c,ListBox as n,ListBoxItem as b,Header as m,ListBoxSection as d}from"react-aria-components";import{jsx as p,jsxs as x}from"react/jsx-runtime";var f=Object.defineProperty,u=Object.defineProperties,h=Object.getOwnPropertyDescriptors,y=Object.getOwnPropertySymbols,v=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable,_=(e,r,o)=>r in e?f(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,g=(e,r)=>{for(var o in r||(r={}))v.call(r,o)&&_(e,o,r[o]);if(y)for(var o of y(r))N.call(r,o)&&_(e,o,r[o]);return e},O=(e,r)=>u(e,h(r)),T=(e,r)=>{var o={};for(var a in e)v.call(e,a)&&r.indexOf(a)<0&&(o[a]=e[a]);if(null!=e&&y)for(var a of y(e))r.indexOf(a)<0&&N.call(e,a)&&(o[a]=e[a]);return o},P=e=>{let r="";return"string"==typeof e?r=e:"number"==typeof e?r=e.toString():e instanceof Array?e.forEach(e=>{r+=P(e)}):t(e)&&(r+=P(e.props.children)),r};function j(t){var b=t,{children:m,className:d,errorText:f,helpText:u,label:h,"aria-labelledby":y,menuTrigger:v="focus",popoverProps:N,inputProps:_}=b,j=T(b,["children","className","errorText","helpText","label","aria-labelledby","menuTrigger","popoverProps","inputProps"]);const w=a(),C="".concat(w,"-error-text"),I="".concat(w,"-help-text"),S=P(h),k=[f&&C,u&&I].filter(Boolean).join(" ")||void 0;return p(e,{className:o("sds-combobox",f&&"sds-combobox--invalid",d),label:h,errorText:f,errorTextId:C,helpText:u,helpTextId:I,htmlFor:w,children:x(l,O(g({menuTrigger:v,id:w,"aria-label":S,"aria-labelledby":y},j),{children:[x("div",{className:"sds-combobox__combobox",children:[p(i,g({className:"sds-combobox__combobox-input","aria-describedby":k,"aria-invalid":Boolean(f),"aria-errormessage":f?C:void 0},_)),p(s,{className:"sds-combobox__combobox-button",children:p(r,{})})]}),p(c,O(g({className:"sds-combobox__popover"},N),{children:p(n,{className:"sds-combobox__listbox",children:m})}))]}))})}function w(e){var r=e,{className:a}=r,t=T(r,["className"]);return p(b,g({className:o("sds-combobox__item",a)},t))}function C({children:e}){return p(m,{className:"sds-combobox__header",children:e})}function I({children:e}){return p(d,{children:e})}j.displayName="Combobox",w.displayName="ComboboxItem",C.displayName="ComboboxHeader",I.displayName="ComboboxSection";export{j as Combobox,C as ComboboxHeader,w as ComboboxItem,I as ComboboxSection};//# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,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OAAQ,EAAA,aAAA,CAAA,cAAA,CAAA,EAAA,SAAA,EAAU,uBAA4B,EAAA,EAAA,YAAA,CAAA,EAA9C,EACC,QAAA,kBAAA,GAAA,CAAC,OAAQ,EAAA,EAAA,SAAA,EAAU,uBAAyB,EAAA,QAAA,EAAS,CACvD,EAAA,CAAA;AAAA;AAAA,SAAA;AAAA;AACF;AAAA,GACF;AAEJ;AAEO,SAAS,aAAa,EAGiB,EAAA;AAHjB,EAC3B,IAAA,EAAA,GAAA,EAAA,EAAA;AAAA,IAAA;AAAA,GA3GF,GA0G6B,EAExB,EAAA,KAAA,GAAA,SAAA,CAFwB,EAExB,EAAA;AAAA,IADH;AAAA,GAAA,CAAA;AAGA,EAAA,2BACG,WAAY,EAAA,cAAA,CAAA,EAAA,SAAA,EAAW,KAAK,oBAAsB,EAAA,SAAS,KAAO,KAAO,CAAA,CAAA;AAE9E;AAEO,SAAS,cAAA,CAAe,EAAE,QAAA,EAAqC,EAAA;AACpE,EAAA,uBAAQ,GAAA,CAAA,MAAA,EAAA,EAAO,SAAU,EAAA,sBAAA,EAAwB,QAAS,EAAA,CAAA;AAC5D;AAEO,SAAS,eAAA,CAAgB,EAAE,QAAA,EAAqC,EAAA;AACrE,EAAO,uBAAA,GAAA,CAAC,kBAAgB,QAAS,EAAA,CAAA;AACnC","file":"index.mjs","sourcesContent":["import { isValidElement, ReactNode } from \"react\";\n\nexport const reactNodeToString = (reactNode: ReactNode): string => {\n let string = \"\";\n if (typeof reactNode === \"string\") {\n string = reactNode;\n } else if (typeof reactNode === \"number\") {\n string = reactNode.toString();\n } else if (reactNode instanceof Array) {\n reactNode.forEach((child) => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n string += reactNodeToString(child);\n });\n } else if (isValidElement(reactNode)) {\n // @ts-expect-error is of type unknown\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n string += reactNodeToString(reactNode.props.children);\n }\n return string;\n};\n","import { FormField } from \"@sikt/sds-form\";\nimport { ExpandShowAltIcon } from \"@sikt/sds-icons\";\nimport { clsx } from \"clsx/lite\";\nimport { ReactNode, useId } from \"react\";\nimport {\n ComboBox as AriaCombobox,\n ComboBoxProps as AriaComboboxProps,\n Button,\n Header,\n Input,\n ListBox,\n ListBoxItem,\n ListBoxItemProps,\n ListBoxSection,\n Popover,\n PopoverProps,\n} from \"react-aria-components\";\nimport \"./combobox.pcss\";\nimport { reactNodeToString } from \"./reactNodeToString\";\n\ninterface ComboboxBaseProps<T extends object>\n extends Omit<\n AriaComboboxProps<T>,\n \"children\" | \"menuTrigger\" | \"aria-label\" | \"aria-labelledby\"\n > {\n children: ReactNode | ((item: T) => ReactNode);\n className?: string;\n errorText?: ReactNode;\n helpText?: ReactNode;\n menuTrigger?: \"focus\" | \"manual\" | \"input\";\n popoverProps?: PopoverProps;\n}\n\nexport type ComboboxProps<T extends object> = ComboboxBaseProps<T> &\n (\n | {\n label: NonNullable<ReactNode>;\n \"aria-labelledby\"?: never;\n }\n | {\n label?: never;\n \"aria-labelledby\": string;\n }\n );\n\nexport function Combobox<T extends object>({\n children,\n className,\n errorText,\n helpText,\n label,\n \"aria-labelledby\": ariaLabelledBy,\n menuTrigger = \"focus\",\n popoverProps,\n ...props\n}: ComboboxProps<T>) {\n const id = useId();\n const errorTextId = `${id}-error-text`;\n const helpTextId = `${id}-help-text`;\n\n const ariaLabel = reactNodeToString(label);\n const ariaDescribedBy =\n [errorText && errorTextId, helpText && helpTextId]\n .filter(Boolean)\n .join(\" \") || undefined;\n\n return (\n <FormField\n className={clsx(\n \"sds-combobox\",\n errorText && \"sds-combobox--invalid\",\n className,\n )}\n label={label}\n errorText={errorText}\n errorTextId={errorTextId}\n helpText={helpText}\n helpTextId={helpTextId}\n htmlFor={id}\n >\n <AriaCombobox\n menuTrigger={menuTrigger}\n id={id}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n {...props}\n >\n <div className=\"sds-combobox__combobox\">\n <Input\n className=\"sds-combobox__combobox-input\"\n aria-describedby={ariaDescribedBy}\n aria-invalid={Boolean(errorText)}\n aria-errormessage={errorText ? errorTextId : undefined}\n />\n <Button className=\"sds-combobox__combobox-button\">\n <ExpandShowAltIcon />\n </Button>\n </div>\n <Popover className=\"sds-combobox__popover\" {...popoverProps}>\n <ListBox className=\"sds-combobox__listbox\">{children}</ListBox>\n </Popover>\n </AriaCombobox>\n </FormField>\n );\n}\n\nexport function ComboboxItem({\n className,\n ...props\n}: ListBoxItemProps & { className?: string }) {\n return (\n <ListBoxItem className={clsx(\"sds-combobox__item\", className)} {...props} />\n );\n}\n\nexport function ComboboxHeader({ children }: { children: ReactNode }) {\n return <Header className=\"sds-combobox__header\">{children}</Header>;\n}\n\nexport function ComboboxSection({ children }: { children: ReactNode }) {\n return <ListBoxSection>{children}</ListBoxSection>;\n}\n"]}
1
+ {"version":3,"sources":["../../core/src/utils/reactNodeToString.ts","../src/Combobox.tsx"],"names":["AriaCombobox"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,IAAM,iBAAA,GAAoB,CAAC,SAAiC,KAAA;AACjE,EAAA,IAAI,MAAS,GAAA,EAAA;AACb,EAAI,IAAA,OAAO,cAAc,QAAU,EAAA;AACjC,IAAS,MAAA,GAAA,SAAA;AAAA,GACX,MAAA,IAAW,OAAO,SAAA,KAAc,QAAU,EAAA;AACxC,IAAA,MAAA,GAAS,UAAU,QAAS,EAAA;AAAA,GAC9B,MAAA,IAAW,qBAAqB,KAAO,EAAA;AACrC,IAAU,SAAA,CAAA,OAAA,CAAQ,CAAC,KAAU,KAAA;AAE3B,MAAA,MAAA,IAAU,kBAAkB,KAAK,CAAA;AAAA,KAClC,CAAA;AAAA,GACH,MAAA,IAAW,cAAe,CAAA,SAAS,CAAG,EAAA;AAGpC,IAAU,MAAA,IAAA,iBAAA,CAAkB,SAAU,CAAA,KAAA,CAAM,QAAQ,CAAA;AAAA;AAEtD,EAAO,OAAA,MAAA;AACT,CAAA;ACmCO,SAAS,SAA2B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AS,cAAA,CAAe,EAAE,QAAA,EAAqC,EAAA;AACpE,EAAA,uBAAQ,GAAA,CAAA,MAAA,EAAA,EAAO,SAAU,EAAA,sBAAA,EAAwB,QAAS,EAAA,CAAA;AAC5D;AACA,cAAA,CAAe,WAAc,GAAA,gBAAA;AAEtB,SAAS,eAAA,CAAgB,EAAE,QAAA,EAAqC,EAAA;AACrE,EAAO,uBAAA,GAAA,CAAC,kBAAgB,QAAS,EAAA,CAAA;AACnC;AACA,eAAA,CAAgB,WAAc,GAAA,iBAAA","file":"index.mjs","sourcesContent":["import { isValidElement, ReactNode } from \"react\";\n\nexport const reactNodeToString = (reactNode: ReactNode): string => {\n let string = \"\";\n if (typeof reactNode === \"string\") {\n string = reactNode;\n } else if (typeof reactNode === \"number\") {\n string = reactNode.toString();\n } else if (reactNode instanceof Array) {\n reactNode.forEach((child) => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n string += reactNodeToString(child);\n });\n } else if (isValidElement(reactNode)) {\n // @ts-expect-error is of type unknown\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n string += reactNodeToString(reactNode.props.children);\n }\n return string;\n};\n","import { FormField } from \"@sikt/sds-form\";\nimport { ExpandShowAltIcon } from \"@sikt/sds-icons\";\nimport { clsx } from \"clsx/lite\";\nimport { InputHTMLAttributes, ReactNode, useId } from \"react\";\nimport {\n ComboBox as AriaCombobox,\n ComboBoxProps as AriaComboboxProps,\n Button,\n Header,\n Input,\n ListBox,\n ListBoxItem,\n ListBoxItemProps,\n ListBoxSection,\n Popover,\n PopoverProps,\n} from \"react-aria-components\";\nimport \"./combobox.pcss\";\nimport { reactNodeToString } from \"../../core/src/utils/reactNodeToString\";\n\ninterface ComboboxBaseProps<T extends object> extends Omit<\n AriaComboboxProps<T>,\n \"children\" | \"menuTrigger\" | \"aria-label\" | \"aria-labelledby\"\n> {\n children: ReactNode | ((item: T) => ReactNode);\n className?: string;\n /**\n * Text to show when the input is invalid to help the user enter correct value. This also sets `aria-invalid` & `aria-errormessage`.\n */\n errorText?: ReactNode;\n /**\n * Text to show to help the user enter correct value. It's a better pattern to have enough information in the `label`.\n */\n helpText?: ReactNode;\n menuTrigger?: \"focus\" | \"manual\" | \"input\";\n popoverProps?: PopoverProps;\n inputProps?: InputHTMLAttributes<HTMLInputElement>;\n}\n\nexport type ComboboxProps<T extends object> = ComboboxBaseProps<T> &\n (\n | {\n label: NonNullable<ReactNode>;\n \"aria-labelledby\"?: never;\n }\n | {\n label?: never;\n /**\n * Id (or id's) that identifies the element (or elements) that labels the element it is applied to. For accessibility these should NOT be visually hidden.\n */\n \"aria-labelledby\": string;\n }\n );\n\nexport function Combobox<T extends object>({\n children,\n className,\n errorText,\n helpText,\n label,\n \"aria-labelledby\": ariaLabelledBy,\n menuTrigger = \"focus\",\n popoverProps,\n inputProps,\n ...props\n}: ComboboxProps<T>) {\n const id = useId();\n const errorTextId = `${id}-error-text`;\n const helpTextId = `${id}-help-text`;\n\n const ariaLabel = reactNodeToString(label);\n const ariaDescribedBy =\n [errorText && errorTextId, helpText && helpTextId]\n .filter(Boolean)\n .join(\" \") || undefined;\n\n return (\n <FormField\n className={clsx(\n \"sds-combobox\",\n errorText && \"sds-combobox--invalid\",\n className,\n )}\n label={label}\n errorText={errorText}\n errorTextId={errorTextId}\n helpText={helpText}\n helpTextId={helpTextId}\n htmlFor={id}\n >\n <AriaCombobox\n menuTrigger={menuTrigger}\n id={id}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n {...props}\n >\n <div className=\"sds-combobox__combobox\">\n <Input\n className=\"sds-combobox__combobox-input\"\n aria-describedby={ariaDescribedBy}\n aria-invalid={Boolean(errorText)}\n aria-errormessage={errorText ? errorTextId : undefined}\n {...inputProps}\n />\n <Button className=\"sds-combobox__combobox-button\">\n <ExpandShowAltIcon />\n </Button>\n </div>\n <Popover className=\"sds-combobox__popover\" {...popoverProps}>\n <ListBox className=\"sds-combobox__listbox\">{children}</ListBox>\n </Popover>\n </AriaCombobox>\n </FormField>\n );\n}\nCombobox.displayName = \"Combobox\";\n\nexport function ComboboxItem({\n className,\n ...props\n}: ListBoxItemProps & { className?: string }) {\n return (\n <ListBoxItem className={clsx(\"sds-combobox__item\", className)} {...props} />\n );\n}\nComboboxItem.displayName = \"ComboboxItem\";\n\nexport function ComboboxHeader({ children }: { children: ReactNode }) {\n return <Header className=\"sds-combobox__header\">{children}</Header>;\n}\nComboboxHeader.displayName = \"ComboboxHeader\";\n\nexport function ComboboxSection({ children }: { children: ReactNode }) {\n return <ListBoxSection>{children}</ListBoxSection>;\n}\nComboboxSection.displayName = \"ComboboxSection\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sikt/sds-combobox",
3
- "version": "3.2.1",
3
+ "version": "3.3.0",
4
4
  "license": "UNLICENSED",
5
5
  "homepage": "https://designsystem.sikt.no/",
6
6
  "repository": {
@@ -37,7 +37,7 @@
37
37
  "@sikt/sds-core": "^4.6.0",
38
38
  "@sikt/sds-form": "^4.1.0",
39
39
  "@sikt/sds-icons": "^3.0.0",
40
- "react-aria-components": "^1.12.2"
40
+ "react-aria-components": "^1.14.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@types/react": "^18.0.0 || ^19.0.0",