@cboxdk/cbox-ui 0.15.5 → 0.15.6

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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
- import { ReactNode, ComponentType, FormEvent, AnchorHTMLAttributes, ComponentProps, ButtonHTMLAttributes, InputHTMLAttributes, TextareaHTMLAttributes } from 'react';
3
+ import { ReactNode, ComponentType, FormEvent, AnchorHTMLAttributes, ComponentProps, AriaAttributes, ButtonHTMLAttributes, InputHTMLAttributes, TextareaHTMLAttributes } from 'react';
4
4
  import { C as CboxThemeMode, a as CboxKnownApp } from './catalog-BroZWvws.js';
5
5
  export { b as CboxAppCatalogState, c as CboxCatalogApp, d as authorizeHref, p as parseAppCatalog, r as readKnownAppCatalog, e as rememberAppCatalog, s as secureIconUrl, f as signInTarget } from './catalog-BroZWvws.js';
6
6
  import { LucideIcon } from 'lucide-react';
@@ -1119,7 +1119,7 @@ type LinkComp = ComponentType<{
1119
1119
  className?: string;
1120
1120
  children: ReactNode;
1121
1121
  }>;
1122
- type CommonProps = {
1122
+ type CommonProps = Pick<AriaAttributes, 'aria-describedby' | 'aria-invalid'> & {
1123
1123
  /** Options or grouped options. Pass an array of either shape. */
1124
1124
  items: ComboboxOption[] | ComboboxGroup[];
1125
1125
  /** Placeholder shown in the trigger when no value is selected. */
package/dist/index.js CHANGED
@@ -4920,8 +4920,52 @@ function CboxAppCatalog({ endpoint, currentAppKey, theme, className }) {
4920
4920
  className
4921
4921
  });
4922
4922
  }
