@deque/cauldron-react 5.9.1-canary.db304969 → 5.10.0-canary.3e283f97

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.
@@ -7,6 +7,7 @@ interface ComboboxOption {
7
7
  key?: string;
8
8
  label: string;
9
9
  value?: ComboboxValue;
10
+ formValue?: ComboboxValue;
10
11
  description?: string;
11
12
  }
12
13
  interface ComboboxProps extends React.InputHTMLAttributes<Omit<HTMLInputElement, 'value' | 'defaultValue'>> {
@@ -3,9 +3,11 @@ import { ComboboxValue } from './ComboboxOption';
3
3
  type ComboboxContext = {
4
4
  autocomplete: 'none' | 'manual' | 'automatic';
5
5
  inputValue: ComboboxValue;
6
+ formValue: ComboboxValue;
6
7
  selectedValue: ComboboxValue;
7
8
  matchingOptions: Map<HTMLElement, ComboboxOptionState>;
8
9
  setMatchingOptions: React.Dispatch<React.SetStateAction<Map<HTMLElement, ComboboxOptionState>>>;
10
+ setFormValue: React.Dispatch<React.SetStateAction<ComboboxValue>>;
9
11
  matches: (<T extends string = string>(value: T) => boolean) | boolean;
10
12
  };
11
13
  export type ComboboxOptionState = {
@@ -17,6 +19,6 @@ type ComboboxProvider = {
17
19
  matches: ((inputValue: string, value: string) => boolean) | boolean;
18
20
  } & Omit<ComboboxContext, 'matches'>;
19
21
  declare const ComboboxContext: React.Context<ComboboxContext>;
20
- declare function ComboboxProvider({ autocomplete, inputValue, selectedValue, matches, matchingOptions, setMatchingOptions, children }: ComboboxProvider): JSX.Element;
22
+ declare function ComboboxProvider({ autocomplete, inputValue, formValue, selectedValue, matches, matchingOptions, setMatchingOptions, setFormValue, children }: ComboboxProvider): JSX.Element;
21
23
  declare function useComboboxContext(): ComboboxContext;
22
24
  export { ComboboxProvider, useComboboxContext };
@@ -5,6 +5,7 @@ export type ComboboxValue = Exclude<ListboxValue, number>;
5
5
  interface ComboboxOptionProps extends React.HTMLAttributes<HTMLLIElement> {
6
6
  disabled?: boolean;
7
7
  value?: ComboboxValue;
8
+ formValue?: ComboboxValue;
8
9
  description?: ContentNode;
9
10
  children: string;
10
11
  }
package/lib/index.js CHANGED
@@ -4188,30 +4188,36 @@ ListboxGroup.displayName = 'ListboxGroup';
4188
4188
  var ComboboxContext = React.createContext({
4189
4189
  autocomplete: 'manual',
4190
4190
  inputValue: undefined,
4191
+ formValue: undefined,
4191
4192
  selectedValue: undefined,
4192
4193
  matches: true,
4193
4194
  matchingOptions: new Map(),
4194
- setMatchingOptions: function () { return null; }
4195
+ setMatchingOptions: function () { return null; },
4196
+ setFormValue: function () { return null; }
4195
4197
  });
4196
4198
  function ComboboxProvider(_a) {
4197
- var autocomplete = _a.autocomplete, inputValue = _a.inputValue, selectedValue = _a.selectedValue, matches = _a.matches, matchingOptions = _a.matchingOptions, setMatchingOptions = _a.setMatchingOptions, children = _a.children;
4199
+ var autocomplete = _a.autocomplete, inputValue = _a.inputValue, formValue = _a.formValue, selectedValue = _a.selectedValue, matches = _a.matches, matchingOptions = _a.matchingOptions, setMatchingOptions = _a.setMatchingOptions, setFormValue = _a.setFormValue, children = _a.children;
4198
4200
  var Provider = ComboboxContext.Provider;
4199
4201
  var contextValue = React.useMemo(function () { return ({
4200
4202
  autocomplete: autocomplete,
4201
4203
  inputValue: inputValue,
4204
+ formValue: formValue,
4202
4205
  selectedValue: selectedValue,
4203
4206
  matches: typeof matches === 'function' && !!inputValue
4204
4207
  ? function (value) { return matches(inputValue, value); }
4205
4208
  : true,
4206
4209
  matchingOptions: matchingOptions,
4207
- setMatchingOptions: setMatchingOptions
4210
+ setMatchingOptions: setMatchingOptions,
4211
+ setFormValue: setFormValue
4208
4212
  }); }, [
4209
4213
  autocomplete,
4210
4214
  inputValue,
4215
+ formValue,
4211
4216
  selectedValue,
4212
4217
  matches,
4213
4218
  matchingOptions,
4214
- setMatchingOptions
4219
+ setMatchingOptions,
4220
+ setFormValue
4215
4221
  ]);
4216
4222
  return React__default["default"].createElement(Provider, { value: contextValue }, children);
4217
4223
  }
@@ -4284,10 +4290,10 @@ var ComboboxMatch = function (_a) {
4284
4290
  React__default["default"].createElement("span", null, matchAfter)));
4285
4291
  };
