@ozen-ui/kit 0.34.1 → 0.34.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.
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "../__inner__/cjs/components/Calendar/index.js",
3
+ "module": "../__inner__/esm/components/Calendar/index.js",
4
+ "types": "../__inner__/esm/components/Calendar/index.d.ts"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "../__inner__/cjs/components/DatePicker/index.js",
3
+ "module": "../__inner__/esm/components/DatePicker/index.js",
4
+ "types": "../__inner__/esm/components/DatePicker/index.d.ts"
5
+ }
@@ -20,7 +20,7 @@ function AutocompleteRender(inProps, ref) {
20
20
  props: inProps,
21
21
  name: 'Autocomplete',
22
22
  });
23
- var _a = (0, helper_1.withDefaultGetters)(props), _b = _a.disabled, disabled = _b === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLED : _b, _c = _a.required, required = _c === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_REQUIRED : _c, _d = _a.autoFocus, autoFocus = _d === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_AUTOFOCUS : _d, _e = _a.fullWidth, fullWidth = _e === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_FULLWIDTH : _e, _f = _a.size, size = _f === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_SIZE : _f, _g = _a.allowCustomValue, allowCustomValue = _g === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_ALLOW_CUSTOM_VALUE : _g, _h = _a.disableShowChevron, disableShowChevron = _h === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_CHEVRON : _h, _j = _a.disableClearButton, disableClearButton = _j === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_CLEAR_BUTTON : _j, _k = _a.disableShowEmptyOptionsList, disableShowEmptyOptionsList = _k === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_EMPTY_OPTIONS_LIST : _k, _l = _a.disableCloseOnSelect, disableCloseOnSelect = _l === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_CLOSE_ON_SELECT : _l, _m = _a.renderInput, renderInput = _m === void 0 ? function (props) { return react_1.default.createElement(Input_1.Input, tslib_1.__assign({}, props, { ref: ref })); } : _m, searchFunctionProp = _a.searchFunction, renderOptionProp = _a.renderOption, inputValueProp = _a.inputValue, className = _a.className, valueProp = _a.value, options = _a.options, defaultValue = _a.defaultValue, error = _a.error, onChange = _a.onChange, onInputChange = _a.onInputChange, label = _a.label, placeholder = _a.placeholder, renderLeft = _a.renderLeft, hint = _a.hint, getOptionKey = _a.getOptionKey, getOptionLabel = _a.getOptionLabel, getOptionDisabled = _a.getOptionDisabled, dataListProps = _a.dataListProps, onCloseProp = _a.onClose, onOpenProp = _a.onOpen, openProp = _a.open, defaultOpen = _a.defaultOpen, loading = _a.loading, inputProps = _a.inputProps, onKeyDown = _a.onKeyDown, noOptionsText = _a.noOptionsText, clearText = _a.clearText, openText = _a.openText, loadingText = _a.loadingText, closeText = _a.closeText, other = tslib_1.__rest(_a, ["disabled", "required", "autoFocus", "fullWidth", "size", "allowCustomValue", "disableShowChevron", "disableClearButton", "disableShowEmptyOptionsList", "disableCloseOnSelect", "renderInput", "searchFunction", "renderOption", "inputValue", "className", "value", "options", "defaultValue", "error", "onChange", "onInputChange", "label", "placeholder", "renderLeft", "hint", "getOptionKey", "getOptionLabel", "getOptionDisabled", "dataListProps", "onClose", "onOpen", "open", "defaultOpen", "loading", "inputProps", "onKeyDown", "noOptionsText", "clearText", "openText", "loadingText", "closeText"]);
23
+ var _a = (0, helper_1.withDefaultGetters)(props), _b = _a.disabled, disabled = _b === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLED : _b, _c = _a.required, required = _c === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_REQUIRED : _c, _d = _a.autoFocus, autoFocus = _d === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_AUTOFOCUS : _d, _e = _a.fullWidth, fullWidth = _e === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_FULLWIDTH : _e, _f = _a.size, size = _f === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_SIZE : _f, _g = _a.allowCustomValue, allowCustomValue = _g === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_ALLOW_CUSTOM_VALUE : _g, _h = _a.disableShowChevron, disableShowChevron = _h === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_CHEVRON : _h, _j = _a.disableClearButton, disableClearButton = _j === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_CLEAR_BUTTON : _j, _k = _a.disableShowEmptyOptionsList, disableShowEmptyOptionsList = _k === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_EMPTY_OPTIONS_LIST : _k, _l = _a.disableCloseOnSelect, disableCloseOnSelect = _l === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_CLOSE_ON_SELECT : _l, _m = _a.renderInput, renderInput = _m === void 0 ? function (props) { return react_1.default.createElement(Input_1.Input, tslib_1.__assign({}, props, { ref: ref })); } : _m, searchFunctionProp = _a.searchFunction, renderOptionProp = _a.renderOption, inputValueProp = _a.inputValue, className = _a.className, valueProp = _a.value, options = _a.options, defaultValue = _a.defaultValue, error = _a.error, onChange = _a.onChange, onInputChange = _a.onInputChange, label = _a.label, placeholder = _a.placeholder, renderLeft = _a.renderLeft, renderRight = _a.renderRight, hint = _a.hint, getOptionKey = _a.getOptionKey, getOptionLabel = _a.getOptionLabel, getOptionDisabled = _a.getOptionDisabled, dataListProps = _a.dataListProps, onCloseProp = _a.onClose, onOpenProp = _a.onOpen, openProp = _a.open, defaultOpen = _a.defaultOpen, loading = _a.loading, inputProps = _a.inputProps, onKeyDown = _a.onKeyDown, noOptionsText = _a.noOptionsText, clearText = _a.clearText, openText = _a.openText, loadingText = _a.loadingText, closeText = _a.closeText, other = tslib_1.__rest(_a, ["disabled", "required", "autoFocus", "fullWidth", "size", "allowCustomValue", "disableShowChevron", "disableClearButton", "disableShowEmptyOptionsList", "disableCloseOnSelect", "renderInput", "searchFunction", "renderOption", "inputValue", "className", "value", "options", "defaultValue", "error", "onChange", "onInputChange", "label", "placeholder", "renderLeft", "renderRight", "hint", "getOptionKey", "getOptionLabel", "getOptionDisabled", "dataListProps", "onClose", "onOpen", "open", "defaultOpen", "loading", "inputProps", "onKeyDown", "noOptionsText", "clearText", "openText", "loadingText", "closeText"]);
24
24
  var anchorRef = (0, react_1.useRef)(null);
