@czi-sds/components 19.4.0 → 19.4.2

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.
@@ -4,6 +4,7 @@ import { AccordionProps as RawAccordionProps } from "@mui/material";
4
4
  import { AccordionSummaryProps as RawAccordionSummaryProps } from "@mui/material";
5
5
  import { AutocompleteChangeDetails as AutocompleteChangeDetails$0 } from "@mui/material";
6
6
  import { AutocompleteChangeReason as AutocompleteChangeReason$0 } from "@mui/material";
7
+ import { AutocompleteCloseReason as AutocompleteCloseReason$0 } from "@mui/material";
7
8
  import { AutocompleteValue as AutocompleteValue$0 } from "@mui/material";
8
9
  import { AutocompleteProps as MuiAutocompleteProps } from "@mui/material";
9
10
  import { TextFieldProps as RawTextFieldSearchProps } from "@mui/material";
@@ -34,7 +35,7 @@ import { ReactElement, ReactNode, SyntheticEvent, ComponentType } from "react";
34
35
  import { Theme, ThemeOptions, TypographyStyle, PaletteOptions } from "@mui/material/styles";
35
36
  import { SerializedStyles } from "@emotion/react";
36
37
  import { AlertProps } from "@mui/lab";
37
- import { AutocompleteChangeDetails, AutocompleteChangeReason, AutocompleteValue } from "@mui/base";
38
+ import { AutocompleteChangeDetails, AutocompleteChangeReason, AutocompleteCloseReason, AutocompleteValue } from "@mui/base";
38
39
  import { AlertTitleProps } from "@mui/material/AlertTitle";
39
40
  import { AutocompleteValue as AutocompleteValue$1 } from "@mui/material/useAutocomplete";
40
41
  declare const AccordionDetails: (props: AccordionDetailsProps) => import("react/jsx-runtime").JSX.Element;
@@ -439,6 +440,8 @@ interface ExtraAutocompleteProps<T, Multiple, DisableClearable, FreeSolo> extend
439
440
  onChange?: (event: React.SyntheticEvent, value: AutocompleteValue$0<T, Multiple, DisableClearable, FreeSolo>, reason: AutocompleteChangeReason$0, details?: AutocompleteChangeDetails$0<T>) => void;
440
441
  InputBaseProps?: Partial<InputSearchProps>;
441
442
  label?: string;
443
+ onClickAway?: (event?: MouseEvent | TouchEvent, reason?: AutocompleteCloseReason$0) => void;
444
+ onClick?: (event?: TouchEvent | MouseEvent) => void;
442
445
  }
443
446
  type CustomAutocompleteProps<T, Multiple extends boolean | undefined, DisableClearable extends boolean | undefined, FreeSolo extends boolean | undefined> = Omit<MuiAutocompleteProps<T, Multiple, DisableClearable, FreeSolo>, "renderInput" | "nonce" | "rev" | "rel" | "autoFocus" | "content">;
444
447
  type AutocompleteBaseProps<T, Multiple extends boolean | undefined, DisableClearable extends boolean | undefined, FreeSolo extends boolean | undefined> = CustomAutocompleteProps<T, Multiple, DisableClearable, FreeSolo> & ExtraAutocompleteProps<T, Multiple, DisableClearable, FreeSolo>;
@@ -472,7 +475,8 @@ interface ExtraAutocompleteMultiColumnProps<T, Multiple extends boolean | undefi
472
475
  PopperComponent?: React.JSXElementConstructor<PopperProps>;
473
476
  PopperPlacement?: "bottom-start" | "top-start" | "bottom-end" | "top-end";
474
477
  children?: JSX.Element | null;
475
- onClickAway?: (event: MouseEvent | TouchEvent) => void;
478
+ onClickAway?: (event?: MouseEvent | TouchEvent, reason?: AutocompleteCloseReason$0) => void;
479
+ onClick?: (event?: TouchEvent | MouseEvent) => void;
476
480
  ClickAwayListenerProps?: Partial<MUIClickAwayListenerProps>;
477
481
  options: AutocompleteMultiColumnOption<T, Multiple, DisableClearable, FreeSolo>[];
478
482
  value?: AutocompleteMultiColumnValue<T, Multiple, DisableClearable, FreeSolo>;
@@ -499,7 +503,8 @@ interface ExtraAutocompleteProps$0<T, Multiple extends boolean | undefined, Disa
499
503
  options: SDSAutocompleteOptions<T, Multiple, DisableClearable, FreeSolo>;
500
504
  PopperBaseProps?: Partial<PopperProps>;
501
505
  value?: SDSAutocompleteValue<T, Multiple, DisableClearable, FreeSolo>;
502
- onClickAway?: (event: MouseEvent | TouchEvent) => void;
506
+ onClickAway?: (event?: MouseEvent | TouchEvent, reason?: AutocompleteCloseReason) => void;
507
+ onClick?: (event?: TouchEvent | MouseEvent) => void;
503
508
  onChange?: SDSAutocompleteOnChange<T, Multiple, DisableClearable, FreeSolo>;
504
509
  count?: number;
505
510
  icon?: ReactElement;
