@deque/cauldron-react 6.20.2-canary.e9a0c04b → 6.20.2-canary.fdaa9831

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.
@@ -21,6 +21,7 @@ interface BaseComboboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElem
21
21
  renderNoResults?: (() => React.JSX.Element) | React.ReactElement;
22
22
  portal?: React.RefObject<HTMLElement> | HTMLElement;
23
23
  inputRef?: React.Ref<HTMLInputElement>;
24
+ description?: React.ReactNode;
24
25
  }
25
26
  interface SingleSelectComboboxProps extends BaseComboboxProps {
26
27
  value?: ComboboxValue;
package/lib/index.js CHANGED
@@ -4158,7 +4158,7 @@ var ComboboxNoResults = function (_a) {
4158
4158
  return (React__default["default"].createElement("div", { className: "ComboboxListbox__empty", role: "alert", "aria-live": "polite" }, children || 'No results found.'));
4159
4159
  };
4160
4160
  var Combobox = React.forwardRef(function (_a, ref) {
4161
- 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, propInputValue = _a.inputValue, defaultInputValue = _a.defaultInputValue, _c = _a.multiselect, multiselect = _c === void 0 ? false : _c, _d = _a.requiredText, requiredText = _d === void 0 ? 'Required' : _d, error = _a.error, _e = _a.autocomplete, autocomplete = _e === void 0 ? 'manual' : _e, 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, _f = _a.inputRef, propInputRef = _f === void 0 ? null : _f, ariaDescribedby = _a["aria-describedby"], _g = _a.disabled, disabled = _g === void 0 ? false : _g, props = tslib.__rest(_a, ["id", "className", "label", "children", "options", "value", "defaultValue", "inputValue", "defaultInputValue", "multiselect", "requiredText", "error", "autocomplete", "onSelectionChange", "onActiveChange", "onChange", "onKeyDown", "onFocus", "onBlur", "name", "renderNoResults", "portal", "inputRef", 'aria-describedby', "disabled"]);
4161
+ 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, propInputValue = _a.inputValue, defaultInputValue = _a.defaultInputValue, _c = _a.multiselect, multiselect = _c === void 0 ? false : _c, _d = _a.requiredText, requiredText = _d === void 0 ? 'Required' : _d, error = _a.error, _e = _a.autocomplete, autocomplete = _e === void 0 ? 'manual' : _e, 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, _f = _a.inputRef, propInputRef = _f === void 0 ? null : _f, description = _a.description, ariaDescribedby = _a["aria-describedby"], _g = _a.disabled, disabled = _g === void 0 ? false : _g, props = tslib.__rest(_a, ["id", "className", "label", "children", "options", "value", "defaultValue", "inputValue", "defaultInputValue", "multiselect", "requiredText", "error", "autocomplete", "onSelectionChange", "onActiveChange", "onChange", "onKeyDown", "onFocus", "onBlur", "name", "renderNoResults", "portal", "inputRef", "description", 'aria-describedby', "disabled"]);
4162
4162
  var _h = tslib.__read(React.useState(new Map()), 2), matchingOptions = _h[0], setMatchingOptions = _h[1];
4163
4163
  var _j = tslib.__read(React.useState(function () {
4164
4164
  var value = defaultValue || propValue;
@@ -4502,9 +4502,15 @@ var Combobox = React.forwardRef(function (_a, ref) {
4502
4502
  comboboxOptions,
4503
4503
  noMatchingOptions));
4504
4504
  var errorId = "".concat(id, "-error");
4505
- var inputProps = tslib.__assign(tslib.__assign({}, props), { 'aria-describedby': error
4506
- ? addIdRef(ariaDescribedby, errorId)
4507
- : ariaDescribedby });
4505
+ var descriptionId = "".concat(id, "-description");
4506
+ var describedby = ariaDescribedby;
4507
+ if (description) {
4508
+ describedby = addIdRef(describedby, descriptionId);
4509
+ }
4510
+ if (error) {
4511
+ describedby = addIdRef(describedby, errorId);
4512
+ }
4513
+ var inputProps = tslib.__assign(tslib.__assign({}, props), { 'aria-describedby': describedby });
4508
4514
  return (React__default["default"].createElement("div", { id: id, className: classNames__default["default"]('Combobox', { 'Combobox--multiselect': multiselect }, className), ref: comboboxRef },
4509
4515
  name &&
4510
4516
  formValues.map(function (formValue, index) { return (React__default["default"].createElement("input", { type: "hidden", key: index, name: name, value: formValue })); }),
@@ -4514,6 +4520,10 @@ var Combobox = React.forwardRef(function (_a, ref) {
4514
4520
  }), id: "".concat(id, "-label"), htmlFor: "".concat(id, "-input") },
4515
4521
  React__default["default"].createElement("span", null, label),
4516
4522
  isRequired && (React__default["default"].createElement("span", { className: "Field__required-text", "aria-hidden": "true" }, requiredText))),
4523
+ description && (React__default["default"].createElement("span", { className: "Field__description", id: descriptionId }, description)),
4524
+ hasError && (React__default["default"].createElement("div", { className: "Field__error", id: errorId },
4525
+ React__default["default"].createElement(Icon, { type: "caution" }),
4526
+ error)),
4517
4527
  React__default["default"].createElement(TextFieldWrapper, { className: classNames__default["default"]({ 'TextFieldWrapper--error': hasError }),
4518
4528
  // We're handling click here to open the listbox when the wrapping element is clicked,
4519
4529
  // there's already keyboard handlers to open the listbox on the input element
@@ -4543,8 +4553,7 @@ var Combobox = React.forwardRef(function (_a, ref) {
4543
4553
  : portal.current ||
4544
4554
  // eslint-disable-next-line ssr-friendly/no-dom-globals-in-react-fc
4545
4555
  /* istanbul ignore next: default fallback value */ document.body)
4546
- : comboboxListbox),
4547
- hasError && (React__default["default"].createElement("div", { className: "Error", id: errorId }, error))));
4556
+ : comboboxListbox)));
4548
4557
  });
4549
4558
  Combobox.displayName = 'Combobox';
4550
4559
 
@@ -4623,25 +4632,25 @@ var Popover = React.forwardRef(function (_a, ref) {
4623
4632
  targetElement === null || targetElement === void 0 ? void 0 : targetElement.setAttribute('aria-haspopup', 'true');
4624
4633
  }
4625
4634
  }, [targetElement, id, show]);