25
25
  var _o = tslib_1.__read((0, useControlled_1.useControlled)({
26
26
  value: inputValueProp,
@@ -49,7 +49,7 @@ function AutocompleteRender(inProps, ref) {
49
49
  var savedGetOptionLabel = (0, useMutableRef_1.useMutableRef)(getOptionLabel);
50
50
  var _r = tslib_1.__read((0, react_1.useState)(tslib_1.__spreadArray([], tslib_1.__read(options), false)), 2), filteredOptions = _r[0], setFilteredOptions = _r[1];
51
51
  var searchFunction = searchFunctionProp || searchFunctionDefault;
52
- var dataListValue = valueState ? getOptionLabel(valueState) : '';
52
+ var dataListValue = valueState ? getOptionKey(valueState) : '';
53
53
  var hasOptions = !!(filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.length);
54
54
  var showNoOptions = !hasOptions && !loading;
55
55
  var showLoading = !hasOptions && !!loading;
@@ -163,7 +163,7 @@ function AutocompleteRender(inProps, ref) {
163
163
  /** Событие выбора значения из раскрывающегося списка */
164
164
  var handleChangeDataList = function (event, _a) {
165
165
  var value = _a.value;
166
- var selectedOption = filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.find(function (option) { return (getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option)) === value; });
166
+ var selectedOption = filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.find(function (option) { return (getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option)) === value; });
167
167
  if (selectedOption) {
168
168
  var newInputValue = getOptionLabel(selectedOption);
169
169
  setValueState(selectedOption);
@@ -177,17 +177,17 @@ function AutocompleteRender(inProps, ref) {
177
177
  }
178
178
  };
179
179
  /** Отображение текстового поля */
180
- var input = renderInput(tslib_1.__assign(tslib_1.__assign({ size: size, hint: hint, disabled: disabled, label: label, required: required, error: error, fullWidth: fullWidth, placeholder: placeholder, renderLeft: renderLeft }, other), { renderRight: (react_1.default.createElement(components_1.AutocompleteRenderRight, { open: open, size: size, disabled: disabled, clearText: clearText, closeText: closeText, openText: openText, hasValue: !!inputValue, onClear: onClear, onOpen: handleToggle, disableShowChevron: disableShowChevron, disableClearButton: disableClearButton })), onChange: handleChangeInput, onKeyDown: handleKeyDown, value: inputValue || '', inputProps: tslib_1.__assign(tslib_1.__assign({}, inputProps), { onBlur: onBlur, onClick: handleClickOnInput }), bodyProps: { ref: anchorRef, 'aria-expanded': open }, className: (0, exports.cnAutocomplete)({ size: size, hasChevron: !disableShowChevron }, [
180
+ var input = renderInput(tslib_1.__assign(tslib_1.__assign({ size: size, hint: hint, disabled: disabled, label: label, required: required, error: error, fullWidth: fullWidth, placeholder: placeholder, renderLeft: renderLeft }, other), { renderRight: (react_1.default.createElement(components_1.AutocompleteRenderRight, { open: open, size: size, disabled: disabled, clearText: clearText, closeText: closeText, openText: openText, hasValue: !!inputValue, onClear: onClear, onOpen: handleToggle, renderRight: renderRight, disableShowChevron: disableShowChevron, disableClearButton: disableClearButton })), onChange: handleChangeInput, onKeyDown: handleKeyDown, value: inputValue || '', inputProps: tslib_1.__assign(tslib_1.__assign({}, inputProps), { onBlur: onBlur, onClick: handleClickOnInput }), bodyProps: { ref: anchorRef, 'aria-expanded': open }, className: (0, exports.cnAutocomplete)({ size: size, hasChevron: !disableShowChevron }, [
181
181
  className,
182
182
  ]), ref: ref }));
183
183
  /** Отображение опций */
184
184
  var renderOptions = filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.map(function (option) {
185
185
  var selected = valueState
186
- ? getOptionLabel(valueState) === getOptionLabel(option)
186
+ ? getOptionKey(valueState) === getOptionKey(option)
187
187
  : false;
188
188
  var renderOptionDefault = function (_a) {
189
- var option = _a.option, selected = _a.selected;
190
- return (react_1.default.createElement(DataList_1.DataListOption, { key: getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option), label: getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option), value: getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option), disabled: getOptionDisabled === null || getOptionDisabled === void 0 ? void 0 : getOptionDisabled(option), selected: selected }));
189
+ var option = _a.option;
190
+ return (react_1.default.createElement(DataList_1.DataListOption, { key: getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option), label: getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option), value: getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option), disabled: getOptionDisabled === null || getOptionDisabled === void 0 ? void 0 : getOptionDisabled(option) }));
191
191
  };
192
192
  var renderOption = renderOptionProp || renderOptionDefault;
193
193
  return renderOption({ option: option, selected: selected });
@@ -5,6 +5,6 @@ type AutocompleteRenderRightProps = {
5
5
  onOpen: () => void;
6
6
  onClear: (e: React.MouseEvent<HTMLElement>) => void;
7
7
  hasValue: boolean;
8
- } & Pick<AutocompleteProps, 'clearText' | 'closeText' | 'openText' | 'size' | 'disabled' | 'open' | 'disableClearButton' | 'disableShowChevron'>;
8
+ } & Pick<AutocompleteProps, 'clearText' | 'closeText' | 'openText' | 'size' | 'disabled' | 'open' | 'disableClearButton' | 'disableShowChevron' | 'renderRight'>;
9
9
  export declare const AutocompleteRenderRight: FC<AutocompleteRenderRightProps>;
10
10
  export {};
@@ -5,10 +5,11 @@ var tslib_1 = require("tslib");
5
5
  var react_1 = tslib_1.__importDefault(require("react"));
6
6
  var icons_1 = require("@ozen-ui/icons");
7
7
  var FieldControl_1 = require("../../../FieldControl");
8
+ var FieldIcon_1 = require("../../../FieldIcon");
8
9
  var IconButton_1 = require("../../../IconButton");
9
10
  var index_1 = require("../../index");
10
11
  var AutocompleteRenderRight = function (_a) {
11
- var disableClearButton = _a.disableClearButton, disableShowChevron = _a.disableShowChevron, clearText = _a.clearText, closeText = _a.closeText, openText = _a.openText, disabled = _a.disabled, hasValue = _a.hasValue, onClear = _a.onClear, onOpen = _a.onOpen, open = _a.open, size = _a.size;
12
+ var disableClearButton = _a.disableClearButton, disableShowChevron = _a.disableShowChevron, renderRight = _a.renderRight, clearText = _a.clearText, closeText = _a.closeText, openText = _a.openText, disabled = _a.disabled, hasValue = _a.hasValue, onClear = _a.onClear, onOpen = _a.onOpen, open = _a.open, size = _a.size;
12
13
  var _b = tslib_1.__read((0, FieldControl_1.useFieldControl)(), 1), _c = _b[0], focused = _c.focused, hovered = _c.hovered;
13
14
  var isVisibleClearButton = !!(hovered || open || focused) && hasValue;
14
15
  return (react_1.default.createElement("div", { className: (0, index_1.cnAutocomplete)('RenderRight') },
@@ -18,6 +19,7 @@ var AutocompleteRenderRight = function (_a) {
18
19
  }, className: (0, index_1.cnAutocomplete)('ClearButton', {
19
20
  visibility: isVisibleClearButton,
20
21
  }), title: clearText, "aria-label": clearText, size: size, icon: icons_1.CloseIcon, compressed: true })),
22
+ react_1.default.createElement(FieldIcon_1.FieldIcon, { icon: renderRight }),
21
23
  !disableShowChevron && (react_1.default.createElement(IconButton_1.IconButton, { type: "button", variant: "ghost", tabIndex: -1, onClick: function (e) {
22
24
  e.preventDefault();
23
25
  onOpen();
@@ -59,6 +59,22 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
59
59
  } & {
60
60
  size?: import("@ozen-ui/icons").IconSize | undefined;
61
61
  }, string | import("react").JSXElementConstructor<any>>) | undefined;
62
+ renderRight?: string | number | import("react").FC<import("react").SVGProps<SVGSVGElement> & {
63
+ color?: string | undefined;
64
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
65
+ } & {
66
+ size?: import("@ozen-ui/icons").IconSize | undefined;
67
+ }> | import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
68
+ color?: string | undefined;
69
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
70
+ } & {
71
+ size?: import("@ozen-ui/icons").IconSize | undefined;
72
+ }, string | import("react").JSXElementConstructor<any>> | (() => import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
73
+ color?: string | undefined;
74
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
75
+ } & {
76
+ size?: import("@ozen-ui/icons").IconSize | undefined;
77
+ }, string | import("react").JSXElementConstructor<any>>) | undefined;
62
78
  inputProps?: (Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref"> & {
63
79
  ref?: ((instance: HTMLInputElement | null) => void) | import("react").RefObject<HTMLInputElement> | null | undefined;
64
80
  } & {
@@ -76,7 +92,7 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
76
92
  } ? Record<string, unknown> : {
77
93
  getOptionKey?: AutocompletePropGetOptionKey<OPTION> | undefined;
78
94
  }) & (OPTION extends {
79
- id: boolean | undefined;
95
+ disabled: boolean | undefined;
80
96
  } ? Record<string, unknown> : {
81
97
  getOptionDisabled?: AutocompletePropGetOptionKey<OPTION> | undefined;
82
98
  }) & {
@@ -139,6 +155,22 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
139
155
  } & {
140
156
  size?: import("@ozen-ui/icons").IconSize | undefined;
141
157
  }, string | import("react").JSXElementConstructor<any>>) | undefined;
158
+ renderRight?: string | number | import("react").FC<import("react").SVGProps<SVGSVGElement> & {
159
+ color?: string | undefined;
160
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
161
+ } & {
162
+ size?: import("@ozen-ui/icons").IconSize | undefined;
163
+ }> | import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
164
+ color?: string | undefined;
165
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
166
+ } & {
167
+ size?: import("@ozen-ui/icons").IconSize | undefined;
168
+ }, string | import("react").JSXElementConstructor<any>> | (() => import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
169
+ color?: string | undefined;
170
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
171
+ } & {
172
+ size?: import("@ozen-ui/icons").IconSize | undefined;
173
+ }, string | import("react").JSXElementConstructor<any>>) | undefined;
142
174
  inputProps?: (Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref"> & {
143
175
  ref?: ((instance: HTMLInputElement | null) => void) | import("react").RefObject<HTMLInputElement> | null | undefined;
144
176
  } & {
@@ -156,7 +188,7 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
156
188
  } ? Record<string, unknown> : {
157
189
  getOptionKey?: AutocompletePropGetOptionKey<OPTION> | undefined;
158
190
  }) & (OPTION extends {
159
- id: boolean | undefined;
191
+ disabled: boolean | undefined;
160
192
  } ? Record<string, unknown> : {
161
193
  getOptionDisabled?: AutocompletePropGetOptionKey<OPTION> | undefined;
162
194
  }) & {
@@ -31,7 +31,7 @@ type AutocompleteOpenUncontrolledProps = {
31
31
  /** Состояние открытие по умолчанию (неконтролируемый компонент) */
32
32
  defaultOpen?: boolean;
33
33
  };
34
- type AutocompleteInputProps = Pick<InputProps, 'placeholder' | 'autoFocus' | 'fullWidth' | 'disabled' | 'label' | 'required' | 'style' | 'error' | 'hint' | 'renderLeft' | 'className' | 'inputProps' | 'onKeyDown'>;
34
+ type AutocompleteInputProps = Pick<InputProps, 'placeholder' | 'autoFocus' | 'fullWidth' | 'disabled' | 'label' | 'required' | 'style' | 'error' | 'hint' | 'renderLeft' | 'renderRight' | 'className' | 'inputProps' | 'onKeyDown'>;
35
35
  type AutocompleteDataListProps = Partial<Omit<DataListProps, 'onClose' | 'open' | 'anchorRef' | 'multiple' | 'selected' | 'onSelect'>>;
36
36
  export type AutocompleteProps<OPTION = AutocompleteDefaultOption> = {
37
37
  /** Список вариантов выбора (опции) */
@@ -97,7 +97,7 @@ export type AutocompleteProps<OPTION = AutocompleteDefaultOption> = {
97
97
  } ? Record<string, unknown> : {
98
98
  getOptionKey?: AutocompletePropGetOptionKey<OPTION>;
99
99
  }) & (OPTION extends {
100
- id: AutocompleteDefaultOption['disabled'];
100
+ disabled: AutocompleteDefaultOption['disabled'];
101
101
  } ? Record<string, unknown> : {
102
102
  getOptionDisabled?: AutocompletePropGetOptionKey<OPTION>;
103
103
  });
@@ -8,6 +8,7 @@ var react_is_1 = require("react-is");
8
8
  var useControlled_1 = require("../../hooks/useControlled");
9
9
  var useEventListener_1 = require("../../hooks/useEventListener");
10
10
  var useMultiRef_1 = require("../../hooks/useMultiRef");
11
+ var usePrevious_1 = require("../../hooks/usePrevious");
11
12
  var useThemeProps_1 = require("../../hooks/useThemeProps");
12
13
  var classname_1 = require("../../utils/classname");
13
14
  var isKey_1 = require("../../utils/isKey");
@@ -79,23 +80,31 @@ var DataListRender = function (inProps, ref) {
79
80
  items: items,
80
81
  selected: (0, helpers_1.lastSelectedValue)(selectedState),
81
82
  onSelect: function (event, item) {
82
- handleSelect(event, item || '');
83
+ handleSelect(event, item !== null && item !== void 0 ? item : '');
83
84
  },
84
85
  }), current = _f.current, focused = _f.focused, onKeyDown = _f.onKeyDown, onClick = _f.onClick;