package/dist/index.cjs.js CHANGED
@@ -3774,25 +3774,37 @@ var StyledMenuItemText = styles.styled("div")(templateObject_6$8 || (templateObj
3774
3774
  var templateObject_1$L, templateObject_2$t, templateObject_3$k, templateObject_4$f, templateObject_5$b, templateObject_6$8;
3775
3775
 
3776
3776
  var AutocompleteBase = function (props) {
3777
- var multiple = props.multiple, _a = props.disableCloseOnSelect, disableCloseOnSelect = _a === void 0 ? multiple : _a, _b = props.getOptionLabel, getOptionLabel = _b === void 0 ? defaultGetOptionLabel : _b, _c = props.InputBaseProps, InputBaseProps = _c === void 0 ? EMPTY_OBJECT : _c, _d = props.isOptionEqualToValue, isOptionEqualToValue = _d === void 0 ? defaultIsOptionEqualToValue : _d, _e = props.keepSearchOnSelect, keepSearchOnSelect = _e === void 0 ? false : _e, _f = props.label, label = _f === void 0 ? "Label" : _f, _g = props.loading, loading = _g === void 0 ? false : _g, _h = props.loadingText, loadingText = _h === void 0 ? "" : _h, _j = props.noOptionsText, noOptionsText = _j === void 0 ? "No options" : _j, _k = props.onInputChange, onInputChange = _k === void 0 ? noop : _k, _l = props.renderOption, renderOption = _l === void 0 ? defaultRenderOption : _l, _m = props.renderTags, renderTags = _m === void 0 ? defaultRenderTags : _m, _o = props.search, search = _o === void 0 ? false : _o, _p = props.clearOnBlur, clearOnBlur = _p === void 0 ? false : _p, _q = props.blurOnSelect, blurOnSelect = _q === void 0 ? !multiple : _q;
3777
+ var multiple = props.multiple, _a = props.disableCloseOnSelect, disableCloseOnSelect = _a === void 0 ? multiple : _a, _b = props.getOptionLabel, getOptionLabel = _b === void 0 ? defaultGetOptionLabel : _b, _c = props.InputBaseProps, InputBaseProps = _c === void 0 ? EMPTY_OBJECT : _c, _d = props.isOptionEqualToValue, isOptionEqualToValue = _d === void 0 ? defaultIsOptionEqualToValue : _d, _e = props.keepSearchOnSelect, keepSearchOnSelect = _e === void 0 ? false : _e, _f = props.label, label = _f === void 0 ? "Label" : _f, _g = props.loading, loading = _g === void 0 ? false : _g, _h = props.loadingText, loadingText = _h === void 0 ? "" : _h, _j = props.noOptionsText, noOptionsText = _j === void 0 ? "No options" : _j, _k = props.onInputChange, onInputChange = _k === void 0 ? noop : _k, _l = props.renderOption, renderOption = _l === void 0 ? defaultRenderOption : _l, _m = props.renderTags, renderTags = _m === void 0 ? defaultRenderTags : _m, _o = props.search, search = _o === void 0 ? false : _o, _p = props.clearOnBlur, clearOnBlur = _p === void 0 ? false : _p, _q = props.blurOnSelect, blurOnSelect = _q === void 0 ? !multiple : _q, onClickAway = props.onClickAway, onClick = props.onClick, onOpen = props.onOpen, onClose = props.onClose;
3778
3778
  var theme = styles.useTheme();
3779
3779
  var _r = React.useState(""), inputValue = _r[0], setInputValue = _r[1];
3780
- return (jsxRuntime.jsx(StyledAutocompleteBase, __assign({ clearOnBlur: clearOnBlur, disableCloseOnSelect: disableCloseOnSelect, disablePortal: true, renderTags: renderTags, loading: loading, loadingText: loadingText, noOptionsText: noOptionsText, PaperComponent: StyledPaper$3, PopperComponent: useDefaultPopperComponent(), renderOption: renderOption, getOptionLabel: getOptionLabel, isOptionEqualToValue: isOptionEqualToValue, inputValue: inputValue, renderInput: defaultRenderInput, multiple: multiple }, props, {
3781
- // (masoudmanson): For multiple options (multiple = true), setting blurOnSelect to false
3782
- // keeps the dropdown open after selecting an option. This feature enhances user experience
3783
- // by preventing the dropdown from closing, enabling users to select multiple options
3784
- // without having to reopen the menu repeatedly.
3780
+ return (jsxRuntime.jsx(StyledAutocompleteBase, __assign({ clearOnBlur: clearOnBlur, disableCloseOnSelect: disableCloseOnSelect, disablePortal: true, renderTags: renderTags, loading: loading, loadingText: loadingText, noOptionsText: noOptionsText, PaperComponent: StyledPaper$3, PopperComponent: useDefaultPopperComponent(), renderOption: renderOption, getOptionLabel: getOptionLabel, isOptionEqualToValue: isOptionEqualToValue, inputValue: inputValue, renderInput: defaultRenderInput, multiple: multiple,
3781
+ /**
3782
+ * (masoudmanson): Overrides the onOpen and onClose handlers to ensure that
3783
+ * the onClick and onClickAway handlers are triggered when a controlled dropdown
3784
+ * is opened or closed, respectively.
3785
+ */
3786
+ onOpen: defaultOnOpen, onClose: defaultOnClose }, props, {
3787
+ /**
3788
+ * (masoudmanson): For multiple options (multiple = true), setting blurOnSelect to false
3789
+ * keeps the dropdown open after selecting an option. This feature enhances user experience
3790
+ * by preventing the dropdown from closing, enabling users to select multiple options
3791
+ * without having to reopen the menu repeatedly.
3792
+ */
3785
3793
  blurOnSelect: multiple ? false : blurOnSelect,
3786
- // (masoudmanson): Given the necessity of maintaining consistent onBlur functionality,
3787
- // and clearing the input value on blur, it's crucial to include the onBlur handler
3788
- // after spreading other props. Furthermore, within the defaultOnBlur function, the
3789
- // actual onBlur function is invoked for completeness.
3794
+ /**
3795
+ * (masoudmanson): Given the necessity of maintaining consistent onBlur functionality,
3796
+ * and clearing the input value on blur, it's crucial to include the onBlur handler
3797
+ * after spreading other props. Furthermore, within the defaultOnBlur function, the
3798
+ * actual onBlur function is invoked for completeness.
3799
+ */
3790
3800
  onBlur: defaultOnBlur,
3791
- // (masoudmanson): To ensure component-level actions (changing the input field value)
3792
- // trigger upon input changes, it's crucial to position the onInputChange handler after
3793
- // spreading the other props. Furthermore, within the defaultOnInputChange function,
3794
- // the provided onInputChange from props is called at the end to emit the input changes
3795
- // to the user.
3801
+ /**
3802
+ * (masoudmanson): To ensure component-level actions (changing the input field value)
3803
+ * trigger upon input changes, it's crucial to position the onInputChange handler after
3804
+ * spreading the other props. Furthermore, within the defaultOnInputChange function,
3805
+ * the provided onInputChange from props is called at the end to emit the input changes
3806
+ * to the user.
3807
+ */
3796
3808
  onInputChange: defaultOnInputChange })));
3797
3809
  /**
3798
3810
  * (masoudmanson): Using a custom Popper or Paper with the Autocomplete
@@ -3836,6 +3848,24 @@ var AutocompleteBase = function (props) {
3836
3848
  setInputValue("");
3837
3849
  (_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, event);
3838
3850
  }
3851
+ /**
3852
+ * (masoudmanson): The default onOpen handler is the Callback fired when the popup
3853
+ * requests to be opened. This function is responsible for invoking the onOpen and onClick
3854
+ * handlers when a controlled dropdown is opening.
3855
+ */
3856
+ function defaultOnOpen(event) {
3857
+ onOpen === null || onOpen === void 0 ? void 0 : onOpen(event);
3858
+ onClick === null || onClick === void 0 ? void 0 : onClick(event);
3859
+ }
3860
+ /**
3861
+ * (masoudmanson): The default onClose handler is the callback fired when the popup
3862
+ * requests to be closed. This function is responsible for invoking the onClose and onClickAway
3863
+ * handlers when a controlled dropdown is closing.
3864
+ */
3865
+ function defaultOnClose(event, reason) {
3866
+ onClose === null || onClose === void 0 ? void 0 : onClose(event, reason);
3867
+ onClickAway === null || onClickAway === void 0 ? void 0 : onClickAway(event, reason);
3868
+ }
3839
3869
  function defaultOnInputChange(event, value, reason) {
3840
3870
  if (!multiple) {
3841
3871
  if (reason === "input") {
@@ -3989,16 +4019,26 @@ var templateObject_1$J, templateObject_2$r, templateObject_3$i, templateObject_4
3989
4019
 
3990
4020
  var AutocompleteMultiColumn = function (props) {
3991
4021
  var _a;
3992
- var InputBaseProps = props.InputBaseProps, _b = props.open, open = _b === void 0 ? false : _b, _c = props.PopperPlacement, PopperPlacement = _c === void 0 ? "bottom-start" : _c, PopperBaseProps = props.PopperBaseProps, _d = props.search, search = _d === void 0 ? false : _d, _e = props.label, label = _e === void 0 ? "Search" : _e, _f = props.onClickAway, onClickAway = _f === void 0 ? defaultOnClickAway : _f, ClickAwayListenerProps = props.ClickAwayListenerProps, options = props.options, onInputChange = props.onInputChange, onBlur = props.onBlur, multiple = props.multiple, parentInitialValue = props.value, onChange = props.onChange, _g = props.PopperComponent, PopperComponent = _g === void 0 ? StyledPopper$2 : _g, rest = __rest(props, ["InputBaseProps", "open", "PopperPlacement", "PopperBaseProps", "search", "label", "onClickAway", "ClickAwayListenerProps", "options", "onInputChange", "onBlur", "multiple", "value", "onChange", "PopperComponent"]);
4022
+ var InputBaseProps = props.InputBaseProps, open = props.open, _b = props.PopperPlacement, PopperPlacement = _b === void 0 ? "bottom-start" : _b, PopperBaseProps = props.PopperBaseProps, _c = props.search, search = _c === void 0 ? false : _c, _d = props.label, label = _d === void 0 ? "Search" : _d, onClickAway = props.onClickAway, onClick = props.onClick, ClickAwayListenerProps = props.ClickAwayListenerProps, options = props.options, onInputChange = props.onInputChange, onBlur = props.onBlur, multiple = props.multiple, parentInitialValue = props.value, onChange = props.onChange, _e = props.PopperComponent, PopperComponent = _e === void 0 ? StyledPopper$2 : _e, rest = __rest(props, ["InputBaseProps", "open", "PopperPlacement", "PopperBaseProps", "search", "label", "onClickAway", "onClick", "ClickAwayListenerProps", "options", "onInputChange", "onBlur", "multiple", "value", "onChange", "PopperComponent"]);
3993
4023
  var theme = styles.useTheme();
3994
- var _h = React.useState(""), inputValue = _h[0], setInputValue = _h[1];
3995
- var _j = React.useState(open), popperOpen = _j[0], setPopperOpen = _j[1];
4024
+ var isOpenControlled = open !== undefined;
4025
+ var _f = React.useState(""), inputValue = _f[0], setInputValue = _f[1];
4026
+ var _g = React.useState(isOpenControlled ? open : false), popperOpen = _g[0], setPopperOpen = _g[1];
4027
+ /**
4028
+ * (masoudmanson): This useEffect is used to update the popperOpen state
4029
+ * when the open prop is controlled.
4030
+ */
4031
+ React.useEffect(function () {
4032
+ if (isOpenControlled) {
4033
+ setPopperOpen(open);
4034
+ }
4035
+ }, [isOpenControlled, open]);
3996
4036
  var anchorRef = React.useRef(null);
3997
- var _k = React.useState(null), anchorEl = _k[0], setAnchorEl = _k[1];
4037
+ var _h = React.useState(null), anchorEl = _h[0], setAnchorEl = _h[1];
3998
4038
  React.useEffect(function () {
3999
4039
  setAnchorEl(anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current);
4000
4040
  }, [anchorRef]);
4001
- var _l = React.useState({}), autocompleteMultiColumnValue = _l[0], setAutocompleteMultiColumnValue = _l[1];
4041
+ var _j = React.useState({}), autocompleteMultiColumnValue = _j[0], setAutocompleteMultiColumnValue = _j[1];
4002
4042
  React.useEffect(function () {
4003
4043
  if (parentInitialValue !== undefined) {
4004
4044
  setAutocompleteMultiColumnValue(parentInitialValue);
@@ -4012,7 +4052,7 @@ var AutocompleteMultiColumn = function (props) {
4012
4052
  });
4013
4053
  onChange === null || onChange === void 0 ? void 0 : onChange(event, __assign(__assign({}, autocompleteMultiColumnValue), (_a = {}, _a[column] = val, _a)), reason, details);
4014
4054
  };
4015
- return (jsxRuntime.jsx(material.ClickAwayListener, __assign({ onClickAway: onClickAway }, ClickAwayListenerProps, { children: jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx(StyledAutocompleteInput, __assign({ id: "location-search", label: label, placeholder: label, value: inputValue, onChange: handleInputChange, onClick: handleInputClick, onBlur: handleInputBlur, ref: anchorRef, search: search, onKeyDown: handleInputKeyDown, InputProps: __assign(__assign({}, InputBaseProps === null || InputBaseProps === void 0 ? void 0 : InputBaseProps.ref), { endAdornment: (jsxRuntime.jsxs(StyledInputAdornment, { position: "end", children: [inputValue && (jsxRuntime.jsx(ButtonIcon, { "aria-label": "clear-button", className: "input-search-clear-icon", sdsType: "primary", sdsSize: "small", sdsIconProps: {
4055
+ return (jsxRuntime.jsx(material.ClickAwayListener, __assign({ onClickAway: defaultOnClickAway }, ClickAwayListenerProps, { children: jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx(StyledAutocompleteInput, __assign({ id: "location-search", label: label, placeholder: label, value: inputValue, onChange: handleInputChange, onClick: handleInputClick, onBlur: handleInputBlur, ref: anchorRef, search: search, onKeyDown: handleInputKeyDown, InputProps: __assign(__assign({}, InputBaseProps === null || InputBaseProps === void 0 ? void 0 : InputBaseProps.ref), { endAdornment: (jsxRuntime.jsxs(StyledInputAdornment, { position: "end", children: [inputValue && (jsxRuntime.jsx(ButtonIcon, { "aria-label": "clear-button", className: "input-search-clear-icon", sdsType: "primary", sdsSize: "small", sdsIconProps: {
4016
4056
  sdsType: "iconButton",
4017
4057
  }, icon: "xMark", onClick: clearInput })), jsxRuntime.jsx(ButtonIcon, { "aria-label": "search-button", sdsType: "secondary", sdsSize: "small", sdsIconProps: {
4018
4058
  sdsType: "interactive",
@@ -4039,7 +4079,22 @@ var AutocompleteMultiColumn = function (props) {
4039
4079
  */
4040
4080
  onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange({ target: { value: "" } }, "", "clear");
4041
4081
  }
4042
- function handleInputClick(_) {
4082
+ function handleInputClick(event) {
4083
+ /**
4084
+ * (masoudmanson): Because the Autocomplete component overrides the
4085
+ * InputSearch's onClick, we must also include the parent onClick here.
4086
+ */
4087
+ onClick === null || onClick === void 0 ? void 0 : onClick(event);
4088
+ /**
4089
+ * (masoudmanson): If the dropdown is controlled, we call the onClick prop to allow the parent
4090
+ * to handle the opening and closing of the dropdown.
4091
+ */
4092
+ if (isOpenControlled) {
4093
+ return;
4094
+ }
4095
+ /**
4096
+ * (masoudmanson): If the dropdown is not controlled, we toggle the dropdown open and closed.
4097
+ */
4043
4098
  if (popperOpen) {
4044
4099
  setPopperOpen(false);
4045
4100
  }
@@ -4063,13 +4118,55 @@ var AutocompleteMultiColumn = function (props) {
4063
4118
  setInputValue("");
4064
4119
  onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
4065
4120
  }
4066
- function defaultOnClickAway() {
4067
- setPopperOpen(false);
4121
+ /**
4122
+ * (masoudmanson): This is the default onClickAway handler for the Autocomplete component.
4123
+ * It is used to close the dropdown when the user clicks away from the dropdown. It also
4124
+ * calls the parent onClickAway prop if it is provided.
4125
+ */
4126
+ function defaultOnClickAway(event) {
4127
+ /**
4128
+ * (masoudmanson): We only want to close the dropdown if it is open.
4129
+ * This may sound unnecessary, but it is to prevent the dropdown from
4130
+ * calling the parent onClickAway prop when the dropdown is closed.
4131
+ */
4132
+ if (popperOpen) {
4133
+ onClickAway === null || onClickAway === void 0 ? void 0 : onClickAway(event, "blur");
4134
+ /**
4135
+ * (masoudmanson): If the dropdown is controlled, we call the onClickAway prop to allow the parent
4136
+ * to handle the closing of the dropdown.
4137
+ */
4138
+ if (isOpenControlled)
4139
+ return;
4140
+ // (masoudmanson): If the dropdown is not controlled, we close the dropdown.
4141
+ setPopperOpen(false);
4142
+ }
4068
4143
  }
4069
4144
  function handleInputKeyDown(event) {
4070
- // (masoudmanson): This prevents Backspace from deselecting selected dropdown options.
4071
- if (event.key === "Backspace") {
4072
- event.stopPropagation();
4145
+ var _a;
4146
+ /**
4147
+ * (masoudmanson): Because the Autocomplete component overrides the
4148
+ * InputSearch's onKeyDown, we must also include the user defined onKeyDown here.
4149
+ */
4150
+ if (props === null || props === void 0 ? void 0 : props.onKeyDown) {
4151
+ (_a = props === null || props === void 0 ? void 0 : props.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(props, event);
4152
+ }
4153
+ else {
4154
+ // (masoudmanson): This prevents Backspace from deselecting selected dropdown options.
4155
+ if (event.key === "Backspace") {
4156
+ event.stopPropagation();
4157
+ }
4158
+ /**
4159
+ * (masoudmanson): This is to handle the Escape key to close the dropdown.
4160
+ * If the dropdown is controlled, we call the onClick prop to allow the parent
4161
+ * to handle the closing of the dropdown.
4162
+ */
4163
+ if (event.key === "Escape") {
4164
+ if (isOpenControlled) {
4165
+ onClick === null || onClick === void 0 ? void 0 : onClick();
4166
+ return;
4167
+ }
4168
+ setPopperOpen(false);
4169
+ }
4073
4170
  }
4074
4171
  }
4075
4172
  };
@@ -4081,7 +4178,7 @@ var Autocomplete = function (props) {
4081
4178
  if (options.length > 1) {
4082
4179
  return (jsxRuntime.jsx(AutocompleteMultiColumn, __assign({ options: options, value: value, onChange: onChange }, rest, {
4083
4180
  // (masoudmanson): groupBy option is disabled on MultiColumn dropdowns
4084
- groupBy: undefined, open: true })));
4181
+ groupBy: undefined })));
4085
4182
  }
4086
4183
  else {
4087
4184
  return (jsxRuntime.jsx(AutocompleteBase, __assign({ options: options[0].options, value: value, onChange: onChange }, rest)));
@@ -4804,7 +4901,7 @@ var DropdownMenu = function (props) {
4804
4901
  ], open: open, anchorEl: anchorEl, placement: PopperPlacement }, PopperBaseProps, {
4805
4902
  // (masoudmanson): To override the width of the Popper,
4806
4903
  // the sx prop's value must be set after spreading the PopperBaseProps.
4807
- sx: dropdownMenuPopperSx, children: jsxRuntime.jsx(PaperComponent, { children: jsxRuntime.jsx(material.ClickAwayListener, __assign({ onClickAway: onClickAway }, ClickAwayListenerProps, { children: jsxRuntime.jsxs(StyledDropdownMenuAutocompleteWrapper, { children: [title && (jsxRuntime.jsx(StyledHeaderTitle, { search: search, children: title })), anchorEl && (jsxRuntime.jsx(Autocomplete, __assign({ label: label, search: search, title: title, open: open, options: options, PopperBaseProps: DEFAULT_POPPER_BASE_PROPS, disablePortal: true, onClickAway: noop }, rest, { InputBaseProps: DefaultInputBaseProps }))), children] }) })) }) })));
4904
+ sx: dropdownMenuPopperSx, children: jsxRuntime.jsx(PaperComponent, { children: jsxRuntime.jsx(material.ClickAwayListener, __assign({ onClickAway: onClickAway }, ClickAwayListenerProps, { children: jsxRuntime.jsxs(StyledDropdownMenuAutocompleteWrapper, { children: [title && (jsxRuntime.jsx(StyledHeaderTitle, { search: search, children: title })), anchorEl && (jsxRuntime.jsx(Autocomplete, __assign({ label: label, search: search, title: title, open: open, options: options, PopperBaseProps: DEFAULT_POPPER_BASE_PROPS, disablePortal: true, onClickAway: noop, onClick: noop }, rest, { InputBaseProps: DefaultInputBaseProps }))), children] }) })) }) })));
4808
4905
  };
4809
4906
 
4810
4907
  var labelFontBodyS = fontBody("s");
@@ -5345,7 +5442,7 @@ var Dropdown = function (props) {
5345
5442
  // which by default will not close on blur. If closeOnBlur is enabled, clicking out
5346
5443
  // is equivalent to clicking the Cancel button, closing the dropdown and losing
5347
5444
  // unapplied changes.
5348
- closeOnBlur = _f === void 0 ? !buttons : _f, onClose = props.onClose, onChange = props.onChange, _g = props.DropdownMenuProps, DropdownMenuProps = _g === void 0 ? {} : _g, _h = props.InputDropdownProps, InputDropdownProps = _h === void 0 ? { sdsStyle: "minimal" } : _h, _j = props.InputDropdownComponent, InputDropdownComponent = _j === void 0 ? InputDropdown : _j, _k = props.isTriggerChangeOnOptionClick, isTriggerChangeOnOptionClick = _k === void 0 ? false : _k, _l = props.disabled, disabled = _l === void 0 ? false : _l, propValue = props.value, rest = __rest(props, ["options", "label", "multiple", "search", "buttonPosition", "buttons", "closeOnBlur", "onClose", "onChange", "DropdownMenuProps", "InputDropdownProps", "InputDropdownComponent", "isTriggerChangeOnOptionClick", "disabled", "value"]);
5445
+ closeOnBlur = _f === void 0 ? !buttons : _f, onClose = props.onClose, onChange = props.onChange, _g = props.DropdownMenuProps, DropdownMenuProps = _g === void 0 ? {} : _g, _h = props.InputDropdownProps, InputDropdownProps = _h === void 0 ? { sdsStyle: "minimal" } : _h, _j = props.InputDropdownComponent, InputDropdownComponent = _j === void 0 ? InputDropdown : _j, _k = props.isTriggerChangeOnOptionClick, isTriggerChangeOnOptionClick = _k === void 0 ? false : _k, _l = props.disabled, disabled = _l === void 0 ? false : _l, propValue = props.value, onClick = props.onClick, rest = __rest(props, ["options", "label", "multiple", "search", "buttonPosition", "buttons", "closeOnBlur", "onClose", "onChange", "DropdownMenuProps", "InputDropdownProps", "InputDropdownComponent", "isTriggerChangeOnOptionClick", "disabled", "value", "onClick"]);
5349
5446
  if (buttons && !multiple) {
5350
5447
  // eslint-disable-next-line no-console
5351
5448
  console.warn("Warning: buttons are only supported for multiple select dropdowns.");
@@ -5395,6 +5492,7 @@ var Dropdown = function (props) {
5395
5492
  }
5396
5493
  }
5397
5494
  function handleClick(event) {
5495
+ onClick === null || onClick === void 0 ? void 0 : onClick(event);
5398
5496
  if (open) {
5399
5497
  if (!shouldShowButtons) {
5400
5498
  if (multiple) {
@@ -4,6 +4,7 @@ import { AccordionProps as RawAccordionProps } from "@mui/material";
4
4
  import { AccordionSummaryProps as RawAccordionSummaryProps } from "@mui/material";
5
5
  import { AutocompleteChangeDetails as AutocompleteChangeDetails$0 } from "@mui/material";
6
6
  import { AutocompleteChangeReason as AutocompleteChangeReason$0 } from "@mui/material";
7
+ import { AutocompleteCloseReason as AutocompleteCloseReason$0 } from "@mui/material";
7
8
  import { AutocompleteValue as AutocompleteValue$0 } from "@mui/material";
8
9
  import { AutocompleteProps as MuiAutocompleteProps } from "@mui/material";
9
10
  import { TextFieldProps as RawTextFieldSearchProps } from "@mui/material";
@@ -34,7 +35,7 @@ import { ReactElement, ReactNode, SyntheticEvent, ComponentType } from "react";
34
35
  import { Theme, ThemeOptions, TypographyStyle, PaletteOptions } from "@mui/material/styles";
35
36
  import { SerializedStyles } from "@emotion/react";
36
37
  import { AlertProps } from "@mui/lab";
37
- import { AutocompleteChangeDetails, AutocompleteChangeReason, AutocompleteValue } from "@mui/base";
38
+ import { AutocompleteChangeDetails, AutocompleteChangeReason, AutocompleteCloseReason, AutocompleteValue } from "@mui/base";
38
39
  import { AlertTitleProps } from "@mui/material/AlertTitle";
39
40
  import { AutocompleteValue as AutocompleteValue$1 } from "@mui/material/useAutocomplete";
40
41
  declare const AccordionDetails: (props: AccordionDetailsProps) => import("react/jsx-runtime").JSX.Element;
@@ -439,6 +440,8 @@ interface ExtraAutocompleteProps<T, Multiple, DisableClearable, FreeSolo> extend
439
440
  onChange?: (event: React.SyntheticEvent, value: AutocompleteValue$0<T, Multiple, DisableClearable, FreeSolo>, reason: AutocompleteChangeReason$0, details?: AutocompleteChangeDetails$0<T>) => void;
440
441
  InputBaseProps?: Partial<InputSearchProps>;
441
442
  label?: string;
443
+ onClickAway?: (event?: MouseEvent | TouchEvent, reason?: AutocompleteCloseReason$0) => void;
444
+ onClick?: (event?: TouchEvent | MouseEvent) => void;
442
445
  }
443
446
  type CustomAutocompleteProps<T, Multiple extends boolean | undefined, DisableClearable extends boolean | undefined, FreeSolo extends boolean | undefined> = Omit<MuiAutocompleteProps<T, Multiple, DisableClearable, FreeSolo>, "renderInput" | "nonce" | "rev" | "rel" | "autoFocus" | "content">;
444
447
  type AutocompleteBaseProps<T, Multiple extends boolean | undefined, DisableClearable extends boolean | undefined, FreeSolo extends boolean | undefined> = CustomAutocompleteProps<T, Multiple, DisableClearable, FreeSolo> & ExtraAutocompleteProps<T, Multiple, DisableClearable, FreeSolo>;
@@ -472,7 +475,8 @@ interface ExtraAutocompleteMultiColumnProps<T, Multiple extends boolean | undefi
472
475
  PopperComponent?: React.JSXElementConstructor<PopperProps>;
473
476
  PopperPlacement?: "bottom-start" | "top-start" | "bottom-end" | "top-end";
474
477
  children?: JSX.Element | null;
475
- onClickAway?: (event: MouseEvent | TouchEvent) => void;
478
+ onClickAway?: (event?: MouseEvent | TouchEvent, reason?: AutocompleteCloseReason$0) => void;
479
+ onClick?: (event?: TouchEvent | MouseEvent) => void;
476
480
  ClickAwayListenerProps?: Partial<MUIClickAwayListenerProps>;
477
481
  options: AutocompleteMultiColumnOption<T, Multiple, DisableClearable, FreeSolo>[];
478
482
  value?: AutocompleteMultiColumnValue<T, Multiple, DisableClearable, FreeSolo>;
@@ -499,7 +503,8 @@ interface ExtraAutocompleteProps$0<T, Multiple extends boolean | undefined, Disa
499
503
  options: SDSAutocompleteOptions<T, Multiple, DisableClearable, FreeSolo>;
500
504
  PopperBaseProps?: Partial<PopperProps>;
501
505
  value?: SDSAutocompleteValue<T, Multiple, DisableClearable, FreeSolo>;
502
- onClickAway?: (event: MouseEvent | TouchEvent) => void;
506
+ onClickAway?: (event?: MouseEvent | TouchEvent, reason?: AutocompleteCloseReason) => void;
507
+ onClick?: (event?: TouchEvent | MouseEvent) => void;
503
508
  onChange?: SDSAutocompleteOnChange<T, Multiple, DisableClearable, FreeSolo>;
504
509
  count?: number;
505
510
  icon?: ReactElement;
package/dist/index.esm.js CHANGED
@@ -3754,25 +3754,37 @@ var StyledMenuItemText = styled("div")(templateObject_6$8 || (templateObject_6$8
3754
3754
  var templateObject_1$L, templateObject_2$t, templateObject_3$k, templateObject_4$f, templateObject_5$b, templateObject_6$8;
3755
3755
 
3756
3756
  var AutocompleteBase = function (props) {
3757
- var multiple = props.multiple, _a = props.disableCloseOnSelect, disableCloseOnSelect = _a === void 0 ? multiple : _a, _b = props.getOptionLabel, getOptionLabel = _b === void 0 ? defaultGetOptionLabel : _b, _c = props.InputBaseProps, InputBaseProps = _c === void 0 ? EMPTY_OBJECT : _c, _d = props.isOptionEqualToValue, isOptionEqualToValue = _d === void 0 ? defaultIsOptionEqualToValue : _d, _e = props.keepSearchOnSelect, keepSearchOnSelect = _e === void 0 ? false : _e, _f = props.label, label = _f === void 0 ? "Label" : _f, _g = props.loading, loading = _g === void 0 ? false : _g, _h = props.loadingText, loadingText = _h === void 0 ? "" : _h, _j = props.noOptionsText, noOptionsText = _j === void 0 ? "No options" : _j, _k = props.onInputChange, onInputChange = _k === void 0 ? noop : _k, _l = props.renderOption, renderOption = _l === void 0 ? defaultRenderOption : _l, _m = props.renderTags, renderTags = _m === void 0 ? defaultRenderTags : _m, _o = props.search, search = _o === void 0 ? false : _o, _p = props.clearOnBlur, clearOnBlur = _p === void 0 ? false : _p, _q = props.blurOnSelect, blurOnSelect = _q === void 0 ? !multiple : _q;
3757
+ var multiple = props.multiple, _a = props.disableCloseOnSelect, disableCloseOnSelect = _a === void 0 ? multiple : _a, _b = props.getOptionLabel, getOptionLabel = _b === void 0 ? defaultGetOptionLabel : _b, _c = props.InputBaseProps, InputBaseProps = _c === void 0 ? EMPTY_OBJECT : _c, _d = props.isOptionEqualToValue, isOptionEqualToValue = _d === void 0 ? defaultIsOptionEqualToValue : _d, _e = props.keepSearchOnSelect, keepSearchOnSelect = _e === void 0 ? false : _e, _f = props.label, label = _f === void 0 ? "Label" : _f, _g = props.loading, loading = _g === void 0 ? false : _g, _h = props.loadingText, loadingText = _h === void 0 ? "" : _h, _j = props.noOptionsText, noOptionsText = _j === void 0 ? "No options" : _j, _k = props.onInputChange, onInputChange = _k === void 0 ? noop : _k, _l = props.renderOption, renderOption = _l === void 0 ? defaultRenderOption : _l, _m = props.renderTags, renderTags = _m === void 0 ? defaultRenderTags : _m, _o = props.search, search = _o === void 0 ? false : _o, _p = props.clearOnBlur, clearOnBlur = _p === void 0 ? false : _p, _q = props.blurOnSelect, blurOnSelect = _q === void 0 ? !multiple : _q, onClickAway = props.onClickAway, onClick = props.onClick, onOpen = props.onOpen, onClose = props.onClose;
3758
3758
  var theme = useTheme();
3759
3759
  var _r = useState(""), inputValue = _r[0], setInputValue = _r[1];
3760
- return (jsx(StyledAutocompleteBase, __assign({ clearOnBlur: clearOnBlur, disableCloseOnSelect: disableCloseOnSelect, disablePortal: true, renderTags: renderTags, loading: loading, loadingText: loadingText, noOptionsText: noOptionsText, PaperComponent: StyledPaper$3, PopperComponent: useDefaultPopperComponent(), renderOption: renderOption, getOptionLabel: getOptionLabel, isOptionEqualToValue: isOptionEqualToValue, inputValue: inputValue, renderInput: defaultRenderInput, multiple: multiple }, props, {
3761
- // (masoudmanson): For multiple options (multiple = true), setting blurOnSelect to false
3762
- // keeps the dropdown open after selecting an option. This feature enhances user experience
3763
- // by preventing the dropdown from closing, enabling users to select multiple options
3764
- // without having to reopen the menu repeatedly.
3760
+ return (jsx(StyledAutocompleteBase, __assign({ clearOnBlur: clearOnBlur, disableCloseOnSelect: disableCloseOnSelect, disablePortal: true, renderTags: renderTags, loading: loading, loadingText: loadingText, noOptionsText: noOptionsText, PaperComponent: StyledPaper$3, PopperComponent: useDefaultPopperComponent(), renderOption: renderOption, getOptionLabel: getOptionLabel, isOptionEqualToValue: isOptionEqualToValue, inputValue: inputValue, renderInput: defaultRenderInput, multiple: multiple,
3761
+ /**
3762
+ * (masoudmanson): Overrides the onOpen and onClose handlers to ensure that
3763
+ * the onClick and onClickAway handlers are triggered when a controlled dropdown
3764
+ * is opened or closed, respectively.
3765
+ */
3766
+ onOpen: defaultOnOpen, onClose: defaultOnClose }, props, {
3767
+ /**
3768
+ * (masoudmanson): For multiple options (multiple = true), setting blurOnSelect to false
3769
+ * keeps the dropdown open after selecting an option. This feature enhances user experience
3770
+ * by preventing the dropdown from closing, enabling users to select multiple options
3771
+ * without having to reopen the menu repeatedly.
3772
+ */
3765
3773
  blurOnSelect: multiple ? false : blurOnSelect,
3766
- // (masoudmanson): Given the necessity of maintaining consistent onBlur functionality,
3767
- // and clearing the input value on blur, it's crucial to include the onBlur handler
3768
- // after spreading other props. Furthermore, within the defaultOnBlur function, the
3769
- // actual onBlur function is invoked for completeness.
3774
+ /**
3775
+ * (masoudmanson): Given the necessity of maintaining consistent onBlur functionality,
3776
+ * and clearing the input value on blur, it's crucial to include the onBlur handler
3777
+ * after spreading other props. Furthermore, within the defaultOnBlur function, the
3778
+ * actual onBlur function is invoked for completeness.
3779
+ */
3770
3780
  onBlur: defaultOnBlur,
3771
- // (masoudmanson): To ensure component-level actions (changing the input field value)
3772
- // trigger upon input changes, it's crucial to position the onInputChange handler after
3773
- // spreading the other props. Furthermore, within the defaultOnInputChange function,
3774
- // the provided onInputChange from props is called at the end to emit the input changes
3775
- // to the user.
3781
+ /**
3782
+ * (masoudmanson): To ensure component-level actions (changing the input field value)
3783
+ * trigger upon input changes, it's crucial to position the onInputChange handler after
3784
+ * spreading the other props. Furthermore, within the defaultOnInputChange function,
3785
+ * the provided onInputChange from props is called at the end to emit the input changes
3786
+ * to the user.
3787
+ */
3776
3788
  onInputChange: defaultOnInputChange })));
3777
3789
  /**
3778
3790
  * (masoudmanson): Using a custom Popper or Paper with the Autocomplete
@@ -3816,6 +3828,24 @@ var AutocompleteBase = function (props) {
3816
3828
  setInputValue("");
3817
3829
  (_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, event);
3818
3830
  }
3831
+ /**
3832
+ * (masoudmanson): The default onOpen handler is the Callback fired when the popup
3833
+ * requests to be opened. This function is responsible for invoking the onOpen and onClick
3834
+ * handlers when a controlled dropdown is opening.
3835
+ */
3836
+ function defaultOnOpen(event) {
3837
+ onOpen === null || onOpen === void 0 ? void 0 : onOpen(event);
3838
+ onClick === null || onClick === void 0 ? void 0 : onClick(event);
3839
+ }
3840
+ /**
3841
+ * (masoudmanson): The default onClose handler is the callback fired when the popup
3842
+ * requests to be closed. This function is responsible for invoking the onClose and onClickAway
3843
+ * handlers when a controlled dropdown is closing.
3844
+ */
3845
+ function defaultOnClose(event, reason) {
3846
+ onClose === null || onClose === void 0 ? void 0 : onClose(event, reason);
3847
+ onClickAway === null || onClickAway === void 0 ? void 0 : onClickAway(event, reason);
3848
+ }
3819
3849
  function defaultOnInputChange(event, value, reason) {
3820
3850
  if (!multiple) {
3821
3851
  if (reason === "input") {
@@ -3969,16 +3999,26 @@ var templateObject_1$J, templateObject_2$r, templateObject_3$i, templateObject_4
3969
3999
 
3970
4000
  var AutocompleteMultiColumn = function (props) {
3971
4001
  var _a;
3972
- var InputBaseProps = props.InputBaseProps, _b = props.open, open = _b === void 0 ? false : _b, _c = props.PopperPlacement, PopperPlacement = _c === void 0 ? "bottom-start" : _c, PopperBaseProps = props.PopperBaseProps, _d = props.search, search = _d === void 0 ? false : _d, _e = props.label, label = _e === void 0 ? "Search" : _e, _f = props.onClickAway, onClickAway = _f === void 0 ? defaultOnClickAway : _f, ClickAwayListenerProps = props.ClickAwayListenerProps, options = props.options, onInputChange = props.onInputChange, onBlur = props.onBlur, multiple = props.multiple, parentInitialValue = props.value, onChange = props.onChange, _g = props.PopperComponent, PopperComponent = _g === void 0 ? StyledPopper$2 : _g, rest = __rest(props, ["InputBaseProps", "open", "PopperPlacement", "PopperBaseProps", "search", "label", "onClickAway", "ClickAwayListenerProps", "options", "onInputChange", "onBlur", "multiple", "value", "onChange", "PopperComponent"]);
4002
+ var InputBaseProps = props.InputBaseProps, open = props.open, _b = props.PopperPlacement, PopperPlacement = _b === void 0 ? "bottom-start" : _b, PopperBaseProps = props.PopperBaseProps, _c = props.search, search = _c === void 0 ? false : _c, _d = props.label, label = _d === void 0 ? "Search" : _d, onClickAway = props.onClickAway, onClick = props.onClick, ClickAwayListenerProps = props.ClickAwayListenerProps, options = props.options, onInputChange = props.onInputChange, onBlur = props.onBlur, multiple = props.multiple, parentInitialValue = props.value, onChange = props.onChange, _e = props.PopperComponent, PopperComponent = _e === void 0 ? StyledPopper$2 : _e, rest = __rest(props, ["InputBaseProps", "open", "PopperPlacement", "PopperBaseProps", "search", "label", "onClickAway", "onClick", "ClickAwayListenerProps", "options", "onInputChange", "onBlur", "multiple", "value", "onChange", "PopperComponent"]);
3973
4003
  var theme = useTheme();
3974
- var _h = useState(""), inputValue = _h[0], setInputValue = _h[1];
3975
- var _j = useState(open), popperOpen = _j[0], setPopperOpen = _j[1];
4004
+ var isOpenControlled = open !== undefined;
4005
+ var _f = useState(""), inputValue = _f[0], setInputValue = _f[1];
4006
+ var _g = useState(isOpenControlled ? open : false), popperOpen = _g[0], setPopperOpen = _g[1];
4007
+ /**
4008
+ * (masoudmanson): This useEffect is used to update the popperOpen state
4009
+ * when the open prop is controlled.
4010
+ */
4011
+ useEffect(function () {
4012
+ if (isOpenControlled) {
4013
+ setPopperOpen(open);
4014
+ }
4015
+ }, [isOpenControlled, open]);
3976
4016
  var anchorRef = useRef(null);
3977
- var _k = React__default.useState(null), anchorEl = _k[0], setAnchorEl = _k[1];
4017
+ var _h = React__default.useState(null), anchorEl = _h[0], setAnchorEl = _h[1];
3978
4018
  useEffect(function () {
3979
4019
  setAnchorEl(anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current);
3980
4020
  }, [anchorRef]);
3981
- var _l = useState({}), autocompleteMultiColumnValue = _l[0], setAutocompleteMultiColumnValue = _l[1];
4021
+ var _j = useState({}), autocompleteMultiColumnValue = _j[0], setAutocompleteMultiColumnValue = _j[1];
3982
4022
  useEffect(function () {
3983
4023
  if (parentInitialValue !== undefined) {
3984
4024
  setAutocompleteMultiColumnValue(parentInitialValue);
@@ -3992,7 +4032,7 @@ var AutocompleteMultiColumn = function (props) {
3992
4032
  });
3993
4033
  onChange === null || onChange === void 0 ? void 0 : onChange(event, __assign(__assign({}, autocompleteMultiColumnValue), (_a = {}, _a[column] = val, _a)), reason, details);
3994
4034
  };
3995
- return (jsx(ClickAwayListener, __assign({ onClickAway: onClickAway }, ClickAwayListenerProps, { children: jsxs("div", { children: [jsx(StyledAutocompleteInput, __assign({ id: "location-search", label: label, placeholder: label, value: inputValue, onChange: handleInputChange, onClick: handleInputClick, onBlur: handleInputBlur, ref: anchorRef, search: search, onKeyDown: handleInputKeyDown, InputProps: __assign(__assign({}, InputBaseProps === null || InputBaseProps === void 0 ? void 0 : InputBaseProps.ref), { endAdornment: (jsxs(StyledInputAdornment, { position: "end", children: [inputValue && (jsx(ButtonIcon, { "aria-label": "clear-button", className: "input-search-clear-icon", sdsType: "primary", sdsSize: "small", sdsIconProps: {
4035
+ return (jsx(ClickAwayListener, __assign({ onClickAway: defaultOnClickAway }, ClickAwayListenerProps, { children: jsxs("div", { children: [jsx(StyledAutocompleteInput, __assign({ id: "location-search", label: label, placeholder: label, value: inputValue, onChange: handleInputChange, onClick: handleInputClick, onBlur: handleInputBlur, ref: anchorRef, search: search, onKeyDown: handleInputKeyDown, InputProps: __assign(__assign({}, InputBaseProps === null || InputBaseProps === void 0 ? void 0 : InputBaseProps.ref), { endAdornment: (jsxs(StyledInputAdornment, { position: "end", children: [inputValue && (jsx(ButtonIcon, { "aria-label": "clear-button", className: "input-search-clear-icon", sdsType: "primary", sdsSize: "small", sdsIconProps: {
3996
4036
  sdsType: "iconButton",
3997
4037
  }, icon: "xMark", onClick: clearInput })), jsx(ButtonIcon, { "aria-label": "search-button", sdsType: "secondary", sdsSize: "small", sdsIconProps: {
3998
4038
  sdsType: "interactive",
@@ -4019,7 +4059,22 @@ var AutocompleteMultiColumn = function (props) {
4019
4059
  */
4020
4060
  onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange({ target: { value: "" } }, "", "clear");
4021
4061
  }
4022
- function handleInputClick(_) {
4062
+ function handleInputClick(event) {
4063
+ /**
4064
+ * (masoudmanson): Because the Autocomplete component overrides the
4065
+ * InputSearch's onClick, we must also include the parent onClick here.
4066
+ */
4067
+ onClick === null || onClick === void 0 ? void 0 : onClick(event);
4068
+ /**
4069
+ * (masoudmanson): If the dropdown is controlled, we call the onClick prop to allow the parent
4070
+ * to handle the opening and closing of the dropdown.
4071
+ */
4072
+ if (isOpenControlled) {
4073
+ return;
4074
+ }
4075
+ /**
4076
+ * (masoudmanson): If the dropdown is not controlled, we toggle the dropdown open and closed.
4077
+ */
4023
4078
  if (popperOpen) {
4024
4079
  setPopperOpen(false);
4025
4080
  }
@@ -4043,13 +4098,55 @@ var AutocompleteMultiColumn = function (props) {
4043
4098
  setInputValue("");
4044
4099
  onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
4045
4100
  }
4046
- function defaultOnClickAway() {
4047
- setPopperOpen(false);
4101
+ /**
4102
+ * (masoudmanson): This is the default onClickAway handler for the Autocomplete component.
4103
+ * It is used to close the dropdown when the user clicks away from the dropdown. It also
4104
+ * calls the parent onClickAway prop if it is provided.
4105
+ */
4106
+ function defaultOnClickAway(event) {
4107
+ /**
4108
+ * (masoudmanson): We only want to close the dropdown if it is open.
4109
+ * This may sound unnecessary, but it is to prevent the dropdown from
4110
+ * calling the parent onClickAway prop when the dropdown is closed.
4111
+ */
4112
+ if (popperOpen) {
4113
+ onClickAway === null || onClickAway === void 0 ? void 0 : onClickAway(event, "blur");
4114
+ /**
4115
+ * (masoudmanson): If the dropdown is controlled, we call the onClickAway prop to allow the parent
4116
+ * to handle the closing of the dropdown.
4117
+ */
4118
+ if (isOpenControlled)
4119
+ return;
4120
+ // (masoudmanson): If the dropdown is not controlled, we close the dropdown.
4121
+ setPopperOpen(false);
4122
+ }
4048
4123
  }
4049
4124
  function handleInputKeyDown(event) {
4050
- // (masoudmanson): This prevents Backspace from deselecting selected dropdown options.
4051
- if (event.key === "Backspace") {
4052
- event.stopPropagation();
4125
+ var _a;
4126
+ /**
4127
+ * (masoudmanson): Because the Autocomplete component overrides the
4128
+ * InputSearch's onKeyDown, we must also include the user defined onKeyDown here.
4129
+ */
4130
+ if (props === null || props === void 0 ? void 0 : props.onKeyDown) {
4131
+ (_a = props === null || props === void 0 ? void 0 : props.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(props, event);
4132
+ }
4133
+ else {
4134
+ // (masoudmanson): This prevents Backspace from deselecting selected dropdown options.
4135
+ if (event.key === "Backspace") {
4136
+ event.stopPropagation();
4137
+ }
4138
+ /**
4139
+ * (masoudmanson): This is to handle the Escape key to close the dropdown.
4140
+ * If the dropdown is controlled, we call the onClick prop to allow the parent
4141
+ * to handle the closing of the dropdown.
4142
+ */
4143
+ if (event.key === "Escape") {
4144
+ if (isOpenControlled) {
4145
+ onClick === null || onClick === void 0 ? void 0 : onClick();
4146
+ return;
4147
+ }
4148
+ setPopperOpen(false);
4149
+ }
4053
4150
  }
4054
4151
  }
4055
4152
  };
@@ -4061,7 +4158,7 @@ var Autocomplete = function (props) {
4061
4158
  if (options.length > 1) {
4062
4159
  return (jsx(AutocompleteMultiColumn, __assign({ options: options, value: value, onChange: onChange }, rest, {
4063
4160
  // (masoudmanson): groupBy option is disabled on MultiColumn dropdowns
4064
- groupBy: undefined, open: true })));
4161
+ groupBy: undefined })));
4065
4162
  }
4066
4163
  else {
4067
4164
  return (jsx(AutocompleteBase, __assign({ options: options[0].options, value: value, onChange: onChange }, rest)));
@@ -4784,7 +4881,7 @@ var DropdownMenu = function (props) {
4784
4881
  ], open: open, anchorEl: anchorEl, placement: PopperPlacement }, PopperBaseProps, {
4785
4882
  // (masoudmanson): To override the width of the Popper,
4786
4883
  // the sx prop's value must be set after spreading the PopperBaseProps.
4787
- sx: dropdownMenuPopperSx, children: jsx(PaperComponent, { children: jsx(ClickAwayListener, __assign({ onClickAway: onClickAway }, ClickAwayListenerProps, { children: jsxs(StyledDropdownMenuAutocompleteWrapper, { children: [title && (jsx(StyledHeaderTitle, { search: search, children: title })), anchorEl && (jsx(Autocomplete, __assign({ label: label, search: search, title: title, open: open, options: options, PopperBaseProps: DEFAULT_POPPER_BASE_PROPS, disablePortal: true, onClickAway: noop }, rest, { InputBaseProps: DefaultInputBaseProps }))), children] }) })) }) })));
4884
+ sx: dropdownMenuPopperSx, children: jsx(PaperComponent, { children: jsx(ClickAwayListener, __assign({ onClickAway: onClickAway }, ClickAwayListenerProps, { children: jsxs(StyledDropdownMenuAutocompleteWrapper, { children: [title && (jsx(StyledHeaderTitle, { search: search, children: title })), anchorEl && (jsx(Autocomplete, __assign({ label: label, search: search, title: title, open: open, options: options, PopperBaseProps: DEFAULT_POPPER_BASE_PROPS, disablePortal: true, onClickAway: noop, onClick: noop }, rest, { InputBaseProps: DefaultInputBaseProps }))), children] }) })) }) })));
4788
4885
  };
4789
4886
 
4790
4887
  var labelFontBodyS = fontBody("s");
@@ -5325,7 +5422,7 @@ var Dropdown = function (props) {
5325
5422
  // which by default will not close on blur. If closeOnBlur is enabled, clicking out
5326
5423
  // is equivalent to clicking the Cancel button, closing the dropdown and losing
5327
5424
  // unapplied changes.
5328
- closeOnBlur = _f === void 0 ? !buttons : _f, onClose = props.onClose, onChange = props.onChange, _g = props.DropdownMenuProps, DropdownMenuProps = _g === void 0 ? {} : _g, _h = props.InputDropdownProps, InputDropdownProps = _h === void 0 ? { sdsStyle: "minimal" } : _h, _j = props.InputDropdownComponent, InputDropdownComponent = _j === void 0 ? InputDropdown : _j, _k = props.isTriggerChangeOnOptionClick, isTriggerChangeOnOptionClick = _k === void 0 ? false : _k, _l = props.disabled, disabled = _l === void 0 ? false : _l, propValue = props.value, rest = __rest(props, ["options", "label", "multiple", "search", "buttonPosition", "buttons", "closeOnBlur", "onClose", "onChange", "DropdownMenuProps", "InputDropdownProps", "InputDropdownComponent", "isTriggerChangeOnOptionClick", "disabled", "value"]);
5425
+ closeOnBlur = _f === void 0 ? !buttons : _f, onClose = props.onClose, onChange = props.onChange, _g = props.DropdownMenuProps, DropdownMenuProps = _g === void 0 ? {} : _g, _h = props.InputDropdownProps, InputDropdownProps = _h === void 0 ? { sdsStyle: "minimal" } : _h, _j = props.InputDropdownComponent, InputDropdownComponent = _j === void 0 ? InputDropdown : _j, _k = props.isTriggerChangeOnOptionClick, isTriggerChangeOnOptionClick = _k === void 0 ? false : _k, _l = props.disabled, disabled = _l === void 0 ? false : _l, propValue = props.value, onClick = props.onClick, rest = __rest(props, ["options", "label", "multiple", "search", "buttonPosition", "buttons", "closeOnBlur", "onClose", "onChange", "DropdownMenuProps", "InputDropdownProps", "InputDropdownComponent", "isTriggerChangeOnOptionClick", "disabled", "value", "onClick"]);
5329
5426
  if (buttons && !multiple) {
5330
5427
  // eslint-disable-next-line no-console
5331
5428
  console.warn("Warning: buttons are only supported for multiple select dropdowns.");
@@ -5375,6 +5472,7 @@ var Dropdown = function (props) {
5375
5472
  }
5376
5473
  }
5377
5474
  function handleClick(event) {
5475
+ onClick === null || onClick === void 0 ? void 0 : onClick(event);
5378
5476
  if (open) {
5379
5477
  if (!shouldShowButtons) {
5380
5478
  if (multiple) {