4923
+ var FieldContext = createContext(null);
4924
+ function useFieldControl() {
4925
+ const field = useContext(FieldContext);
4926
+ if (field === null) return {};
4927
+ return {
4928
+ id: field.controlId,
4929
+ ...field.describedBy !== void 0 ? { "aria-describedby": field.describedBy } : {},
4930
+ ...field.invalid ? { "aria-invalid": true } : {},
4931
+ ...field.required ? { required: true } : {}
4932
+ };
4933
+ }
4934
+ function Field({ label, id: statedId, labelAction, hint, error, required = false, optional = false, className, children }) {
4935
+ const { t } = useCboxLocalization();
4936
+ const generated = useId();
4937
+ const base = statedId ?? generated;
4938
+ const controlId = statedId ?? `${generated}-control`;
4939
+ const hintId = `${base}-hint`;
4940
+ const errorId = `${base}-error`;
4941
+ const hasError = error !== void 0 && error !== null && error !== "";
4942
+ const describedBy = [hint !== void 0 ? hintId : null, hasError ? errorId : null].filter(Boolean).join(" ") || void 0;
4943
+ const context = useMemo(() => ({ controlId, describedBy, invalid: hasError, required }), [controlId, describedBy, hasError, required]);
4944
+ const labelElement = /* @__PURE__ */ jsxs("label", { className: "cbx-ui-label", htmlFor: controlId, children: [
4945
+ label,
4946
+ required && /* @__PURE__ */ jsxs(Fragment, { children: [
4947
+ " ",
4948
+ /* @__PURE__ */ jsx("span", { className: "cbx-ui-label-required", "aria-hidden": "true", children: "*" }),
4949
+ /* @__PURE__ */ jsx("span", { className: "cbx-ui-sr-only", children: t("(required)") })
4950
+ ] }),
4951
+ optional && /* @__PURE__ */ jsxs(Fragment, { children: [
4952
+ " ",
4953
+ /* @__PURE__ */ jsx("span", { className: "cbx-ui-label-optional", children: t("(optional)") })
4954
+ ] })
4955
+ ] });
4956
+ return /* @__PURE__ */ jsx(FieldContext.Provider, { value: context, children: /* @__PURE__ */ jsxs("div", { className: cn("cbx-ui-field", className), children: [
4957
+ labelAction !== void 0 ? /* @__PURE__ */ jsxs("div", { className: "cbx-ui-field-head", children: [
4958
+ labelElement,
4959
+ labelAction
4960
+ ] }) : labelElement,
4961
+ children,
4962
+ hint !== void 0 && /* @__PURE__ */ jsx("p", { id: hintId, className: "cbx-ui-hint", children: hint }),
4963
+ /* @__PURE__ */ jsx("p", { id: errorId, className: "cbx-ui-error", role: "alert", hidden: !hasError, children: hasError ? error : null })
4964
+ ] }) });
4965
+ }
4923
4966
  function Combobox(props) {
4924
4967
  const { t } = useCboxLocalization();
4968
+ const field = useFieldControl();
4925
4969
  const {
4926
4970
  items,
4927
4971
  placeholder = t("Select\u2026"),
@@ -4929,7 +4973,7 @@ function Combobox(props) {
4929
4973
  emptyText = t("Nothing matches."),
4930
4974
  footerLink,
4931
4975
  disabled = false,
4932
- required = false,
4976
+ required = field.required ?? false,
4933
4977
  ariaLabel,
4934
4978
  triggerClassName,
4935
4979
  panelClassName,
@@ -4952,10 +4996,11 @@ function Combobox(props) {
4952
4996
  const [query2, setQuery] = useState("");
4953
4997
  const [highlightIndex, setHighlightIndex] = useState(-1);
4954
4998
  const containerRef = useRef(null);
4999
+ const triggerRef = useRef(null);
4955
5000
  const inputRef = useRef(null);
4956
5001
  const listRef = useRef(null);
4957
5002
  const reactId = useId();
4958
- const id = idProp ?? reactId;
5003
+ const id = idProp ?? field.id ?? reactId;
4959
5004
  const listId = `${id}-listbox`;
4960
5005
  const filteredGroups = useMemo(
4961
5006
  () => filterGroups(groups, query2),
@@ -4998,6 +5043,7 @@ function Combobox(props) {
4998
5043
  return;
4999
5044
  }
5000
5045
  if (props.onChange !== void 0) {
5046
+ triggerRef.current?.focus();
5001
5047
  props.onChange(opt.value);
5002
5048
  }
5003
5049
  setOpen(false);
@@ -5049,11 +5095,6 @@ function Combobox(props) {
5049
5095
  }
5050
5096
  return;
5051
5097
  }
5052
- if (event.key === "Escape") {
5053
- event.preventDefault();
5054
- setOpen(false);
5055
- return;
5056
- }
5057
5098
  if (event.key === "Tab") {
5058
5099
  setOpen(false);
5059
5100
  return;
@@ -5066,10 +5107,19 @@ function Combobox(props) {
5066
5107
  {
5067
5108
  ref: containerRef,
5068
5109
  className: cn("relative", triggerWidth === "full" && "w-full", className),
5110
+ onKeyDown: (event) => {
5111
+ if (open && event.key === "Escape") {
5112
+ event.preventDefault();
5113
+ event.stopPropagation();
5114
+ setOpen(false);
5115
+ triggerRef.current?.focus();
5116
+ }
5117
+ },
5069
5118
  children: [
5070
5119
  /* @__PURE__ */ jsxs(
5071
5120
  "button",
5072
5121
  {
5122
+ ref: triggerRef,
5073
5123
  id,
5074
5124
  type: "button",
5075
5125
  role: "combobox",
@@ -5079,6 +5129,8 @@ function Combobox(props) {
5079
5129
  "aria-controls": listId,
5080
5130
  "aria-required": required,
5081
5131
  "aria-label": ariaLabel,
5132
+ "aria-describedby": props["aria-describedby"] ?? field["aria-describedby"],
5133
+ "aria-invalid": props["aria-invalid"] ?? field["aria-invalid"],
5082
5134
  onClick: () => setOpen((v) => !v),
5083
5135
  className: cn(
5084
5136
  "flex h-9 items-center gap-2 rounded-md border border-input bg-card px-3 text-left text-[13px] text-foreground transition-colors",
@@ -5827,49 +5879,6 @@ function Checkbox({ checked, onCheckedChange, label, hint, disabled = false, req
5827
5879
  ] })
5828
5880
  ] });
5829
5881
  }
5830
- var FieldContext = createContext(null);
5831
- function useFieldControl() {
5832
- const field = useContext(FieldContext);
5833
- if (field === null) return {};
5834
- return {
5835
- id: field.controlId,
5836
- ...field.describedBy !== void 0 ? { "aria-describedby": field.describedBy } : {},
5837
- ...field.invalid ? { "aria-invalid": true } : {},
5838
- ...field.required ? { required: true } : {}
5839
- };
5840
- }
5841
- function Field({ label, id: statedId, labelAction, hint, error, required = false, optional = false, className, children }) {
5842
- const { t } = useCboxLocalization();
5843
- const generated = useId();
5844
- const base = statedId ?? generated;
5845
- const controlId = statedId ?? `${generated}-control`;
5846
- const hintId = `${base}-hint`;
5847
- const errorId = `${base}-error`;
5848
- const hasError = error !== void 0 && error !== null && error !== "";
5849
- const describedBy = [hint !== void 0 ? hintId : null, hasError ? errorId : null].filter(Boolean).join(" ") || void 0;
5850
- const context = useMemo(() => ({ controlId, describedBy, invalid: hasError, required }), [controlId, describedBy, hasError, required]);
5851
- const labelElement = /* @__PURE__ */ jsxs("label", { className: "cbx-ui-label", htmlFor: controlId, children: [
5852
- label,
5853
- required && /* @__PURE__ */ jsxs(Fragment, { children: [
5854
- " ",
5855
- /* @__PURE__ */ jsx("span", { className: "cbx-ui-label-required", "aria-hidden": "true", children: "*" }),
5856
- /* @__PURE__ */ jsx("span", { className: "cbx-ui-sr-only", children: t("(required)") })
5857
- ] }),
5858
- optional && /* @__PURE__ */ jsxs(Fragment, { children: [
5859
- " ",
5860
- /* @__PURE__ */ jsx("span", { className: "cbx-ui-label-optional", children: t("(optional)") })
5861
- ] })
5862
- ] });
5863
- return /* @__PURE__ */ jsx(FieldContext.Provider, { value: context, children: /* @__PURE__ */ jsxs("div", { className: cn("cbx-ui-field", className), children: [
5864
- labelAction !== void 0 ? /* @__PURE__ */ jsxs("div", { className: "cbx-ui-field-head", children: [
5865
- labelElement,
5866
- labelAction
5867
- ] }) : labelElement,
5868
- children,
5869
- hint !== void 0 && /* @__PURE__ */ jsx("p", { id: hintId, className: "cbx-ui-hint", children: hint }),
5870
- /* @__PURE__ */ jsx("p", { id: errorId, className: "cbx-ui-error", role: "alert", hidden: !hasError, children: hasError ? error : null })
5871
- ] }) });
5872
- }
5873
5882
  var Input = forwardRef(function Input2({ scale = "md", className, ...props }, ref) {
5874
5883
  const field = useFieldControl();
5875
5884
  return /* @__PURE__ */ jsx("input", { ref, className: cn("cbx-ui-input", scale === "lg" && "cbx-ui-input--lg", className), ...field, ...props });