86
+ var previousCurrent = (0, usePrevious_1.usePrevious)(current);
85
87
  (0, react_1.useEffect)(function () {
86
88
  var _a, _b;
87
- var selected = focused || current || '';
89
+ var firstCurrent = (previousCurrent === null || previousCurrent === undefined) &&
90
+ current !== null &&
91
+ current !== undefined
92
+ ? current
93
+ : undefined;
94
+ var selected = focused !== null && focused !== void 0 ? focused : firstCurrent;
88
95
  // Находит элемент по ключу
89
- var idx = nodes.get(selected);
96
+ var idx = selected !== undefined && selected !== null
97
+ ? nodes.get(selected)
98
+ : undefined;
90
99
  if (idx !== undefined) {
91
100
  // Прокрутка списка
92
101
  (0, scrollContainerToElement_1.scrollContainerToElement)({
93
102
  container: dataListRef.current,
94
103
  element: (_b = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b[idx],
95
- behavior: focused ? 'smooth' : 'instant',
104
+ behavior: focused !== undefined && focused !== null ? 'smooth' : 'instant',
96
105
  });
97
106
  }
98
- }, [focused, current]);
107
+ }, [focused, current, previousCurrent]);
99
108
  // Назначает элементу контроля событие управления списком с клавиатуры
