@deque/cauldron-react 6.2.1-canary.6af58613 → 6.2.1-canary.6d2d22b3

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 SearchFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, '
7
7
  onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;
8
8
  hideLabel?: boolean;
9
9
  isForm?: boolean;
10
+ trailingChildren?: React.ReactNode;
10
11
  }
11
12
  declare const SearchField: React.ForwardRefExoticComponent<SearchFieldProps & React.RefAttributes<HTMLInputElement>>;
12
13
  export default SearchField;
package/lib/index.js CHANGED
@@ -1601,6 +1601,43 @@ var Button = React.forwardRef(function (_a, ref) {
1601
1601
  });
1602
1602
  Button.displayName = 'Button';
1603
1603
 
1604
+ /**
1605
+ * Returns a unique set of id refs from the provided string
1606
+ * @param ids - string of id refs
1607
+ */
1608
+ function idRefs(ids) {
1609
+ if (!ids || !ids.trim()) {
1610
+ return new Set();
1611
+ }
1612
+ return new Set(ids.trim().split(/\s+/));
1613
+ }
1614
+ /**
1615
+ * Returns an updated id ref string with the provided id value added
1616
+ * @param ids - string of id refs
1617
+ * @param id - id to add
1618
+ */
1619
+ function addIdRef(ids, id) {
1620
+ return tslib.__spreadArray([], tslib.__read(idRefs(ids).add(id)), false).join(' ');
1621
+ }
1622
+ /**
1623
+ * Returns an updated id ref string with the provided id value removed
1624
+ * @param ids - string of id refs
1625
+ * @param id - id to remove
1626
+ */
1627
+ function removeIdRef(_ids, id) {
1628
+ var ids = idRefs(_ids);
1629
+ ids.delete(id);
1630
+ return tslib.__spreadArray([], tslib.__read(ids), false).join(' ');
1631
+ }
1632
+ /**
1633
+ * Returns if an id ref string contains the provided id value
1634
+ * @param ids - string of id refs
1635
+ * @param id - id to check if it exists in the provided idRef string
1636
+ */
1637
+ function hasIdRef(ids, id) {
1638
+ return idRefs(ids).has(id);
1639
+ }
1640
+
1604
1641
  var TIP_HIDE_DELAY = 100;
1605
1642
  // fires a custom "cauldron:tooltip:show" / "cauldron:tooltip:hide" event
1606
1643
  // to allow projects using cauldron to hook into when a tooltip is shown/hidden
@@ -1723,11 +1760,17 @@ function Tooltip(_a) {
1723
1760
  }, [tooltipElement, show, hide]);
1724
1761
  // Keep the target's id in sync
