@deque/cauldron-react 6.15.0 → 6.16.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.
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import { ContentNode } from '../../types';
3
2
  import ComboboxOption from './ComboboxOption';
3
+ import type { ContentNode } from '../../types';
4
4
  import type { ComboboxValue } from './ComboboxOption';
5
5
  import type { ListboxOption } from '../Listbox/ListboxContext';
6
6
  interface ComboboxOption {
@@ -9,24 +9,42 @@ interface ComboboxOption {
9
9
  value?: ComboboxValue;
10
10
  formValue?: ComboboxValue;
11
11
  description?: string;
12
+ removeOptionLabel?: string;
12
13
  }
13
- interface ComboboxProps extends React.InputHTMLAttributes<Omit<HTMLInputElement, 'value' | 'defaultValue'>> {
14
+ interface BaseComboboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'value' | 'defaultValue'> {
14
15
  label: ContentNode;
15
16
  options?: ComboboxOption[];
16
- value?: ComboboxValue;
17
- defaultValue?: ComboboxValue;
18
17
  requiredText?: React.ReactNode;
19
18
  error?: React.ReactNode;
20
19
  autocomplete?: 'none' | 'manual' | 'automatic';
21
- onSelectionChange?: <T extends HTMLElement = HTMLElement>({ target, value, previousValue }: {
22
- target: T;
23
- value: ComboboxValue;
24
- previousValue: ComboboxValue;
25
- }) => void;
26
20
  onActiveChange?: (option: ListboxOption) => void;
27
21
  renderNoResults?: (() => React.JSX.Element) | React.ReactElement;
28
22
  portal?: React.RefObject<HTMLElement> | HTMLElement;
29
23
  inputRef?: React.Ref<HTMLInputElement>;
30
24
  }
31
- declare const Combobox: React.ForwardRefExoticComponent<ComboboxProps & React.RefAttributes<HTMLDivElement>>;
25
+ interface SingleSelectComboboxProps extends BaseComboboxProps {
26
+ value?: ComboboxValue;
27
+ defaultValue?: ComboboxValue;
28
+ inputValue?: never;
29
+ defaultInputValue?: never;
30
+ onSelectionChange?: <T extends HTMLElement = HTMLElement>(props: {
31
+ target: T;
32
+ value: ComboboxValue;
33
+ previousValue: ComboboxValue;
34
+ }) => void;
35
+ multiselect?: false;
36
+ }
37
+ interface MultiSelectComboboxProps extends BaseComboboxProps {
38
+ value?: ComboboxValue[];
39
+ defaultValue?: ComboboxValue[];
40
+ inputValue?: ComboboxValue;
41
+ defaultInputValue?: ComboboxValue;
42
+ onSelectionChange?: <T extends HTMLElement = HTMLElement>(props: {
43
+ target: T;
44
+ value: ComboboxValue[];
45
+ previousValue: ComboboxValue[];
46
+ }) => void;
47
+ multiselect: true;
48
+ }
49
+ declare const Combobox: React.ForwardRefExoticComponent<(SingleSelectComboboxProps | MultiSelectComboboxProps) & React.RefAttributes<HTMLDivElement>>;
32
50
  export default Combobox;
@@ -3,22 +3,25 @@ import { ComboboxValue } from './ComboboxOption';
3
3
  type ComboboxContext = {
4
4
  autocomplete: 'none' | 'manual' | 'automatic';
5
5
  inputValue: ComboboxValue;
6
- formValue: ComboboxValue;
7
- selectedValue: ComboboxValue;
6
+ formValues: ComboboxValue[];
7
+ selectedValues: ComboboxValue[];
8
+ removeOptionLabels: string[];
9
+ setRemoveOptionLabels: React.Dispatch<React.SetStateAction<string[]>>;
8
10
  matchingOptions: Map<HTMLElement, ComboboxOptionState>;
9
11
  setMatchingOptions: React.Dispatch<React.SetStateAction<Map<HTMLElement, ComboboxOptionState>>>;
10
- setFormValue: React.Dispatch<React.SetStateAction<ComboboxValue>>;
12
+ setFormValues: React.Dispatch<React.SetStateAction<ComboboxValue[]>>;
11
13
  matches: (<T extends string = string>(value: T) => boolean) | boolean;
12
14
  };
13
15
  export type ComboboxOptionState = {
14
16
  selected: boolean;
15
17
  value: ComboboxValue;
18
+ displayValue: ComboboxValue;
16
19
  };
17
20
  type ComboboxProvider = {
18
21
  children: React.ReactNode;
19
22
  matches: ((inputValue: string, value: string) => boolean) | boolean;
20
23
  } & Omit<ComboboxContext, 'matches'>;
21
24
  declare const ComboboxContext: React.Context<ComboboxContext>;
22
- declare function ComboboxProvider({ autocomplete, inputValue, formValue, selectedValue, matches, matchingOptions, setMatchingOptions, setFormValue, children }: ComboboxProvider): React.JSX.Element;
25
+ declare function ComboboxProvider({ autocomplete, inputValue, formValues, selectedValues, removeOptionLabels, setRemoveOptionLabels, matches, matchingOptions, setMatchingOptions, setFormValues, children }: ComboboxProvider): React.JSX.Element;
23
26
  declare function useComboboxContext(): ComboboxContext;
24
27
  export { ComboboxProvider, useComboboxContext };
@@ -7,6 +7,7 @@ interface ComboboxOptionProps extends React.HTMLAttributes<HTMLLIElement> {
7
7
  value?: ComboboxValue;
8
8
  formValue?: ComboboxValue;
9
9
  description?: ContentNode;
10
+ removeOptionLabel?: string;
10
11
  children: string;
11
12
  }
12
13
  declare const ComboboxOption: React.ForwardRefExoticComponent<ComboboxOptionProps & React.RefAttributes<HTMLLIElement>>;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { ComboboxValue } from './ComboboxOption';
3
+ interface ComboboxPillProps extends React.HTMLAttributes<HTMLButtonElement> {
4
+ value: ComboboxValue;
5
+ removeOptionLabel?: string;
6
+ disabled?: boolean;
7
+ onClick: (e: React.MouseEvent<HTMLButtonElement>) => void;
8
+ }
9
+ declare const ComboboxPill: React.ForwardRefExoticComponent<ComboboxPillProps & React.RefAttributes<HTMLButtonElement>>;
10
+ export default ComboboxPill;
@@ -5,6 +5,7 @@ import type { PolymorphicProps, PolymorphicComponent } from '../../utils/polymor
5
5
  interface BaseListboxProps extends PolymorphicProps<Omit<React.HTMLAttributes<HTMLElement>, 'onSelect' | 'defaultValue'>> {
6
6
  navigation?: 'cycle' | 'bound';
7
7
  onActiveChange?: (option: ListboxOption) => void;
8
+ disabled?: boolean;
8
9
  }
9
10
  interface SingleSelectListboxProps extends BaseListboxProps {
10
11
  multiselect?: false;
@@ -1,11 +1,23 @@
1
1
  import React from 'react';
2
2
  import { type TooltipProps } from '../Tooltip';
3
3
  import type { PolymorphicProps, PolymorphicComponent } from '../../utils/polymorphicComponent';
4
- interface TextEllipsisProps extends PolymorphicProps<React.HTMLAttributes<HTMLElement>> {
4
+ interface TextEllipsisBaseProps extends PolymorphicProps<React.HTMLAttributes<HTMLElement>> {
5
5
  children: string;
6
6
  maxLines?: number;
7
7
  refProp?: string;
8
- tooltipProps?: Omit<TooltipProps, 'target' | 'association'>;
8
+ /**
9
+ * Using this prop may introduce accessibility issues by hiding content from the user.
10
+ * Only use this prop if you have an alternative way to make the full text accessible.
11
+ */
12
+ hideTooltip?: boolean;
9
13
  }
10
- declare const TextEllipsis: PolymorphicComponent<TextEllipsisProps>;
14
+ interface TextEllipsisWithTooltipProps extends TextEllipsisBaseProps {
15
+ tooltipProps?: Omit<TooltipProps, 'target' | 'association' | 'children'>;
16
+ }
17
+ interface TextEllipsisWithoutTooltipProps extends TextEllipsisBaseProps {
18
+ tooltipProps: never;
19
+ /** Prevent TextEllipsis from showing a tooltip when the text is ellipsized. */
20
+ hideTooltip: true;
21
+ }
22
+ declare const TextEllipsis: PolymorphicComponent<TextEllipsisWithTooltipProps | TextEllipsisWithoutTooltipProps>;
11
23
  export default TextEllipsis;
package/lib/index.js CHANGED
@@ -3630,10 +3630,10 @@ var optionMatchesValue = function (option, value) {
3630
3630
  option.value === value;
3631
3631
  };
3632
3632
  var Listbox = React.forwardRef(function (_a, ref) {
3633
- var _b = _a.as, Component = _b === void 0 ? 'ul' : _b, children = _a.children, defaultValue = _a.defaultValue, value = _a.value, _c = _a.navigation, navigation = _c === void 0 ? 'bound' : _c, _d = _a.multiselect, multiselect = _d === void 0 ? false : _d, onKeyDown = _a.onKeyDown, onFocus = _a.onFocus, onSelectionChange = _a.onSelectionChange, onActiveChange = _a.onActiveChange, props = tslib.__rest(_a, ["as", "children", "defaultValue", "value", "navigation", "multiselect", "onKeyDown", "onFocus", "onSelectionChange", "onActiveChange"]);
3634
- var _e = tslib.__read(React.useState([]), 2), options = _e[0], setOptions = _e[1];
3635
- var _f = tslib.__read(React.useState(null), 2), activeOption = _f[0], setActiveOption = _f[1];
3636
- var _g = tslib.__read(React.useState([]), 2), selectedOptions = _g[0], setSelectedOptions = _g[1];
3633
+ var _b = _a.as, Component = _b === void 0 ? 'ul' : _b, children = _a.children, defaultValue = _a.defaultValue, value = _a.value, _c = _a.navigation, navigation = _c === void 0 ? 'bound' : _c, _d = _a.multiselect, multiselect = _d === void 0 ? false : _d, onKeyDown = _a.onKeyDown, onFocus = _a.onFocus, onSelectionChange = _a.onSelectionChange, onActiveChange = _a.onActiveChange, _e = _a.disabled, disabled = _e === void 0 ? false : _e, props = tslib.__rest(_a, ["as", "children", "defaultValue", "value", "navigation", "multiselect", "onKeyDown", "onFocus", "onSelectionChange", "onActiveChange", "disabled"]);
3634
+ var _f = tslib.__read(React.useState([]), 2), options = _f[0], setOptions = _f[1];
3635
+ var _g = tslib.__read(React.useState(null), 2), activeOption = _g[0], setActiveOption = _g[1];
3636
+ var _h = tslib.__read(React.useState([]), 2), selectedOptions = _h[0], setSelectedOptions = _h[1];
3637
3637
  var listboxRef = useSharedRef(ref);
3638
3638
  var isControlled = typeof value !== 'undefined';
3639
3639
  React.useLayoutEffect(function () {
@@ -3673,6 +3673,9 @@ var Listbox = React.forwardRef(function (_a, ref) {
3673
3673
  var handleSelect = React.useCallback(function (option) {
3674
3674
  var _a;
3675
3675
  setActiveOption(option);
3676
+ if (disabled) {
3677
+ return;
3678
+ }
3676
3679
  var optionIsSelected = selectedOptions.some(function (selected) { return selected.element === option.element; });
3677
3680
  var previousValues = selectedOptions.map(function (selected) { return selected.value; });
3678
3681
  // istanbul ignore else
@@ -3861,36 +3864,42 @@ ListboxGroup.displayName = 'ListboxGroup';
3861
3864
  var ComboboxContext = React.createContext({
3862
3865
  autocomplete: 'manual',
3863
3866
  inputValue: undefined,
3864
- formValue: undefined,
3865
- selectedValue: undefined,
3867
+ formValues: [],
3868
+ selectedValues: [],
3869
+ removeOptionLabels: [],
3870
+ setRemoveOptionLabels: function () { return null; },
3866
3871
  matches: true,
3867
3872
  matchingOptions: new Map(),
3868
3873
  setMatchingOptions: function () { return null; },
3869
- setFormValue: function () { return null; }
3874
+ setFormValues: function () { return null; }
3870
3875
  });
3871
3876
  function ComboboxProvider(_a) {
3872
- 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;
3877
+ var autocomplete = _a.autocomplete, inputValue = _a.inputValue, formValues = _a.formValues, selectedValues = _a.selectedValues, removeOptionLabels = _a.removeOptionLabels, setRemoveOptionLabels = _a.setRemoveOptionLabels, matches = _a.matches, matchingOptions = _a.matchingOptions, setMatchingOptions = _a.setMatchingOptions, setFormValues = _a.setFormValues, children = _a.children;
3873
3878
  var Provider = ComboboxContext.Provider;
3874
3879
  var contextValue = React.useMemo(function () { return ({
3875
3880
  autocomplete: autocomplete,
3876
3881
  inputValue: inputValue,
3877
- formValue: formValue,
3878
- selectedValue: selectedValue,
3882
+ formValues: formValues,
3883
+ selectedValues: selectedValues,
3884
+ removeOptionLabels: removeOptionLabels,
3885
+ setRemoveOptionLabels: setRemoveOptionLabels,
3879
3886
  matches: typeof matches === 'function' && !!inputValue
3880
3887
  ? function (value) { return matches(inputValue, value); }
3881
3888
  : true,
3882
3889
  matchingOptions: matchingOptions,
3883
3890
  setMatchingOptions: setMatchingOptions,
3884
- setFormValue: setFormValue
3891
+ setFormValues: setFormValues
3885
3892
  }); }, [
3886
3893
  autocomplete,
3887
3894
  inputValue,
3888
- formValue,
3889
- selectedValue,
3895
+ formValues,
3896
+ selectedValues,
3897
+ removeOptionLabels,
3898
+ setRemoveOptionLabels,
3890
3899
  matches,
3891
3900
  matchingOptions,
3892
3901
  setMatchingOptions,
3893
- setFormValue
3902
+ setFormValues
3894
3903
  ]);
3895
3904
  return React__default["default"].createElement(Provider, { value: contextValue }, children);
3896
3905
  }
@@ -3963,11 +3972,10 @@ var ComboboxMatch = function (_a) {
3963
3972
  React__default["default"].createElement("span", null, matchAfter)));
3964
3973
  };
3965
3974
  var ComboboxOption = React.forwardRef(function (_a, ref) {
3966
- var _b;
3967
- 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"]);
3968
- var _c = tslib.__read(propId ? [propId] : nextId.useId(1, 'combobox-option'), 1), id = _c[0];
3969
- var _d = useListboxContext(), selected = _d.selected, active = _d.active;
3970
- var _e = useComboboxContext(), selectedValue = _e.selectedValue, matches = _e.matches, setMatchingOptions = _e.setMatchingOptions, setFormValue = _e.setFormValue;
3975
+ var className = _a.className, children = _a.children, disabled = _a.disabled, propId = _a.id, description = _a.description, propValue = _a.value, formValue = _a.formValue, removeOptionLabel = _a.removeOptionLabel, props = tslib.__rest(_a, ["className", "children", "disabled", "id", "description", "value", "formValue", "removeOptionLabel"]);
3976
+ var _b = tslib.__read(propId ? [propId] : nextId.useId(1, 'combobox-option'), 1), id = _b[0];
3977
+ var _c = useListboxContext(), selected = _c.selected, active = _c.active;
3978
+ var _d = useComboboxContext(), selectedValues = _d.selectedValues, setRemoveOptionLabels = _d.setRemoveOptionLabels, matches = _d.matches, setMatchingOptions = _d.setMatchingOptions, setFormValues = _d.setFormValues;
3971
3979
  var comboboxOptionRef = useSharedRef(ref);
3972
3980
  var intersectionRef = useIntersectionRef(comboboxOptionRef, {
3973
3981
  root: null,
@@ -3975,8 +3983,10 @@ var ComboboxOption = React.forwardRef(function (_a, ref) {
3975
3983
  });
3976
3984
  var isActive = !!(active === null || active === void 0 ? void 0 : active.element) && active.element === comboboxOptionRef.current;
3977
3985
  var isSelected = !!(selected &&
3978
- !!((_b = selected[0]) === null || _b === void 0 ? void 0 : _b.element) &&
3979
- selected[0].element === comboboxOptionRef.current);
3986
+ selected.findIndex(function (_a) {
3987
+ var element = _a.element;
3988
+ return element === comboboxOptionRef.current;
3989
+ }) !== -1);
3980
3990
  var isMatching = (typeof matches === 'boolean' && matches) ||
3981
3991
  (typeof matches === 'function' && matches(children));
3982
3992
  // istanbul ignore next
@@ -4002,15 +4012,33 @@ var ComboboxOption = React.forwardRef(function (_a, ref) {
4002
4012
  var comboboxValue = typeof propValue !== 'undefined'
4003
4013
  ? propValue
4004
4014
  : (_a = comboboxOptionRef.current) === null || _a === void 0 ? void 0 : _a.innerText;
4005
- if (selectedValue === comboboxValue) {
4006
- setFormValue(typeof formValue === 'undefined' ? comboboxValue : formValue);
4007
- }
4008
- }, [selectedValue, formValue]);
4015
+ var value = typeof formValue === 'undefined' ? comboboxValue : formValue;
4016
+ setFormValues(function (prev) {
4017
+ var formValues = prev.filter(function (fv) { return fv !== value; });
4018
+ if (selectedValues.includes(comboboxValue)) {
4019
+ formValues.push(value);
4020
+ }
4021
+ return formValues;
4022
+ });
4023
+ setRemoveOptionLabels(function (prev) {
4024
+ if (!removeOptionLabel) {
4025
+ return prev;
4026
+ }
4027
+ return selectedValues.map(function (value, index) {
4028
+ return value === comboboxValue ? removeOptionLabel : prev[index];
4029
+ });
4030
+ });
4031
+ }, [selectedValues, formValue]);
4009
4032
  React.useEffect(function () {
4033
+ var _a;
4010
4034
  if (isMatching) {
4035
+ var comboboxValue_1 = typeof propValue !== 'undefined'
4036
+ ? propValue
4037
+ : (_a = comboboxOptionRef.current) === null || _a === void 0 ? void 0 : _a.innerText;
4011
4038
  setMatchingOptions(function (options) {
4012
4039
  return new Map(options.set(comboboxOptionRef.current, {
4013
- value: children,
4040
+ value: comboboxValue_1,
4041
+ displayValue: children,
4014
4042
  selected: isSelected
4015
4043
  }));
4016
4044
  });
@@ -4042,8 +4070,34 @@ var ComboboxOption = React.forwardRef(function (_a, ref) {
4042
4070
  });
4043
4071
  ComboboxOption.displayName = 'ComboboxOption';
4044
4072
 
4073
+ var ComboboxPill = React.forwardRef(function (_a, ref) {
4074
+ var value = _a.value, removeOptionLabel = _a.removeOptionLabel, _b = _a.disabled, disabled = _b === void 0 ? false : _b, rest = tslib.__rest(_a, ["value", "removeOptionLabel", "disabled"]);
4075
+ var commonProps = {
4076
+ ref: ref,
4077
+ 'aria-label': removeOptionLabel ? removeOptionLabel : "remove ".concat(value),
4078
+ className: 'ComboboxPill',
4079
+ tabIndex: -1
4080
+ };
4081
+ return !disabled ? (React__default["default"].createElement(TagButton, tslib.__assign({ label: value || '', value: "", icon: "close" }, commonProps, rest))) : (React__default["default"].createElement(Button, tslib.__assign({ variant: "tag", disabled: disabled }, commonProps, rest), value));
4082
+ });
4083
+ ComboboxPill.displayName = 'ComboboxPill';
4084
+
4045
4085
  // Event Keys
4046
- var _a = tslib.__read(['Enter', 'Escape', 'Home', 'End'], 4), Enter = _a[0], Escape = _a[1], Home = _a[2], End = _a[3];
4086
+ var _a = tslib.__read([
4087
+ 'Enter',
4088
+ 'Escape',
4089
+ 'Home',
4090
+ 'End',
4091
+ 'Backspace',
4092
+ 'Delete'
4093
+ ], 6), Enter = _a[0], Escape = _a[1], Home = _a[2], End = _a[3], Backspace = _a[4], Delete = _a[5];
4094
+ var _b = tslib.__read([
4095
+ 'ArrowDown',
4096
+ 'ArrowUp',
4097
+ 'ArrowLeft',
4098
+ 'ArrowRight'
4099
+ ], 4), ArrowDown = _b[0], ArrowUp = _b[1], ArrowLeft = _b[2], ArrowRight = _b[3];
4100
+ var PillKeys = [Backspace, Delete, ArrowLeft, ArrowRight];
4047
4101
  var defaultAutoCompleteMatches = function (inputValue, value) {
4048
4102
  // istanbul ignore if
4049
4103
  if (!value) {
@@ -4056,24 +4110,37 @@ var ComboboxNoResults = function (_a) {
4056
4110
  return (React__default["default"].createElement("div", { className: "ComboboxListbox__empty", role: "alert", "aria-live": "polite" }, children || 'No results found.'));
4057
4111
  };
4058
4112
  var Combobox = React.forwardRef(function (_a, ref) {
4059
- 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, _e = _a.inputRef, propInputRef = _e === void 0 ? null : _e, ariaDescribedby = _a["aria-describedby"], props = tslib.__rest(_a, ["id", "className", "label", "children", "options", "value", "defaultValue", "requiredText", "error", "autocomplete", "onSelectionChange", "onActiveChange", "onChange", "onKeyDown", "onFocus", "onBlur", "name", "renderNoResults", "portal", "inputRef", 'aria-describedby']);
4060
- var _f = tslib.__read(React.useState(defaultValue || propValue || ''), 2), value = _f[0], setValue = _f[1];
4061
- var _g = tslib.__read(React.useState(new Map()), 2), matchingOptions = _g[0], setMatchingOptions = _g[1];
4062
- var _h = tslib.__read(React.useState(value || ''), 2), selectedValue = _h[0], setSelectedValue = _h[1];
4063
- var _j = tslib.__read(React.useState(''), 2), formValue = _j[0], setFormValue = _j[1];
4064
- var _k = tslib.__read(React.useState(false), 2), open = _k[0], setOpen = _k[1];
4065
- var _l = tslib.__read(React.useState(null), 2), activeDescendant = _l[0], setActiveDescendant = _l[1];
4066
- var _m = tslib.__read(propId ? [propId] : nextId.useId(1, 'combobox'), 1), id = _m[0];
4113
+ 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"]);
4114
+ var _h = tslib.__read(React.useState(new Map()), 2), matchingOptions = _h[0], setMatchingOptions = _h[1];
4115
+ var _j = tslib.__read(React.useState(function () {
4116
+ var value = defaultValue || propValue;
4117
+ var inputVal = defaultInputValue || propInputValue;
4118
+ return (Array.isArray(value) ? inputVal : value) || '';
4119
+ }), 2), inputValue = _j[0], setInputValue = _j[1];
4120
+ var _k = tslib.__read(React.useState(function () {
4121
+ var value = defaultValue || propValue;
4122
+ if (!value) {
4123
+ return [];
4124
+ }
4125
+ return Array.isArray(value) ? value : [value];
4126
+ }), 2), selectedValues = _k[0], setSelectedValues = _k[1];
4127
+ var _l = tslib.__read(React.useState([]), 2), removeOptionLabels = _l[0], setRemoveOptionLabels = _l[1];
4128
+ var _m = tslib.__read(React.useState([]), 2), formValues = _m[0], setFormValues = _m[1];
4129
+ var _o = tslib.__read(React.useState(false), 2), open = _o[0], setOpen = _o[1];
4130
+ var _p = tslib.__read(React.useState(null), 2), activeDescendant = _p[0], setActiveDescendant = _p[1];
4131
+ var _q = tslib.__read(propId ? [propId] : nextId.useId(1, 'combobox'), 1), id = _q[0];
4067
4132
  var comboboxRef = useSharedRef(ref);
4068
4133
  var inputRef = useSharedRef(propInputRef);
4069
4134
  var listboxRef = React.useRef(null);
4070
- var isControlled = typeof propValue !== 'undefined';
4135
+ var pillsRef = React.useRef([]);
4136
+ var isControlled = typeof propValue !== 'undefined' &&
4137
+ (multiselect ? typeof propInputValue !== 'undefined' : true);
4071
4138
  var isRequired = !!props.required;
4072
4139
  var isAutoComplete = autocomplete !== 'none';
4073
4140
  var hasError = !!error;
4074
4141
  var comboboxOptions = children ||
4075
- options.map(function (option, index) { return (React__default["default"].createElement(ComboboxOption, { key: option.key || index, id: "".concat(id, "-option-").concat(index + 1), description: option.description, value: option.value }, option.label)); });
4076
- var triggerListboxKeyDown = React__default["default"].useCallback(function (key) {
4142
+ options.map(function (option, index) { return (React__default["default"].createElement(ComboboxOption, { key: option.key || index, id: "".concat(id, "-option-").concat(index + 1), description: option.description, value: option.value, formValue: option.formValue, removeOptionLabel: option.removeOptionLabel }, option.label)); });
4143
+ var triggerListboxKeyDown = React.useCallback(function (key) {
4077
4144
  var _a;
4078
4145
  (_a = listboxRef.current) === null || _a === void 0 ? void 0 : _a.dispatchEvent(new KeyboardEvent('keydown', {
4079
4146
  key: key,
@@ -4085,55 +4152,67 @@ var Combobox = React.forwardRef(function (_a, ref) {
4085
4152
  if (!isAutoComplete) {
4086
4153
  return;
4087
4154
  }
4088
- if (!open && selectedValue && value !== selectedValue) {
4089
- setValue(selectedValue);
4155
+ if (!open &&
4156
+ !multiselect &&
4157
+ selectedValues.length &&
4158
+ !selectedValues.includes(inputValue)) {
4159
+ setInputValue(selectedValues[selectedValues.length - 1] || '');
4090
4160
  }
4091
4161
  if (!open) {
4092
4162
  setActiveDescendant(null);
4093
4163
  }
4094
- if (open && autocomplete === 'automatic' && !selectedValue) {
4164
+ if (open && autocomplete === 'automatic' && !selectedValues.length) {
4095
4165
  // Fire a Home keydown event on listbox to ensure the first item is selected
4096
4166
  triggerListboxKeyDown(Home);
4097
4167
  }
4098
- }, [open]);
4168
+ }, [open, multiselect, autocomplete, selectedValues]);
4099
4169
  React.useEffect(function () {
4170
+ var lastSelectedValue = selectedValues.length !== 0
4171
+ ? selectedValues[selectedValues.length - 1]
4172
+ : undefined;
4100
4173
  var _a = tslib.__read(Array.from(matchingOptions.entries()).find(function (_a) {
4101
- var _b = tslib.__read(_a, 2), selected = _b[1].selected;
4102
- return selected;
4174
+ var _b = tslib.__read(_a, 2), value = _b[1].value;
4175
+ return value === lastSelectedValue;
4103
4176
  }) || [], 2), element = _a[0], option = _a[1];
4104
4177
  if (autocomplete === 'manual') {
4105
4178
  setActiveDescendant(!element ? null : tslib.__assign({ element: element }, option));
4106
4179
  }
4107
4180
  else if (autocomplete === 'automatic' &&
4108
4181
  matchingOptions.size &&
4109
- !selectedValue) {
4182
+ !selectedValues.length) {
4110
4183
  // Fire a home keydown event on listbox to ensure the first item is selected
4111
4184
  requestAnimationFrame(function () {
4112
4185
  triggerListboxKeyDown(Home);
4113
4186
  });
4114
4187
  }
4115
- }, [matchingOptions]);
4188
+ }, [selectedValues, matchingOptions]);
4116
4189
  var handleFocus = React.useCallback(function (event) {
4117
4190
  onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
4118
4191
  // istanbul ignore else
4119
4192
  if (!event.defaultPrevented) {
4120
4193
  setOpen(true);
4121
- if (selectedValue && value === selectedValue && isAutoComplete) {
4122
- setValue('');
4194
+ if (selectedValues.length &&
4195
+ selectedValues.includes(inputValue) &&
4196
+ isAutoComplete) {
4197
+ setInputValue('');
4123
4198
  }
4124
4199
  }
4125
- }, [onFocus, value, selectedValue]);
4200
+ }, [onFocus, inputValue, selectedValues]);
4126
4201
  var handleInputClick = React.useCallback(function (event) {
4127
4202
  var _a;
4128
- setOpen(true);
4129
- if (selectedValue && value === selectedValue && isAutoComplete) {
4130
- setValue('');
4203
+ if (!disabled) {
4204
+ setOpen(true);
4205
+ }
4206
+ if (selectedValues.length &&
4207
+ selectedValues.includes(inputValue) &&
4208
+ isAutoComplete) {
4209
+ setInputValue('');
4131
4210
  }
4132
4211
  if (event.target !== inputRef.current) {
4133
4212
  // ensure focus is set on the input field
4134
4213
  (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
4135
4214
  }
4136
- }, [value, selectedValue]);
4215
+ }, [disabled, inputValue, selectedValues]);
4137
4216
  var handleComboboxOptionMouseDown = React.useCallback(function (event) {
4138
4217
  // prevent blur from triggering when activating combobox options
4139
4218
  event.preventDefault();
@@ -4150,22 +4229,46 @@ var Combobox = React.forwardRef(function (_a, ref) {
4150
4229
  onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
4151
4230
  setOpen(false);
4152
4231
  if (autocomplete === 'automatic' && activeDescendant) {
4153
- var stringValue = ((_a = activeDescendant.value) === null || _a === void 0 ? void 0 : _a.toString()) ||
4232
+ var activeValue_1 = ((_a = activeDescendant.value) === null || _a === void 0 ? void 0 : _a.toString()) ||
4154
4233
  /* istanbul ignore next: default value */ '';
4155
- setValue(stringValue);
4156
- setSelectedValue(stringValue);
4157
- onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange({
4158
- target: activeDescendant.element,
4159
- value: stringValue,
4160
- previousValue: value
4161
- });
4234
+ setInputValue(activeValue_1);
4235
+ if (!multiselect) {
4236
+ setSelectedValues([activeValue_1]);
4237
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange({
4238
+ target: activeDescendant.element,
4239
+ value: activeValue_1,
4240
+ previousValue: selectedValues[0]
4241
+ });
4242
+ }
4243
+ else {
4244
+ var activeValueIndex = selectedValues.indexOf(activeValue_1);
4245
+ var newSelectedValues = selectedValues.filter(function (v) { return v !== activeValue_1; });
4246
+ if (activeValueIndex === -1) {
4247
+ newSelectedValues.push(activeValue_1);
4248
+ }
4249
+ setSelectedValues(newSelectedValues);
4250
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange({
4251
+ target: activeDescendant.element,
4252
+ value: newSelectedValues,
4253
+ previousValue: selectedValues
4254
+ });
4255
+ }
4162
4256
  }
4163
- }, [autocomplete, activeDescendant, onBlur]);
4257
+ }, [
4258
+ autocomplete,
4259
+ activeDescendant,
4260
+ onBlur,
4261
+ selectedValues,
4262
+ onSelectionChange
4263
+ ]);
4164
4264
  var handleKeyDown = React.useCallback(function (event) {
4265
+ var _a;
4165
4266
  onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
4166
4267
  var enterKeypress = event.key === Enter;
4167
4268
  var escKeypress = event.key === Escape;
4168
- var arrowKeypress = ['ArrowDown', 'ArrowUp'].includes(event.key);
4269
+ var deleteKeypress = event.key === Delete;
4270
+ var backspaceKeypress = event.key === Backspace;
4271
+ var listboxArrowKeypress = [ArrowUp, ArrowDown].includes(event.key);
4169
4272
  if (
4170
4273
  // prevent the page from scrolling and allow start/end option activation
4171
4274
  [Home, End].includes(event.key) ||
@@ -4183,10 +4286,18 @@ var Combobox = React.forwardRef(function (_a, ref) {
4183
4286
  return;
4184
4287
  }
4185
4288
  setOpen(true);
4186
- if (!open && arrowKeypress && selectedValue && isAutoComplete) {
4289
+ if (inputValue === '' &&
4290
+ (backspaceKeypress || deleteKeypress || event.key === ArrowLeft) &&
4291
+ pillsRef.current.length !== 0) {
4292
+ (_a = pillsRef.current[pillsRef.current.length - 1]) === null || _a === void 0 ? void 0 : _a.focus();
4293
+ }
4294
+ if (!open &&
4295
+ listboxArrowKeypress &&
4296
+ selectedValues.length &&
4297
+ isAutoComplete) {
4187
4298
  // If the user opens the combobox again with a selected value
4188
4299
  // just clear out the field to restore filtering capabilities
4189
- setValue('');
4300
+ setInputValue('');
4190
4301
  }
4191
4302
  // Space should not trigger selection since the user could be typing
4192
4303
  // a value for autocompletion. Additionally when not open and there's
@@ -4199,37 +4310,124 @@ var Combobox = React.forwardRef(function (_a, ref) {
4199
4310
  // forward input events to listbox
4200
4311
  triggerListboxKeyDown(event.key);
4201
4312
  // Close combobox with keyboard selections
4202
- if (enterKeypress && activeDescendant) {
4313
+ if (enterKeypress && activeDescendant && !multiselect) {
4203
4314
  setOpen(false);
4204
4315
  }
4205
- }, [onKeyDown, isAutoComplete, open, selectedValue, activeDescendant]);
4316
+ }, [
4317
+ onKeyDown,
4318
+ isAutoComplete,
4319
+ open,
4320
+ multiselect,
4321
+ selectedValues,
4322
+ activeDescendant
4323
+ ]);
4206
4324
  React.useEffect(function () {
4207
- if (typeof propValue !== 'undefined') {
4208
- setValue(propValue);
4325
+ if (isControlled) {
4326
+ if (!multiselect) {
4327
+ setInputValue(propValue || '');
4328
+ }
4329
+ else {
4330
+ setInputValue(propInputValue || '');
4331
+ }
4209
4332
  }
4210
- }, [propValue]);
4333
+ }, [multiselect, propValue, propInputValue]);
4211
4334
  var handleChange = React.useCallback(function (event) {
4335
+ if (disabled) {
4336
+ return;
4337
+ }
4212
4338
  onChange === null || onChange === void 0 ? void 0 : onChange(event);
4213
4339
  // istanbul ignore else
4214
4340
  if (!isControlled) {
4215
- setValue(event.target.value);
4341
+ setInputValue(event.target.value);
4216
4342
  }
4217
4343
  }, [isControlled, onChange]);
4218
- var handleSelectionChange = React.useCallback(function (_a) {
4219
- var target = _a.target, listboxValue = _a.value, previousValue = _a.previousValue;
4220
- var stringValue = (listboxValue === null || listboxValue === void 0 ? void 0 : listboxValue.toString()) || /* istanbul ignore next */ '';
4221
- // istanbul ignore else
4222
- if (!isControlled) {
4223
- setValue(stringValue);
4344
+ var handleRemovePill = React.useCallback(function (target, value) {
4345
+ if (disabled) {
4346
+ return;
4224
4347
  }
4225
- setSelectedValue(stringValue);
4348
+ var newSelectedValues = selectedValues.filter(function (v) { return v !== value; });
4349
+ setSelectedValues(newSelectedValues);
4226
4350
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange({
4227
4351
  target: target,
4228
- value: stringValue,
4229
- previousValue: previousValue === null || previousValue === void 0 ? void 0 : previousValue.toString()
4352
+ value: newSelectedValues,
4353
+ previousValue: selectedValues
4230
4354
  });
4231
- setOpen(false);
4232
- }, [isControlled, onSelectionChange]);
4355
+ }, [disabled, selectedValues, onSelectionChange]);
4356
+ var handlePillKeyDown = React.useCallback(function (event) {
4357
+ if (!PillKeys.includes(event.key)) {
4358
+ return;
4359
+ }
4360
+ event.preventDefault();
4361
+ var isDelete = event.key === Delete;
4362
+ var isBackspace = event.key === Backspace;
4363
+ var isArrowLeft = event.key === ArrowLeft;
4364
+ var isArrowRight = event.key === ArrowRight;
4365
+ var focusedIndex = pillsRef.current.findIndex(function (p) { return document.activeElement === p; });
4366
+ var pillsLength = pillsRef.current.length;
4367
+ if (isDelete || isBackspace) {
4368
+ if (disabled) {
4369
+ return;
4370
+ }
4371
+ handleRemovePill(pillsRef.current[focusedIndex], selectedValues[focusedIndex]);
4372
+ var nextIndex = focusedIndex + 1;
4373
+ if (nextIndex == pillsLength) {
4374
+ inputRef.current.focus();
4375
+ }
4376
+ else {
4377
+ pillsRef.current[nextIndex].focus();
4378
+ }
4379
+ }
4380
+ else if (isArrowLeft || isArrowRight) {
4381
+ var nextIndex = Math.max(focusedIndex + (isArrowLeft ? -1 : 1), 0);
4382
+ if (isArrowRight && nextIndex === pillsLength) {
4383
+ inputRef.current.focus();
4384
+ }
4385
+ else {
4386
+ pillsRef.current[nextIndex].focus();
4387
+ }
4388
+ }
4389
+ }, [disabled, pillsRef, handleRemovePill]);
4390
+ var handleSelectionChange = React.useCallback(function (_a) {
4391
+ var target = _a.target, value = _a.value, previousValue = _a.previousValue;
4392
+ if (!multiselect) {
4393
+ var listboxValue = (value === null || value === void 0 ? void 0 : value.toString()) || '';
4394
+ var listboxPreviousValue = (previousValue === null || previousValue === void 0 ? void 0 : previousValue.toString()) || '';
4395
+ // istanbul ignore else
4396
+ if (!isControlled) {
4397
+ setInputValue(listboxValue);
4398
+ }
4399
+ setSelectedValues([listboxValue]);
4400
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange({
4401
+ target: target,
4402
+ value: listboxValue,
4403
+ previousValue: listboxPreviousValue
4404
+ });
4405
+ }
4406
+ else {
4407
+ var listboxPreviousValue = previousValue;
4408
+ var listboxValue = value;
4409
+ var previousValueSet_1 = new Set(listboxPreviousValue);
4410
+ var valueSet_1 = new Set(listboxValue);
4411
+ var removedValues_1 = new Set(listboxPreviousValue.filter(function (v) { return !valueSet_1.has(v); }));
4412
+ var addedValues = listboxValue.filter(function (v) { return !previousValueSet_1.has(v); });
4413
+ var newSelectedValues = selectedValues
4414
+ .filter(function (v) { return !removedValues_1.has(v); })
4415
+ .concat(addedValues);
4416
+ // istanbul ignore else
4417
+ if (!isControlled) {
4418
+ setInputValue('');
4419
+ }
4420
+ setSelectedValues(newSelectedValues);
4421
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange({
4422
+ target: target,
4423
+ value: newSelectedValues,
4424
+ previousValue: selectedValues
4425
+ });
4426
+ }
4427
+ if (!multiselect) {
4428
+ setOpen(false);
4429
+ }
4430
+ }, [isControlled, multiselect, selectedValues, onSelectionChange]);
4233
4431
  var handleActiveChange = React.useCallback(function (option) {
4234
4432
  // istanbul ignore else
4235
4433
  if (option.element) {
@@ -4237,25 +4435,31 @@ var Combobox = React.forwardRef(function (_a, ref) {
4237
4435
  }
4238
4436
  onActiveChange === null || onActiveChange === void 0 ? void 0 : onActiveChange(option);
4239
4437
  }, []);
4240
- var NoMatchingOptions = React__default["default"].useMemo(function () {
4438
+ var NoMatchingOptions = React.useMemo(function () {
4241
4439
  return React__default["default"].isValidElement(renderNoResults)
4242
4440
  ? function () { return React__default["default"].createElement(ComboboxNoResults, null, renderNoResults); }
4243
4441
  : typeof renderNoResults === 'function'
4244
4442
  ? function () { return React__default["default"].createElement(ComboboxNoResults, null, renderNoResults()); }
4245
4443
  : ComboboxNoResults;
4246
4444
  }, [renderNoResults]);
4247
- var noMatchingOptions = !!(value === null || value === void 0 ? void 0 : value.length) && !matchingOptions.size && (React__default["default"].createElement(NoMatchingOptions, null));
4248
- var comboboxListbox = (React__default["default"].createElement(Listbox, { className: classNames__default["default"]('Combobox__listbox', {
4445
+ var noMatchingOptions = !!inputValue && !matchingOptions.size && (React__default["default"].createElement(NoMatchingOptions, null));
4446
+ var comboboxListbox = (
4447
+ // eslint-disable-next-line
4448
+ // @ts-expect-error
4449
+ // multiselect & value props are passed to Listbox, but TS is unable to infer that
4450
+ // it's a correct mapping from Combobox's multiselect & value props
4451
+ React__default["default"].createElement(Listbox, { className: classNames__default["default"]('Combobox__listbox', {
4249
4452
  'Combobox__listbox--open': open
4250
- }), role: noMatchingOptions ? 'presentation' : 'listbox', "aria-labelledby": noMatchingOptions ? undefined : "".concat(id, "-label"), id: "".concat(id, "-listbox"), value: selectedValue, onMouseDown: handleComboboxOptionMouseDown, onClick: handleComboboxOptionClick, onSelectionChange: handleSelectionChange, onActiveChange: handleActiveChange, ref: listboxRef, tabIndex: undefined, "aria-activedescendant": undefined },
4453
+ }), role: noMatchingOptions ? 'presentation' : 'listbox', "aria-labelledby": noMatchingOptions ? undefined : "".concat(id, "-label"), id: "".concat(id, "-listbox"), value: multiselect ? selectedValues : selectedValues[0], onMouseDown: handleComboboxOptionMouseDown, onClick: handleComboboxOptionClick, onSelectionChange: handleSelectionChange, onActiveChange: handleActiveChange, ref: listboxRef, tabIndex: undefined, "aria-activedescendant": undefined, multiselect: multiselect, disabled: disabled },
4251
4454
  comboboxOptions,
4252
4455
  noMatchingOptions));
4253
4456
  var errorId = "".concat(id, "-error");
4254
4457
  var inputProps = tslib.__assign(tslib.__assign({}, props), { 'aria-describedby': error
4255
4458
  ? addIdRef(ariaDescribedby, errorId)
4256
4459
  : ariaDescribedby });
4257
- return (React__default["default"].createElement("div", { id: id, className: classNames__default["default"]('Combobox', className), ref: comboboxRef },
4258
- name && React__default["default"].createElement("input", { type: "hidden", name: name, value: formValue }),
4460
+ return (React__default["default"].createElement("div", { id: id, className: classNames__default["default"]('Combobox', { 'Combobox--multiselect': multiselect }, className), ref: comboboxRef },
4461
+ name &&
4462
+ formValues.map(function (formValue, index) { return (React__default["default"].createElement("input", { type: "hidden", key: index, name: name, value: formValue })); }),
4259
4463
  React__default["default"].createElement("label", { className: classNames__default["default"]('Field__label', {
4260
4464
  'Field__label--is-required': isRequired,
4261
4465
  'Field__label--has-error': hasError
@@ -4266,9 +4470,24 @@ var Combobox = React.forwardRef(function (_a, ref) {
4266
4470
  // We're handling click here to open the listbox when the wrapping element is clicked,
4267
4471
  // there's already keyboard handlers to open the listbox on the input element
4268
4472
  onClick: handleInputClick },
4269
- 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 }, inputProps, { onChange: handleChange, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: handleBlur })),
4473
+ multiselect &&
4474
+ selectedValues.map(function (value, index) {
4475
+ var refCallback = function (elem) {
4476
+ if (elem) {
4477
+ pillsRef.current[index] = elem;
4478
+ }
4479
+ else {
4480
+ pillsRef.current.splice(index, 1);
4481
+ }
4482
+ };
4483
+ var handleClick = function () {
4484
+ return handleRemovePill(pillsRef.current[index], value);
4485
+ };
4486
+ return (React__default["default"].createElement(ComboboxPill, { ref: refCallback, key: value, value: value, removeOptionLabel: removeOptionLabels[index], disabled: disabled, onClick: handleClick, onKeyDown: handlePillKeyDown }));
4487
+ }),
4488
+ React__default["default"].createElement("input", tslib.__assign({ type: "text", id: "".concat(id, "-input"), ref: inputRef, value: inputValue, role: "combobox", disabled: disabled, "aria-autocomplete": !isAutoComplete ? 'none' : 'list', "aria-controls": "".concat(id, "-listbox"), "aria-expanded": open, "aria-haspopup": "listbox", "aria-activedescendant": open && activeDescendant ? activeDescendant.element.id : undefined }, inputProps, { onChange: handleChange, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: handleBlur })),
4270
4489
  React__default["default"].createElement("span", { className: "Combobox__arrow" })),
4271
- React__default["default"].createElement(ComboboxProvider, { autocomplete: autocomplete, inputValue: value, formValue: formValue, selectedValue: selectedValue, matches: !isAutoComplete || defaultAutoCompleteMatches, matchingOptions: matchingOptions, setMatchingOptions: setMatchingOptions, setFormValue: setFormValue }, portal && typeof document !== 'undefined'
4490
+ React__default["default"].createElement(ComboboxProvider, { autocomplete: autocomplete, inputValue: inputValue, formValues: formValues, selectedValues: selectedValues, removeOptionLabels: removeOptionLabels, setRemoveOptionLabels: setRemoveOptionLabels, matches: !isAutoComplete || defaultAutoCompleteMatches, matchingOptions: matchingOptions, setMatchingOptions: setMatchingOptions, setFormValues: setFormValues }, portal && typeof document !== 'undefined'
4272
4491
  ? reactDom.createPortal(comboboxListbox,
4273
4492
  // eslint-disable-next-line ssr-friendly/no-dom-globals-in-react-fc
4274
4493
  portal instanceof HTMLElement
@@ -4409,10 +4628,11 @@ function TimelineItem(_a) {
4409
4628
  }
4410
4629
 
4411
4630
  var TextEllipsis = React__default["default"].forwardRef(function (_a, ref) {
4412
- var className = _a.className, children = _a.children, maxLines = _a.maxLines, as = _a.as, tooltipProps = _a.tooltipProps, props = tslib.__rest(_a, ["className", "children", "maxLines", "as", "tooltipProps"]);
4631
+ var className = _a.className, children = _a.children, maxLines = _a.maxLines, as = _a.as, tooltipProps = _a.tooltipProps, hideTooltip = _a.hideTooltip, props = tslib.__rest(_a, ["className", "children", "maxLines", "as", "tooltipProps", "hideTooltip"]);
4413
4632
  var Element = 'div';
4414
4633
  var sharedRef = useSharedRef(ref);
4415
- var _b = tslib.__read(React.useState(false), 2), showTooltip = _b[0], setShowTooltip = _b[1];
4634
+ var _b = tslib.__read(React.useState(false), 2), hasOverflow = _b[0], setHasOverflow = _b[1];
4635
+ var showTooltip = hasOverflow && !hideTooltip;
4416
4636
  if (as) {
4417
4637
  Element = as;
4418
4638
  }
@@ -4427,16 +4647,18 @@ var TextEllipsis = React__default["default"].forwardRef(function (_a, ref) {
4427
4647
  props.style = tslib.__assign({ WebkitLineClamp: maxLines || 2 }, props.style);
4428
4648
  }
4429
4649
  React.useEffect(function () {
4650
+ if (hideTooltip) {
4651
+ return;
4652
+ }
4430
4653
  var listener = function () {
4431
4654
  requestAnimationFrame(function () {
4432
4655
  var overflowElement = sharedRef.current;
4433
4656
  if (!overflowElement) {
4434
4657
  return;
4435
4658
  }
4436
- var hasOverflow = typeof maxLines === 'number'
4659
+ setHasOverflow(typeof maxLines === 'number'
4437
4660
  ? overflowElement.clientHeight < overflowElement.scrollHeight
4438
- : overflowElement.clientWidth < overflowElement.scrollWidth;
4439
- setShowTooltip(hasOverflow);
4661
+ : overflowElement.clientWidth < overflowElement.scrollWidth);
4440
4662
  });
4441
4663
  };
4442
4664
  var observer = new ResizeObserver(listener);
@@ -4444,7 +4666,7 @@ var TextEllipsis = React__default["default"].forwardRef(function (_a, ref) {
4444
4666
  return function () {
4445
4667
  observer === null || observer === void 0 ? void 0 : observer.disconnect();
4446
4668
  };
4447
- }, []);
4669
+ }, [hideTooltip]);
4448
4670
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
4449
4671
  React__default["default"].createElement(Element, tslib.__assign({ className: classNames__default["default"]('TextEllipsis', className, {
4450
4672
  'TextEllipsis--multiline': !!maxLines
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deque/cauldron-react",
3
- "version": "6.15.0",
3
+ "version": "6.16.0",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Fully accessible react components library for Deque Cauldron",
6
6
  "homepage": "https://cauldron.dequelabs.com/",