4626
- var handleClickOutside = function (e) {
4635
+ var handleClosePopover = function () {
4636
+ isolator === null || isolator === void 0 ? void 0 : isolator.deactivate();
4637
+ if (show) {
4638
+ onClose();
4639
+ }
4640
+ };
4641
+ var handleClickOutside = React.useCallback(function (e) {
4627
4642
  if (e.target === targetElement) {
4628
4643
  return;
4629
4644
  }
4630
4645
  if (show) {
4631
4646
  handleClosePopover();
4632
4647
  }
4633
- };
4648
+ }, [show, targetElement, handleClosePopover]);
4634
4649
  var attachIsolator = function () {
4635
4650
  if (popoverRef === null || popoverRef === void 0 ? void 0 : popoverRef.current) {
4636
4651
  setIsolator(new AriaIsolate(popoverRef === null || popoverRef === void 0 ? void 0 : popoverRef.current));
4637
4652
  }
4638
4653
  };
4639
- var handleClosePopover = function () {
4640
- isolator === null || isolator === void 0 ? void 0 : isolator.deactivate();
4641
- if (show) {
4642
- onClose();
4643
- }
4644
- };
4645
4654
  useEscapeKey({
4646
4655
  callback: handleClosePopover,
4647
4656
  active: show
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deque/cauldron-react",
3
- "version": "6.20.2-canary.e9a0c04b",
3
+ "version": "6.20.2-canary.fdaa9831",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Fully accessible react components library for Deque Cauldron",
6
6
  "homepage": "https://cauldron.dequelabs.com/",