1725
1762
  React.useEffect(function () {
1726
- var attrText = targetElement === null || targetElement === void 0 ? void 0 : targetElement.getAttribute(association);
1727
- if (!(attrText === null || attrText === void 0 ? void 0 : attrText.includes(id || ''))) {
1728
- targetElement === null || targetElement === void 0 ? void 0 : targetElement.setAttribute(association, [id, attrText].filter(Boolean).join(' '));
1763
+ var idRefs = targetElement === null || targetElement === void 0 ? void 0 : targetElement.getAttribute(association);
1764
+ if (!hasIdRef(idRefs, id)) {
1765
+ targetElement === null || targetElement === void 0 ? void 0 : targetElement.setAttribute(association, addIdRef(idRefs, id));
1729
1766
  }
1730
- }, [targetElement, id]);
1767
+ return function () {
1768
+ if (targetElement) {
1769
+ var idRefs_1 = targetElement.getAttribute(association);
1770
+ targetElement.setAttribute(association, removeIdRef(idRefs_1, id));
1771
+ }
1772
+ };
1773
+ }, [targetElement, id, association]);
1731
1774
  return (React__default["default"].createElement(React__default["default"].Fragment, null, (showTooltip || hideElementOnHidden) && isBrowser()
1732
1775
  ? reactDom.createPortal(React__default["default"].createElement("div", tslib.__assign({ id: id, className: classNames__default["default"]('Tooltip', "Tooltip--".concat(placement), className, {
1733
1776
  TooltipInfo: variant === 'info',
@@ -1998,19 +2041,6 @@ var randomId = function () {
1998
2041
  return "x_".concat(i++, "_").concat(num);
1999
2042
  };
2000
2043
 
2001
- /**
2002
- * Adds an id to a token list attribute if its not already present in the list
2003
- */
2004
- var tokenList = function (id, currentVal) {
2005
- if (currentVal === void 0) { currentVal = ''; }
2006
- var values = currentVal.split(' ');
2007
- if (values.includes(id)) {
2008
- return currentVal;
2009
- }
2010
- values.push(id);
2011
- return values.join(' ').trim();
2012
- };
2013
-
2014
2044
  var Select = React__default["default"].forwardRef(function (_a, ref) {
2015
2045
  var options = _a.options, children = _a.children, disabled = _a.disabled, label = _a.label, id = _a.id, required = _a.required, _b = _a.requiredText, requiredText = _b === void 0 ? 'Required' : _b, error = _a.error, value = _a.value, ariaDescribedby = _a["aria-describedby"], defaultValue = _a.defaultValue, onChange = _a.onChange, rest = tslib.__rest(_a, ["options", "children", "disabled", "label", "id", "required", "requiredText", "error", "value", 'aria-describedby', "defaultValue", "onChange"]);
2016
2046
  if (options && children) {
@@ -2044,7 +2074,7 @@ var Select = React__default["default"].forwardRef(function (_a, ref) {
2044
2074
  dynamicProps.defaultValue = defaultValue;
2045
2075
  }
2046
2076
  if (error) {
2047
- dynamicProps['aria-describedby'] = tokenList(errorId, ariaDescribedby);
2077
+ dynamicProps['aria-describedby'] = addIdRef(ariaDescribedby, errorId);
2048
2078
  }
2049
2079
  // In order to support controlled selects, we
2050
2080
  // have to attach an `onChange` to the select.
@@ -2260,10 +2290,10 @@ var Checkbox = React.forwardRef(function (_a, ref) {
2260
2290
  }, []), errorId = _f.errorId, labelDescriptionId = _f.labelDescriptionId;
2261
2291
  var ariaDescribedbyId = ariaDescribedby;
2262
2292
  if (error) {
2263
- ariaDescribedbyId = tokenList(errorId, ariaDescribedbyId);
2293
+ ariaDescribedbyId = addIdRef(ariaDescribedbyId, errorId);
2264
2294
  }
2265
2295
  if (labelDescription) {
2266
- ariaDescribedbyId = tokenList(labelDescriptionId, ariaDescribedbyId);
2296
+ ariaDescribedbyId = addIdRef(ariaDescribedbyId, labelDescriptionId);
2267
2297
  }
2268
2298
  return (React__default["default"].createElement("div", { className: "Checkbox__wrap" },
2269
2299
  React__default["default"].createElement("div", { className: classNames__default["default"]('Checkbox is--flex-row', className) },
@@ -2349,7 +2379,7 @@ var TextField = /** @class */ (function (_super) {
2349
2379
  var Field = multiline ? 'textarea' : 'input';
2350
2380
  var inputProps = {
2351
2381
  'aria-describedby': error
2352
- ? tokenList(this.errorId, ariaDescribedby)
2382
+ ? addIdRef(ariaDescribedby, this.errorId)
2353
2383
  : ariaDescribedby
2354
2384
  };
2355
2385
  return (React__default["default"].createElement("div", { className: "Field" },
@@ -2403,7 +2433,7 @@ var TextFieldWrapper = React.forwardRef(function (_a, ref) {
2403
2433
  TextFieldWrapper.displayName = 'TextFieldWrapper';
2404
2434
 
2405
2435
  var SearchField = React.forwardRef(function (_a, ref) {
2406
- var label = _a.label, _b = _a.defaultValue, defaultValue = _b === void 0 ? '' : _b, onChange = _a.onChange, _c = _a.hideLabel, hideLabel = _c === void 0 ? false : _c, _d = _a.placeholder, placeholder = _d === void 0 ? 'Search...' : _d, _e = _a.isForm, isForm = _e === void 0 ? true : _e, propId = _a.id, propValue = _a.value, otherProps = tslib.__rest(_a, ["label", "defaultValue", "onChange", "hideLabel", "placeholder", "isForm", "id", "value"]);
2436
+ var label = _a.label, _b = _a.defaultValue, defaultValue = _b === void 0 ? '' : _b, onChange = _a.onChange, _c = _a.hideLabel, hideLabel = _c === void 0 ? false : _c, _d = _a.placeholder, placeholder = _d === void 0 ? 'Search...' : _d, _e = _a.isForm, isForm = _e === void 0 ? true : _e, propId = _a.id, propValue = _a.value, trailingChildren = _a.trailingChildren, otherProps = tslib.__rest(_a, ["label", "defaultValue", "onChange", "hideLabel", "placeholder", "isForm", "id", "value", "trailingChildren"]);
2407
2437
  var isControlled = typeof propValue !== 'undefined';
2408
2438
  var _f = tslib.__read(React.useState(isControlled ? propValue : defaultValue), 2), value = _f[0], setValue = _f[1];
2409
2439
  var _g = tslib.__read(propId ? [propId] : nextId.useId(1, 'search-field'), 1), id = _g[0];
@@ -2419,6 +2449,9 @@ var SearchField = React.forwardRef(function (_a, ref) {
2419
2449
  setValue(newValue);
2420
2450
  };
2421
2451
  var Field = isForm ? 'form' : 'div';
2452
+ if (typeof trailingChildren === 'string') {
2453
+ trailingChildren = React__default["default"].createElement("span", null, trailingChildren);
2454
+ }
2422
2455
  return (React__default["default"].createElement(Field, { role: isForm ? 'search' : undefined, className: "SearchField", "aria-labelledby": isForm ? "".concat(inputId, "-label") : undefined },
2423
2456
  hideLabel ? (React__default["default"].createElement(Offscreen, null,
2424
2457
  React__default["default"].createElement("label", { htmlFor: inputId, id: "".concat(inputId, "-label") }, label))) : (React__default["default"].createElement("label", { className: "Field__label", htmlFor: inputId, id: "".concat(inputId, "-label") }, label)),
@@ -2426,7 +2459,8 @@ var SearchField = React.forwardRef(function (_a, ref) {
2426
2459
  'TextFieldWrapper--disabled': otherProps.disabled
2427
2460
  }) },
2428
2461
  React__default["default"].createElement(Icon, { type: "magnifying-glass", className: "SearchField__search-icon" }),
2429
- React__default["default"].createElement("input", tslib.__assign({ id: inputId, value: value, onChange: handleChange, placeholder: placeholder, ref: ref }, otherProps, { className: classNames__default["default"](otherProps.className, 'Field__text-input'), type: "search" })))));
2462
+ React__default["default"].createElement("input", tslib.__assign({ id: inputId, value: value, onChange: handleChange, placeholder: placeholder, ref: ref }, otherProps, { className: classNames__default["default"](otherProps.className, 'Field__text-input'), type: "search" })),
2463
+ trailingChildren)));
2430
2464
  });
2431
2465
  SearchField.displayName = 'SearchField';
2432
2466
 
@@ -3736,7 +3770,7 @@ var Combobox = React.forwardRef(function (_a, ref) {
3736
3770
  noMatchingOptions));
3737
3771
  var errorId = "".concat(id, "-error");
3738
3772
  var inputProps = tslib.__assign(tslib.__assign({}, props), { 'aria-describedby': error
3739
- ? tokenList(errorId, ariaDescribedby)
3773
+ ? addIdRef(ariaDescribedby, errorId)
3740
3774
  : ariaDescribedby });
3741
3775
  return (React__default["default"].createElement("div", { id: id, className: classNames__default["default"]('Combobox', className), ref: comboboxRef },
3742
3776
  name && React__default["default"].createElement("input", { type: "hidden", name: name, value: formValue }),
@@ -0,0 +1,25 @@
1
+ type IdRefs = string | null | undefined;
2
+ /**
3
+ * Returns a unique set of id refs from the provided string
4
+ * @param ids - string of id refs
5
+ */
6
+ export default function idRefs(ids: IdRefs): Set<string>;
7
+ /**
8
+ * Returns an updated id ref string with the provided id value added
9
+ * @param ids - string of id refs
10
+ * @param id - id to add
11
+ */
12
+ export declare function addIdRef(ids: IdRefs, id: string): string;
13
+ /**
14
+ * Returns an updated id ref string with the provided id value removed
15
+ * @param ids - string of id refs
16
+ * @param id - id to remove
17
+ */
18
+ export declare function removeIdRef(_ids: IdRefs, id: string): string;
19
+ /**
20
+ * Returns if an id ref string contains the provided id value
21
+ * @param ids - string of id refs
22
+ * @param id - id to check if it exists in the provided idRef string
23
+ */
24
+ export declare function hasIdRef(ids: IdRefs, id: string): boolean;
25
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deque/cauldron-react",
3
- "version": "6.2.1-canary.6af58613",
3
+ "version": "6.2.1-canary.6d2d22b3",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Fully accessible react components library for Deque Cauldron",
6
6
  "homepage": "https://cauldron.dequelabs.com/",
@@ -1,2 +0,0 @@
1
- declare function recursivelyRemoveIds(element: React.ReactNode): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>[] | null | undefined;
2
- export default recursivelyRemoveIds;
@@ -1,5 +0,0 @@
1
- /**
2
- * Adds an id to a token list attribute if its not already present in the list
3
- */
4
- declare const tokenList: (id: string, currentVal?: string) => string;
5
- export default tokenList;