100
109
  (0, useEventListener_1.useEventListener)({
101
110
  eventName: 'keydown',
@@ -17,7 +17,7 @@ function AutocompleteRender(inProps, ref) {
17
17
  props: inProps,
18
18
  name: 'Autocomplete',
19
19
  });
20
- var _a = withDefaultGetters(props), _b = _a.disabled, disabled = _b === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLED : _b, _c = _a.required, required = _c === void 0 ? AUTOCOMPLETE_DEFAULT_REQUIRED : _c, _d = _a.autoFocus, autoFocus = _d === void 0 ? AUTOCOMPLETE_DEFAULT_AUTOFOCUS : _d, _e = _a.fullWidth, fullWidth = _e === void 0 ? AUTOCOMPLETE_DEFAULT_FULLWIDTH : _e, _f = _a.size, size = _f === void 0 ? AUTOCOMPLETE_DEFAULT_SIZE : _f, _g = _a.allowCustomValue, allowCustomValue = _g === void 0 ? AUTOCOMPLETE_DEFAULT_ALLOW_CUSTOM_VALUE : _g, _h = _a.disableShowChevron, disableShowChevron = _h === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_CHEVRON : _h, _j = _a.disableClearButton, disableClearButton = _j === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_CLEAR_BUTTON : _j, _k = _a.disableShowEmptyOptionsList, disableShowEmptyOptionsList = _k === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_EMPTY_OPTIONS_LIST : _k, _l = _a.disableCloseOnSelect, disableCloseOnSelect = _l === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_CLOSE_ON_SELECT : _l, _m = _a.renderInput, renderInput = _m === void 0 ? function (props) { return React.createElement(Input, __assign({}, props, { ref: ref })); } : _m, searchFunctionProp = _a.searchFunction, renderOptionProp = _a.renderOption, inputValueProp = _a.inputValue, className = _a.className, valueProp = _a.value, options = _a.options, defaultValue = _a.defaultValue, error = _a.error, onChange = _a.onChange, onInputChange = _a.onInputChange, label = _a.label, placeholder = _a.placeholder, renderLeft = _a.renderLeft, hint = _a.hint, getOptionKey = _a.getOptionKey, getOptionLabel = _a.getOptionLabel, getOptionDisabled = _a.getOptionDisabled, dataListProps = _a.dataListProps, onCloseProp = _a.onClose, onOpenProp = _a.onOpen, openProp = _a.open, defaultOpen = _a.defaultOpen, loading = _a.loading, inputProps = _a.inputProps, onKeyDown = _a.onKeyDown, noOptionsText = _a.noOptionsText, clearText = _a.clearText, openText = _a.openText, loadingText = _a.loadingText, closeText = _a.closeText, other = __rest(_a, ["disabled", "required", "autoFocus", "fullWidth", "size", "allowCustomValue", "disableShowChevron", "disableClearButton", "disableShowEmptyOptionsList", "disableCloseOnSelect", "renderInput", "searchFunction", "renderOption", "inputValue", "className", "value", "options", "defaultValue", "error", "onChange", "onInputChange", "label", "placeholder", "renderLeft", "hint", "getOptionKey", "getOptionLabel", "getOptionDisabled", "dataListProps", "onClose", "onOpen", "open", "defaultOpen", "loading", "inputProps", "onKeyDown", "noOptionsText", "clearText", "openText", "loadingText", "closeText"]);
20
+ var _a = withDefaultGetters(props), _b = _a.disabled, disabled = _b === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLED : _b, _c = _a.required, required = _c === void 0 ? AUTOCOMPLETE_DEFAULT_REQUIRED : _c, _d = _a.autoFocus, autoFocus = _d === void 0 ? AUTOCOMPLETE_DEFAULT_AUTOFOCUS : _d, _e = _a.fullWidth, fullWidth = _e === void 0 ? AUTOCOMPLETE_DEFAULT_FULLWIDTH : _e, _f = _a.size, size = _f === void 0 ? AUTOCOMPLETE_DEFAULT_SIZE : _f, _g = _a.allowCustomValue, allowCustomValue = _g === void 0 ? AUTOCOMPLETE_DEFAULT_ALLOW_CUSTOM_VALUE : _g, _h = _a.disableShowChevron, disableShowChevron = _h === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_CHEVRON : _h, _j = _a.disableClearButton, disableClearButton = _j === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_CLEAR_BUTTON : _j, _k = _a.disableShowEmptyOptionsList, disableShowEmptyOptionsList = _k === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_EMPTY_OPTIONS_LIST : _k, _l = _a.disableCloseOnSelect, disableCloseOnSelect = _l === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_CLOSE_ON_SELECT : _l, _m = _a.renderInput, renderInput = _m === void 0 ? function (props) { return React.createElement(Input, __assign({}, props, { ref: ref })); } : _m, searchFunctionProp = _a.searchFunction, renderOptionProp = _a.renderOption, inputValueProp = _a.inputValue, className = _a.className, valueProp = _a.value, options = _a.options, defaultValue = _a.defaultValue, error = _a.error, onChange = _a.onChange, onInputChange = _a.onInputChange, label = _a.label, placeholder = _a.placeholder, renderLeft = _a.renderLeft, renderRight = _a.renderRight, hint = _a.hint, getOptionKey = _a.getOptionKey, getOptionLabel = _a.getOptionLabel, getOptionDisabled = _a.getOptionDisabled, dataListProps = _a.dataListProps, onCloseProp = _a.onClose, onOpenProp = _a.onOpen, openProp = _a.open, defaultOpen = _a.defaultOpen, loading = _a.loading, inputProps = _a.inputProps, onKeyDown = _a.onKeyDown, noOptionsText = _a.noOptionsText, clearText = _a.clearText, openText = _a.openText, loadingText = _a.loadingText, closeText = _a.closeText, other = __rest(_a, ["disabled", "required", "autoFocus", "fullWidth", "size", "allowCustomValue", "disableShowChevron", "disableClearButton", "disableShowEmptyOptionsList", "disableCloseOnSelect", "renderInput", "searchFunction", "renderOption", "inputValue", "className", "value", "options", "defaultValue", "error", "onChange", "onInputChange", "label", "placeholder", "renderLeft", "renderRight", "hint", "getOptionKey", "getOptionLabel", "getOptionDisabled", "dataListProps", "onClose", "onOpen", "open", "defaultOpen", "loading", "inputProps", "onKeyDown", "noOptionsText", "clearText", "openText", "loadingText", "closeText"]);
21
21
  var anchorRef = useRef(null);
22
22
  var _o = __read(useControlled({
23
23
  value: inputValueProp,
@@ -46,7 +46,7 @@ function AutocompleteRender(inProps, ref) {
46
46
  var savedGetOptionLabel = useMutableRef(getOptionLabel);
47
47
  var _r = __read(useState(__spreadArray([], __read(options), false)), 2), filteredOptions = _r[0], setFilteredOptions = _r[1];
48
48
  var searchFunction = searchFunctionProp || searchFunctionDefault;
49
- var dataListValue = valueState ? getOptionLabel(valueState) : '';
49
+ var dataListValue = valueState ? getOptionKey(valueState) : '';
50
50
  var hasOptions = !!(filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.length);
51
51
  var showNoOptions = !hasOptions && !loading;
52
52
  var showLoading = !hasOptions && !!loading;
@@ -160,7 +160,7 @@ function AutocompleteRender(inProps, ref) {
160
160
  /** Событие выбора значения из раскрывающегося списка */
161
161
  var handleChangeDataList = function (event, _a) {
162
162
  var value = _a.value;
163
- var selectedOption = filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.find(function (option) { return (getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option)) === value; });
163
+ var selectedOption = filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.find(function (option) { return (getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option)) === value; });
164
164
  if (selectedOption) {
165
165
  var newInputValue = getOptionLabel(selectedOption);
166
166
  setValueState(selectedOption);
@@ -174,17 +174,17 @@ function AutocompleteRender(inProps, ref) {
174
174
  }
175
175
  };
176
176
  /** Отображение текстового поля */
177
- var input = renderInput(__assign(__assign({ size: size, hint: hint, disabled: disabled, label: label, required: required, error: error, fullWidth: fullWidth, placeholder: placeholder, renderLeft: renderLeft }, other), { renderRight: (React.createElement(AutocompleteRenderRight, { open: open, size: size, disabled: disabled, clearText: clearText, closeText: closeText, openText: openText, hasValue: !!inputValue, onClear: onClear, onOpen: handleToggle, disableShowChevron: disableShowChevron, disableClearButton: disableClearButton })), onChange: handleChangeInput, onKeyDown: handleKeyDown, value: inputValue || '', inputProps: __assign(__assign({}, inputProps), { onBlur: onBlur, onClick: handleClickOnInput }), bodyProps: { ref: anchorRef, 'aria-expanded': open }, className: cnAutocomplete({ size: size, hasChevron: !disableShowChevron }, [
177
+ var input = renderInput(__assign(__assign({ size: size, hint: hint, disabled: disabled, label: label, required: required, error: error, fullWidth: fullWidth, placeholder: placeholder, renderLeft: renderLeft }, other), { renderRight: (React.createElement(AutocompleteRenderRight, { open: open, size: size, disabled: disabled, clearText: clearText, closeText: closeText, openText: openText, hasValue: !!inputValue, onClear: onClear, onOpen: handleToggle, renderRight: renderRight, disableShowChevron: disableShowChevron, disableClearButton: disableClearButton })), onChange: handleChangeInput, onKeyDown: handleKeyDown, value: inputValue || '', inputProps: __assign(__assign({}, inputProps), { onBlur: onBlur, onClick: handleClickOnInput }), bodyProps: { ref: anchorRef, 'aria-expanded': open }, className: cnAutocomplete({ size: size, hasChevron: !disableShowChevron }, [
178
178
  className,
179
179
  ]), ref: ref }));
180
180
  /** Отображение опций */
181
181
  var renderOptions = filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.map(function (option) {
182
182
  var selected = valueState
183
- ? getOptionLabel(valueState) === getOptionLabel(option)
183
+ ? getOptionKey(valueState) === getOptionKey(option)
184
184
  : false;
185
185
  var renderOptionDefault = function (_a) {
186
- var option = _a.option, selected = _a.selected;
187
- return (React.createElement(DataListOption, { key: getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option), label: getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option), value: getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option), disabled: getOptionDisabled === null || getOptionDisabled === void 0 ? void 0 : getOptionDisabled(option), selected: selected }));
186
+ var option = _a.option;
187
+ return (React.createElement(DataListOption, { key: getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option), label: getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option), value: getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option), disabled: getOptionDisabled === null || getOptionDisabled === void 0 ? void 0 : getOptionDisabled(option) }));
188
188
  };
189
189
  var renderOption = renderOptionProp || renderOptionDefault;
190
190
  return renderOption({ option: option, selected: selected });
@@ -5,6 +5,6 @@ type AutocompleteRenderRightProps = {
5
5
  onOpen: () => void;
6
6
  onClear: (e: React.MouseEvent<HTMLElement>) => void;
7
7
  hasValue: boolean;
8
- } & Pick<AutocompleteProps, 'clearText' | 'closeText' | 'openText' | 'size' | 'disabled' | 'open' | 'disableClearButton' | 'disableShowChevron'>;
8
+ } & Pick<AutocompleteProps, 'clearText' | 'closeText' | 'openText' | 'size' | 'disabled' | 'open' | 'disableClearButton' | 'disableShowChevron' | 'renderRight'>;
9
9
  export declare const AutocompleteRenderRight: FC<AutocompleteRenderRightProps>;
10
10
  export {};
@@ -2,10 +2,11 @@ import { __read } from "tslib";
2
2
  import React from 'react';
3
3
  import { ChevronDownIcon, ChevronUpIcon, CloseIcon } from '@ozen-ui/icons';
4
4
  import { useFieldControl } from '../../../FieldControl';
5
+ import { FieldIcon } from '../../../FieldIcon';
5
6
  import { IconButton } from '../../../IconButton';
6
7
  import { cnAutocomplete } from '../../index';
7
8
  export var AutocompleteRenderRight = function (_a) {
8
- var disableClearButton = _a.disableClearButton, disableShowChevron = _a.disableShowChevron, clearText = _a.clearText, closeText = _a.closeText, openText = _a.openText, disabled = _a.disabled, hasValue = _a.hasValue, onClear = _a.onClear, onOpen = _a.onOpen, open = _a.open, size = _a.size;
9
+ var disableClearButton = _a.disableClearButton, disableShowChevron = _a.disableShowChevron, renderRight = _a.renderRight, clearText = _a.clearText, closeText = _a.closeText, openText = _a.openText, disabled = _a.disabled, hasValue = _a.hasValue, onClear = _a.onClear, onOpen = _a.onOpen, open = _a.open, size = _a.size;
9
10
  var _b = __read(useFieldControl(), 1), _c = _b[0], focused = _c.focused, hovered = _c.hovered;
10
11
  var isVisibleClearButton = !!(hovered || open || focused) && hasValue;
11
12
  return (React.createElement("div", { className: cnAutocomplete('RenderRight') },
@@ -15,6 +16,7 @@ export var AutocompleteRenderRight = function (_a) {
15
16
  }, className: cnAutocomplete('ClearButton', {
16
17
  visibility: isVisibleClearButton,
17
18
  }), title: clearText, "aria-label": clearText, size: size, icon: CloseIcon, compressed: true })),
19
+ React.createElement(FieldIcon, { icon: renderRight }),
18
20
  !disableShowChevron && (React.createElement(IconButton, { type: "button", variant: "ghost", tabIndex: -1, onClick: function (e) {
19
21
  e.preventDefault();
20
22
  onOpen();
@@ -59,6 +59,22 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
59
59
  } & {
60
60
  size?: import("@ozen-ui/icons").IconSize | undefined;
61
61
  }, string | import("react").JSXElementConstructor<any>>) | undefined;
62
+ renderRight?: string | number | import("react").FC<import("react").SVGProps<SVGSVGElement> & {
63
+ color?: string | undefined;
64
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
65
+ } & {
66
+ size?: import("@ozen-ui/icons").IconSize | undefined;
67
+ }> | import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
68
+ color?: string | undefined;
69
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
70
+ } & {
71
+ size?: import("@ozen-ui/icons").IconSize | undefined;
72
+ }, string | import("react").JSXElementConstructor<any>> | (() => import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
73
+ color?: string | undefined;
74
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
75
+ } & {
76
+ size?: import("@ozen-ui/icons").IconSize | undefined;
77
+ }, string | import("react").JSXElementConstructor<any>>) | undefined;
62
78
  inputProps?: (Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref"> & {
63
79
  ref?: ((instance: HTMLInputElement | null) => void) | import("react").RefObject<HTMLInputElement> | null | undefined;
64
80
  } & {
@@ -76,7 +92,7 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
76
92
  } ? Record<string, unknown> : {
77
93
  getOptionKey?: AutocompletePropGetOptionKey<OPTION> | undefined;
78
94
  }) & (OPTION extends {
79
- id: boolean | undefined;
95
+ disabled: boolean | undefined;
80
96
  } ? Record<string, unknown> : {
81
97
  getOptionDisabled?: AutocompletePropGetOptionKey<OPTION> | undefined;
82
98
  }) & {
@@ -139,6 +155,22 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
139
155
  } & {
140
156
  size?: import("@ozen-ui/icons").IconSize | undefined;
141
157
  }, string | import("react").JSXElementConstructor<any>>) | undefined;
158
+ renderRight?: string | number | import("react").FC<import("react").SVGProps<SVGSVGElement> & {
159
+ color?: string | undefined;
160
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
161
+ } & {
162
+ size?: import("@ozen-ui/icons").IconSize | undefined;
163
+ }> | import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
164
+ color?: string | undefined;
165
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
166
+ } & {
167
+ size?: import("@ozen-ui/icons").IconSize | undefined;
168
+ }, string | import("react").JSXElementConstructor<any>> | (() => import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
169
+ color?: string | undefined;
170
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
171
+ } & {
172
+ size?: import("@ozen-ui/icons").IconSize | undefined;
173
+ }, string | import("react").JSXElementConstructor<any>>) | undefined;
142
174
  inputProps?: (Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref"> & {
143
175
  ref?: ((instance: HTMLInputElement | null) => void) | import("react").RefObject<HTMLInputElement> | null | undefined;
144
176
  } & {
@@ -156,7 +188,7 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
156
188
  } ? Record<string, unknown> : {
157
189
  getOptionKey?: AutocompletePropGetOptionKey<OPTION> | undefined;
158
190
  }) & (OPTION extends {
159
- id: boolean | undefined;
191
+ disabled: boolean | undefined;
160
192
  } ? Record<string, unknown> : {
161
193
  getOptionDisabled?: AutocompletePropGetOptionKey<OPTION> | undefined;
162
194
  }) & {
@@ -31,7 +31,7 @@ type AutocompleteOpenUncontrolledProps = {
31
31
  /** Состояние открытие по умолчанию (неконтролируемый компонент) */
32
32
  defaultOpen?: boolean;
33
33
  };
34
- type AutocompleteInputProps = Pick<InputProps, 'placeholder' | 'autoFocus' | 'fullWidth' | 'disabled' | 'label' | 'required' | 'style' | 'error' | 'hint' | 'renderLeft' | 'className' | 'inputProps' | 'onKeyDown'>;
34
+ type AutocompleteInputProps = Pick<InputProps, 'placeholder' | 'autoFocus' | 'fullWidth' | 'disabled' | 'label' | 'required' | 'style' | 'error' | 'hint' | 'renderLeft' | 'renderRight' | 'className' | 'inputProps' | 'onKeyDown'>;
35
35
  type AutocompleteDataListProps = Partial<Omit<DataListProps, 'onClose' | 'open' | 'anchorRef' | 'multiple' | 'selected' | 'onSelect'>>;
36
36
  export type AutocompleteProps<OPTION = AutocompleteDefaultOption> = {
37
37
  /** Список вариантов выбора (опции) */
@@ -97,7 +97,7 @@ export type AutocompleteProps<OPTION = AutocompleteDefaultOption> = {
97
97
  } ? Record<string, unknown> : {
98
98
  getOptionKey?: AutocompletePropGetOptionKey<OPTION>;
99
99
  }) & (OPTION extends {
100
- id: AutocompleteDefaultOption['disabled'];
100
+ disabled: AutocompleteDefaultOption['disabled'];
101
101
  } ? Record<string, unknown> : {
102
102
  getOptionDisabled?: AutocompletePropGetOptionKey<OPTION>;
103
103
  });
@@ -5,6 +5,7 @@ import { isFragment } from 'react-is';
5
5
  import { useControlled } from '../../hooks/useControlled';
6
6
  import { useEventListener } from '../../hooks/useEventListener';
7
7
  import { useMultiRef } from '../../hooks/useMultiRef';
8
+ import { usePrevious } from '../../hooks/usePrevious';
8
9
  import { useThemeProps } from '../../hooks/useThemeProps';
9
10
  import { cn } from '../../utils/classname';
10
11
  import { isKey } from '../../utils/isKey';
@@ -76,23 +77,31 @@ var DataListRender = function (inProps, ref) {
76
77
  items: items,
77
78
  selected: lastSelectedValue(selectedState),
78
79
  onSelect: function (event, item) {
79
- handleSelect(event, item || '');
80
+ handleSelect(event, item !== null && item !== void 0 ? item : '');
80
81
  },
81
82
  }), current = _f.current, focused = _f.focused, onKeyDown = _f.onKeyDown, onClick = _f.onClick;