4286
4292
  var ComboboxOption = React.forwardRef(function (_a, ref) {
4287
- var className = _a.className, children = _a.children, disabled = _a.disabled, propId = _a.id, description = _a.description, propValue = _a.value, props = tslib.__rest(_a, ["className", "children", "disabled", "id", "description", "value"]);
4293
+ var className = _a.className, children = _a.children, disabled = _a.disabled, propId = _a.id, description = _a.description, propValue = _a.value, formValue = _a.formValue, props = tslib.__rest(_a, ["className", "children", "disabled", "id", "description", "value", "formValue"]);
4288
4294
  var _b = tslib.__read(propId ? [propId] : nextId.useId(1, 'combobox-option'), 1), id = _b[0];
4289
4295
  var _c = useListboxContext(), selected = _c.selected, active = _c.active;
4290
- var _d = useComboboxContext(), matches = _d.matches, setMatchingOptions = _d.setMatchingOptions;
4296
+ var _d = useComboboxContext(), selectedValue = _d.selectedValue, matches = _d.matches, setMatchingOptions = _d.setMatchingOptions, setFormValue = _d.setFormValue;
4291
4297
  var comboboxOptionRef = useSharedRef(ref);
4292
4298
  var intersectionRef = useIntersectionRef(comboboxOptionRef, {
4293
4299
  root: null,
@@ -4315,6 +4321,15 @@ var ComboboxOption = React.forwardRef(function (_a, ref) {
4315
4321
  });
4316
4322
  }
4317
4323
  }, [isActive]);
4324
+ React.useEffect(function () {
4325
+ var _a;
4326
+ var comboboxValue = typeof propValue !== 'undefined'
4327
+ ? propValue
4328
+ : (_a = comboboxOptionRef.current) === null || _a === void 0 ? void 0 : _a.innerText;
4329
+ if (selectedValue === comboboxValue) {
4330
+ setFormValue(typeof formValue === 'undefined' ? comboboxValue : formValue);
4331
+ }
4332
+ }, [selectedValue, formValue]);
4318
4333
  React.useEffect(function () {
4319
4334
  if (isMatching) {
4320
4335
  setMatchingOptions(function (options) {
@@ -4363,13 +4378,14 @@ var ComboboxNoResults = function (_a) {
4363
4378
  return (React__default["default"].createElement("div", { className: "ComboboxListbox__empty", role: "alert", "aria-live": "polite" }, children || 'No results found.'));
4364
4379
  };
4365
4380
  var Combobox = React.forwardRef(function (_a, ref) {
4366
- var propId = _a.id, className = _a.className, label = _a.label, children = _a.children, _b = _a.options, options = _b === void 0 ? [] : _b, propValue = _a.value, defaultValue = _a.defaultValue, _c = _a.requiredText, requiredText = _c === void 0 ? 'Required' : _c, error = _a.error, _d = _a.autocomplete, autocomplete = _d === void 0 ? 'manual' : _d, onSelectionChange = _a.onSelectionChange, onActiveChange = _a.onActiveChange, onChange = _a.onChange, onKeyDown = _a.onKeyDown, onFocus = _a.onFocus, onBlur = _a.onBlur, renderNoResults = _a.renderNoResults, portal = _a.portal, props = tslib.__rest(_a, ["id", "className", "label", "children", "options", "value", "defaultValue", "requiredText", "error", "autocomplete", "onSelectionChange", "onActiveChange", "onChange", "onKeyDown", "onFocus", "onBlur", "renderNoResults", "portal"]);
4381
+ var propId = _a.id, className = _a.className, label = _a.label, children = _a.children, _b = _a.options, options = _b === void 0 ? [] : _b, propValue = _a.value, defaultValue = _a.defaultValue, _c = _a.requiredText, requiredText = _c === void 0 ? 'Required' : _c, error = _a.error, _d = _a.autocomplete, autocomplete = _d === void 0 ? 'manual' : _d, onSelectionChange = _a.onSelectionChange, onActiveChange = _a.onActiveChange, onChange = _a.onChange, onKeyDown = _a.onKeyDown, onFocus = _a.onFocus, onBlur = _a.onBlur, name = _a.name, renderNoResults = _a.renderNoResults, portal = _a.portal, props = tslib.__rest(_a, ["id", "className", "label", "children", "options", "value", "defaultValue", "requiredText", "error", "autocomplete", "onSelectionChange", "onActiveChange", "onChange", "onKeyDown", "onFocus", "onBlur", "name", "renderNoResults", "portal"]);
4367
4382
  var _e = tslib.__read(React.useState(defaultValue || propValue || ''), 2), value = _e[0], setValue = _e[1];
4368
4383
  var _f = tslib.__read(React.useState(new Map()), 2), matchingOptions = _f[0], setMatchingOptions = _f[1];
4369
4384
  var _g = tslib.__read(React.useState(value || ''), 2), selectedValue = _g[0], setSelectedValue = _g[1];
4370
- var _h = tslib.__read(React.useState(false), 2), open = _h[0], setOpen = _h[1];
4371
- var _j = tslib.__read(React.useState(null), 2), activeDescendant = _j[0], setActiveDescendant = _j[1];
4372
- var _k = tslib.__read(propId ? [propId] : nextId.useId(1, 'combobox'), 1), id = _k[0];
4385
+ var _h = tslib.__read(React.useState(''), 2), formValue = _h[0], setFormValue = _h[1];
4386
+ var _j = tslib.__read(React.useState(false), 2), open = _j[0], setOpen = _j[1];
4387
+ var _k = tslib.__read(React.useState(null), 2), activeDescendant = _k[0], setActiveDescendant = _k[1];
4388
+ var _l = tslib.__read(propId ? [propId] : nextId.useId(1, 'combobox'), 1), id = _l[0];
4373
4389
  var comboboxRef = useSharedRef(ref);
4374
4390
  var inputRef = React.useRef(null);
4375
4391
  var listboxRef = React.useRef(null);
@@ -4398,7 +4414,7 @@ var Combobox = React.forwardRef(function (_a, ref) {
4398
4414
  setActiveDescendant(null);
4399
4415
  }
4400
4416
  if (open && autocomplete === 'automatic' && !selectedValue) {
4401
- // Fire an Home keydown event on listbox to ensure the first item is selected
4417
+ // Fire a Home keydown event on listbox to ensure the first item is selected
4402
4418
  triggerListboxKeyDown(Home);
4403
4419
  }
4404
4420
  }, [open]);
@@ -4539,10 +4555,11 @@ var Combobox = React.forwardRef(function (_a, ref) {
4539
4555
  var noMatchingOptions = !!(value === null || value === void 0 ? void 0 : value.length) && !matchingOptions.size && (React__default["default"].createElement(NoMatchingOptions, null));
4540
4556
  var comboboxListbox = (React__default["default"].createElement(Listbox, { className: classNames__default["default"]('Combobox__listbox', {
4541
4557
  'Combobox__listbox--open': open
4542
- }), role: "listbox", "aria-labelledby": "".concat(id, "-label"), id: "".concat(id, "-listbox"), value: selectedValue, onMouseDown: handleComboboxOptionMouseDown, onClick: handleComboboxOptionClick, onSelectionChange: handleSelectionChange, onActiveChange: handleActiveChange, ref: listboxRef, tabIndex: undefined, "aria-activedescendant": "" },
4558
+ }), role: "listbox", "aria-labelledby": "".concat(id, "-label"), id: "".concat(id, "-listbox"), value: selectedValue, onMouseDown: handleComboboxOptionMouseDown, onClick: handleComboboxOptionClick, onSelectionChange: handleSelectionChange, onActiveChange: handleActiveChange, ref: listboxRef, tabIndex: undefined, "aria-activedescendant": undefined },
4543
4559
  comboboxOptions,
4544
4560
  noMatchingOptions));
4545
4561
  return (React__default["default"].createElement("div", { id: id, className: classNames__default["default"]('Combobox', className), ref: comboboxRef },
4562
+ name && React__default["default"].createElement("input", { type: "hidden", name: name, value: formValue }),
4546
4563
  React__default["default"].createElement("label", { className: classNames__default["default"]('Field__label', {
4547
4564
  'Field__label--is-required': isRequired,
4548
4565
  'Field__label--has-error': hasError
@@ -4557,7 +4574,7 @@ var Combobox = React.forwardRef(function (_a, ref) {
4557
4574
  onClick: handleInputClick },
4558
4575
  React__default["default"].createElement("input", tslib.__assign({ type: "text", id: "".concat(id, "-input"), ref: inputRef, value: value, role: "combobox", "aria-autocomplete": !isAutoComplete ? 'none' : 'list', "aria-controls": "".concat(id, "-listbox"), "aria-expanded": open, "aria-haspopup": "listbox", "aria-activedescendant": open && activeDescendant ? activeDescendant.element.id : undefined }, props, { onChange: handleChange, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: handleBlur })),
4559
4576
  React__default["default"].createElement("span", { className: "Combobox__arrow" })),
4560
- React__default["default"].createElement(ComboboxProvider, { autocomplete: autocomplete, inputValue: value, selectedValue: selectedValue, matches: !isAutoComplete || defaultAutoCompleteMatches, matchingOptions: matchingOptions, setMatchingOptions: setMatchingOptions }, portal
4577
+ React__default["default"].createElement(ComboboxProvider, { autocomplete: autocomplete, inputValue: value, formValue: formValue, selectedValue: selectedValue, matches: !isAutoComplete || defaultAutoCompleteMatches, matchingOptions: matchingOptions, setMatchingOptions: setMatchingOptions, setFormValue: setFormValue }, portal
4561
4578
  ? reactDom.createPortal(comboboxListbox, portal instanceof HTMLElement
4562
4579
  ? portal
4563
4580
  : portal.current ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deque/cauldron-react",
3
- "version": "5.9.1-canary.db304969",
3
+ "version": "5.10.0-canary.3e283f97",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Fully accessible react components library for Deque Cauldron",
6
6
  "homepage": "https://cauldron.dequelabs.com/",