83
+ var previousCurrent = usePrevious(current);
82
84
  useEffect(function () {
83
85
  var _a, _b;
84
- var selected = focused || current || '';
86
+ var firstCurrent = (previousCurrent === null || previousCurrent === undefined) &&
87
+ current !== null &&
88
+ current !== undefined
89
+ ? current
90
+ : undefined;
91
+ var selected = focused !== null && focused !== void 0 ? focused : firstCurrent;
85
92
  // Находит элемент по ключу
86
- var idx = nodes.get(selected);
93
+ var idx = selected !== undefined && selected !== null
94
+ ? nodes.get(selected)
95
+ : undefined;
87
96
  if (idx !== undefined) {
88
97
  // Прокрутка списка
89
98
  scrollContainerToElement({
90
99
  container: dataListRef.current,
91
100
  element: (_b = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b[idx],
92
- behavior: focused ? 'smooth' : 'instant',
101
+ behavior: focused !== undefined && focused !== null ? 'smooth' : 'instant',
93
102
  });
94
103
  }
95
- }, [focused, current]);
104
+ }, [focused, current, previousCurrent]);
96
105
  // Назначает элементу контроля событие управления списком с клавиатуры
97
106
  useEventListener({
98
107
  eventName: 'keydown',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ozen-ui/kit",
3
- "version": "0.34.1",
3
+ "version": "0.34.2",
4
4
  "description": "React component library",
5
5
  "files": [
6
6
  "*"