@vkontakte/vkui 6.5.3 → 6.5.4

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.
Files changed (61) hide show
  1. package/dist/cjs/components/CustomSelect/CustomSelect.d.ts +12 -2
  2. package/dist/cjs/components/CustomSelect/CustomSelect.d.ts.map +1 -1
  3. package/dist/cjs/components/CustomSelect/CustomSelect.js +72 -52
  4. package/dist/cjs/components/CustomSelect/CustomSelect.js.map +1 -1
  5. package/dist/cjs/components/CustomSelect/CustomSelectInput.d.ts +1 -3
  6. package/dist/cjs/components/CustomSelect/CustomSelectInput.d.ts.map +1 -1
  7. package/dist/cjs/components/CustomSelect/CustomSelectInput.js +24 -19
  8. package/dist/cjs/components/CustomSelect/CustomSelectInput.js.map +1 -1
  9. package/dist/components/CustomSelect/CustomSelect.d.ts +12 -2
  10. package/dist/components/CustomSelect/CustomSelect.d.ts.map +1 -1
  11. package/dist/components/CustomSelect/CustomSelect.js +64 -44
  12. package/dist/components/CustomSelect/CustomSelect.js.map +1 -1
  13. package/dist/components/CustomSelect/CustomSelectInput.d.ts +1 -3
  14. package/dist/components/CustomSelect/CustomSelectInput.d.ts.map +1 -1
  15. package/dist/components/CustomSelect/CustomSelectInput.js +24 -19
  16. package/dist/components/CustomSelect/CustomSelectInput.js.map +1 -1
  17. package/dist/components.css +1 -1
  18. package/dist/components.css.map +1 -1
  19. package/dist/components.js.tmp +101 -156
  20. package/dist/cssm/components/CustomSelect/CustomSelect.d.ts +12 -2
  21. package/dist/cssm/components/CustomSelect/CustomSelect.d.ts.map +1 -1
  22. package/dist/cssm/components/CustomSelect/CustomSelect.js +60 -41
  23. package/dist/cssm/components/CustomSelect/CustomSelect.js.map +1 -1
  24. package/dist/cssm/components/CustomSelect/CustomSelectInput.d.ts +1 -3
  25. package/dist/cssm/components/CustomSelect/CustomSelectInput.d.ts.map +1 -1
  26. package/dist/cssm/components/CustomSelect/CustomSelectInput.js +21 -16
  27. package/dist/cssm/components/CustomSelect/CustomSelectInput.js.map +1 -1
  28. package/dist/cssm/components/CustomSelect/CustomSelectInput.module.css +40 -74
  29. package/dist/vkui.css +1 -1
  30. package/dist/vkui.css.map +1 -1
  31. package/dist/vkui.js.tmp +101 -156
  32. package/package.json +1 -1
  33. package/src/components/CustomSelect/CustomSelect.tsx +101 -53
  34. package/src/components/CustomSelect/CustomSelectInput.module.css +35 -55
  35. package/src/components/CustomSelect/CustomSelectInput.tsx +35 -24
  36. package/dist/cjs/components/CustomSelect/helpers.d.ts +0 -8
  37. package/dist/cjs/components/CustomSelect/helpers.d.ts.map +0 -1
  38. package/dist/cjs/components/CustomSelect/helpers.js +0 -76
  39. package/dist/cjs/components/CustomSelect/helpers.js.map +0 -1
  40. package/dist/cjs/components/CustomSelect/types.d.ts +0 -12
  41. package/dist/cjs/components/CustomSelect/types.d.ts.map +0 -1
  42. package/dist/cjs/components/CustomSelect/types.js +0 -6
  43. package/dist/cjs/components/CustomSelect/types.js.map +0 -1
  44. package/dist/components/CustomSelect/helpers.d.ts +0 -8
  45. package/dist/components/CustomSelect/helpers.d.ts.map +0 -1
  46. package/dist/components/CustomSelect/helpers.js +0 -48
  47. package/dist/components/CustomSelect/helpers.js.map +0 -1
  48. package/dist/components/CustomSelect/types.d.ts +0 -12
  49. package/dist/components/CustomSelect/types.d.ts.map +0 -1
  50. package/dist/components/CustomSelect/types.js +0 -3
  51. package/dist/components/CustomSelect/types.js.map +0 -1
  52. package/dist/cssm/components/CustomSelect/helpers.d.ts +0 -8
  53. package/dist/cssm/components/CustomSelect/helpers.d.ts.map +0 -1
  54. package/dist/cssm/components/CustomSelect/helpers.js +0 -44
  55. package/dist/cssm/components/CustomSelect/helpers.js.map +0 -1
  56. package/dist/cssm/components/CustomSelect/types.d.ts +0 -12
  57. package/dist/cssm/components/CustomSelect/types.d.ts.map +0 -1
  58. package/dist/cssm/components/CustomSelect/types.js +0 -3
  59. package/dist/cssm/components/CustomSelect/types.js.map +0 -1
  60. package/src/components/CustomSelect/helpers.tsx +0 -61
  61. package/src/components/CustomSelect/types.ts +0 -15
@@ -38497,7 +38497,7 @@ function ChipsSelect_unsupported_iterable_to_array(o, minLen) {
38497
38497
 
38498
38498
 
38499
38499
 
38500
- var ChipsSelect_findIndexAfter = function() {
38500
+ var findIndexAfter = function() {
38501
38501
  var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], startIndex = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : -1;
38502
38502
  if (startIndex >= options.length - 1) {
38503
38503
  return -1;
@@ -38506,7 +38506,7 @@ var ChipsSelect_findIndexAfter = function() {
38506
38506
  return i > startIndex && (!isNotServicePreset(option) || !option.disabled);
38507
38507
  });
38508
38508
  };
38509
- var ChipsSelect_findIndexBefore = function() {
38509
+ var findIndexBefore = function() {
38510
38510
  var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], endIndex = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : options.length;
38511
38511
  var result = -1;
38512
38512
  if (endIndex <= 0) {
@@ -38664,11 +38664,11 @@ var ChipsSelect_findIndexBefore = function() {
38664
38664
  var focusOption = function(nextIndex, type) {
38665
38665
  var index = nextIndex === null ? -1 : nextIndex;
38666
38666
  if (type === FOCUS_ACTION_NEXT) {
38667
- var _$nextIndex = ChipsSelect_findIndexAfter(options, index);
38668
- index = _$nextIndex === -1 ? ChipsSelect_findIndexAfter(options) : _$nextIndex; // Следующий за index или первый валидный до index
38667
+ var _$nextIndex = findIndexAfter(options, index);
38668
+ index = _$nextIndex === -1 ? findIndexAfter(options) : _$nextIndex; // Следующий за index или первый валидный до index
38669
38669
  } else if (type === FOCUS_ACTION_PREV) {
38670
- var beforeIndex = ChipsSelect_findIndexBefore(options, index);
38671
- index = beforeIndex === -1 ? ChipsSelect_findIndexBefore(options) : beforeIndex; // Предшествующий index или последний валидный после index
38670
+ var beforeIndex = findIndexBefore(options, index);
38671
+ index = beforeIndex === -1 ? findIndexBefore(options) : beforeIndex; // Предшествующий index или последний валидный после index
38672
38672
  }
38673
38673
  focusOptionByIndex(index, focusedOptionIndex);
38674
38674
  };
@@ -40908,6 +40908,8 @@ function CustomSelectInput_object_without_properties_loose(source, excluded) {
40908
40908
 
40909
40909
 
40910
40910
 
40911
+
40912
+
40911
40913
  var CustomSelectInput_sizeYClassNames = {
40912
40914
  none: "vkuiCustomSelectInput--sizeY-none",
40913
40915
  compact: "vkuiCustomSelectInput--sizeY-compact"
@@ -40916,7 +40918,7 @@ var CustomSelectInput_sizeYClassNames = {
40916
40918
  * @since 5.10.0
40917
40919
  * @private
40918
40920
  */ var CustomSelectInput_CustomSelectInput = function(_param) {
40919
- var _param_align = _param.align, align = _param_align === void 0 ? 'left' : _param_align, getRef = _param.getRef, className = _param.className, getRootRef = _param.getRootRef, style = _param.style, before = _param.before, after = _param.after, status = _param.status, selectedOptionLabel = _param.selectedOptionLabel, _param_selectType = _param.selectType, selectType = _param_selectType === void 0 ? 'default' : _param_selectType, multiline = _param.multiline, disabled = _param.disabled, fetching = _param.fetching, labelTextTestId = _param.labelTextTestId, searchable = _param.searchable, restInputProps = CustomSelectInput_object_without_properties(_param, [
40921
+ var _param_align = _param.align, align = _param_align === void 0 ? 'left' : _param_align, getRef = _param.getRef, className = _param.className, getRootRef = _param.getRootRef, style = _param.style, before = _param.before, after = _param.after, status = _param.status, children = _param.children, placeholder = _param.placeholder, _param_selectType = _param.selectType, selectType = _param_selectType === void 0 ? 'default' : _param_selectType, multiline = _param.multiline, disabled = _param.disabled, fetching = _param.fetching, labelTextTestId = _param.labelTextTestId, restProps = CustomSelectInput_object_without_properties(_param, [
40920
40922
  "align",
40921
40923
  "getRef",
40922
40924
  "className",
@@ -40925,32 +40927,35 @@ var CustomSelectInput_sizeYClassNames = {
40925
40927
  "before",
40926
40928
  "after",
40927
40929
  "status",
40928
- "selectedOptionLabel",
40930
+ "children",
40931
+ "placeholder",
40929
40932
  "selectType",
40930
40933
  "multiline",
40931
40934
  "disabled",
40932
40935
  "fetching",
40933
- "labelTextTestId",
40934
- "searchable"
40936
+ "labelTextTestId"
40935
40937
  ]);
40936
40938
  var _useAdaptivity = useAdaptivity(), _useAdaptivity_sizeY = _useAdaptivity.sizeY, sizeY = _useAdaptivity_sizeY === void 0 ? 'none' : _useAdaptivity_sizeY;
40939
+ var title = children || placeholder;
40940
+ var showLabelOrPlaceholder = !Boolean(restProps.value);
40937
40941
  var handleRootRef = useExternRef(getRootRef);
40938
- var platform = usePlatform();
40939
- var input = /*#__PURE__*/ React.createElement(SelectTypography, CustomSelectInput_object_spread_props(CustomSelectInput_object_spread({
40940
- selectType: selectType,
40942
+ var focusWithin = useFocusWithin(handleRootRef);
40943
+ var input = /*#__PURE__*/ React.createElement(Text, CustomSelectInput_object_spread_props(CustomSelectInput_object_spread({
40941
40944
  type: "text"
40942
- }, restInputProps), {
40945
+ }, restProps), {
40943
40946
  disabled: disabled && !fetching,
40944
- readOnly: restInputProps.readOnly || !searchable || disabled && fetching,
40947
+ readOnly: restProps.readOnly || disabled && fetching,
40945
40948
  Component: "input",
40946
40949
  normalize: false,
40947
- className: "vkuiCustomSelectInput__input",
40948
- getRootRef: getRef
40950
+ className: classNames("vkuiCustomSelectInput__el", (restProps.readOnly || showLabelOrPlaceholder && !focusWithin) && "vkuiCustomSelectInput__el--cursor-pointer"),
40951
+ getRootRef: getRef,
40952
+ placeholder: children ? '' : placeholder
40949
40953
  }));
40954
+ var platform = usePlatform();
40950
40955
  return /*#__PURE__*/ React.createElement(FormField, {
40951
40956
  Component: "div",
40952
40957
  style: style,
40953
- className: classNames("vkuiCustomSelectInput", align === 'right' && "vkuiCustomSelectInput--align-right", align === 'center' && "vkuiCustomSelectInput--align-center", !selectedOptionLabel && "vkuiCustomSelectInput--empty", multiline && "vkuiCustomSelectInput--multiline", sizeY !== 'regular' && CustomSelectInput_sizeYClassNames[sizeY], before && "vkuiCustomSelectInput--hasBefore", after && "vkuiCustomSelectInput--hasAfter", className),
40958
+ className: classNames("vkuiCustomSelectInput", align === 'right' && "vkuiCustomSelectInput--align-right", align === 'center' && "vkuiCustomSelectInput--align-center", !children && "vkuiCustomSelectInput--empty", multiline && "vkuiCustomSelectInput--multiline", sizeY !== 'regular' && CustomSelectInput_sizeYClassNames[sizeY], before && "vkuiCustomSelectInput--hasBefore", after && "vkuiCustomSelectInput--hasAfter", className),
40954
40959
  getRootRef: handleRootRef,
40955
40960
  before: before,
40956
40961
  after: after,
@@ -40959,97 +40964,17 @@ var CustomSelectInput_sizeYClassNames = {
40959
40964
  status: status
40960
40965
  }, /*#__PURE__*/ React.createElement("div", {
40961
40966
  className: "vkuiCustomSelectInput__input-group"
40962
- }, !searchable && platform === 'ios' ? /*#__PURE__*/ React.createElement(VisuallyHidden, null, input) : input, /*#__PURE__*/ React.createElement("div", {
40963
- className: classNames("vkuiCustomSelectInput__label-wrapper", className),
40967
+ }, /*#__PURE__*/ React.createElement("div", {
40968
+ className: classNames("vkuiCustomSelectInput__container", className),
40964
40969
  tabIndex: -1,
40965
40970
  "aria-hidden": true,
40966
40971
  "data-testid": labelTextTestId
40967
40972
  }, /*#__PURE__*/ React.createElement(SelectTypography, {
40968
40973
  selectType: selectType,
40969
- className: "vkuiCustomSelectInput__label"
40970
- }, selectedOptionLabel || restInputProps.placeholder))));
40974
+ className: "vkuiCustomSelectInput__title"
40975
+ }, showLabelOrPlaceholder && title)), restProps.readOnly && platform === 'ios' ? /*#__PURE__*/ React.createElement(VisuallyHidden, null, input) : input));
40971
40976
  };
40972
40977
 
40973
- ;// CONCATENATED MODULE: ./src/components/CustomSelect/helpers.tsx
40974
- function helpers_object_without_properties(source, excluded) {
40975
- if (source == null) return {};
40976
- var target = helpers_object_without_properties_loose(source, excluded);
40977
- var key, i;
40978
- if (Object.getOwnPropertySymbols) {
40979
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
40980
- for(i = 0; i < sourceSymbolKeys.length; i++){
40981
- key = sourceSymbolKeys[i];
40982
- if (excluded.indexOf(key) >= 0) continue;
40983
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
40984
- target[key] = source[key];
40985
- }
40986
- }
40987
- return target;
40988
- }
40989
- function helpers_object_without_properties_loose(source, excluded) {
40990
- if (source == null) return {};
40991
- var target = {};
40992
- var sourceKeys = Object.keys(source);
40993
- var key, i;
40994
- for(i = 0; i < sourceKeys.length; i++){
40995
- key = sourceKeys[i];
40996
- if (excluded.indexOf(key) >= 0) continue;
40997
- target[key] = source[key];
40998
- }
40999
- return target;
41000
- }
41001
-
41002
-
41003
-
41004
- var helpers_findIndexAfter = function() {
41005
- var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], startIndex = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : -1;
41006
- if (startIndex >= options.length - 1) {
41007
- return -1;
41008
- }
41009
- return options.findIndex(function(option, i) {
41010
- return i > startIndex && !option.disabled;
41011
- });
41012
- };
41013
- var helpers_findIndexBefore = function() {
41014
- var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], endIndex = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : options.length;
41015
- var result = -1;
41016
- if (endIndex <= 0) {
41017
- return result;
41018
- }
41019
- for(var i = endIndex - 1; i >= 0; i--){
41020
- var option = options[i];
41021
- if (!option.disabled) {
41022
- result = i;
41023
- break;
41024
- }
41025
- }
41026
- return result;
41027
- };
41028
- function helpers_findSelectedIndex() {
41029
- var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], value = arguments.length > 1 ? arguments[1] : void 0, withClear = arguments.length > 2 ? arguments[2] : void 0;
41030
- if (withClear && value === '') {
41031
- return -1;
41032
- }
41033
- var _options_findIndex;
41034
- return (_options_findIndex = options.findIndex(function(item) {
41035
- value = typeof item.value === 'number' ? Number(value) : value;
41036
- return item.value === value;
41037
- })) !== null && _options_findIndex !== void 0 ? _options_findIndex : -1;
41038
- }
41039
- function helpers_calculateInputValueFromOptions() {
41040
- var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], selectValue = arguments.length > 1 ? arguments[1] : void 0;
41041
- var selectedOption = options.find(function(option) {
41042
- return option.value === selectValue;
41043
- });
41044
- return selectedOption ? getTextFromChildren(selectedOption.label) : '';
41045
- }
41046
- function helpers_defaultRenderOptionFn(_param) {
41047
- var option = _param.option, props = helpers_object_without_properties(_param, [
41048
- "option"
41049
- ]);
41050
- return /*#__PURE__*/ React.createElement(CustomSelectOption, props);
41051
- }
41052
-
41053
40978
  ;// CONCATENATED MODULE: ./src/components/CustomSelect/CustomSelect.module.css
41054
40979
  // extracted by mini-css-extract-plugin
41055
40980
 
@@ -41198,9 +41123,35 @@ function CustomSelect_unsupported_iterable_to_array(o, minLen) {
41198
41123
 
41199
41124
 
41200
41125
 
41126
+
41127
+
41201
41128
  var CustomSelect_sizeYClassNames = CustomSelect_define_property({
41202
41129
  none: "vkuiCustomSelect--sizeY-none"
41203
41130
  }, 'compact', "vkuiCustomSelect--sizeY-compact");
41131
+ var CustomSelect_findIndexAfter = function() {
41132
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], startIndex = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : -1;
41133
+ if (startIndex >= options.length - 1) {
41134
+ return -1;
41135
+ }
41136
+ return options.findIndex(function(option, i) {
41137
+ return i > startIndex && !option.disabled;
41138
+ });
41139
+ };
41140
+ var CustomSelect_findIndexBefore = function() {
41141
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], endIndex = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : options.length;
41142
+ var result = -1;
41143
+ if (endIndex <= 0) {
41144
+ return result;
41145
+ }
41146
+ for(var i = endIndex - 1; i >= 0; i--){
41147
+ var option = options[i];
41148
+ if (!option.disabled) {
41149
+ result = i;
41150
+ break;
41151
+ }
41152
+ }
41153
+ return result;
41154
+ };
41204
41155
  var CustomSelect_warn = warnOnce('CustomSelect');
41205
41156
  var checkOptionsValueType = function(options) {
41206
41157
  if (new Set(options.map(function(item) {
@@ -41209,9 +41160,26 @@ var checkOptionsValueType = function(options) {
41209
41160
  CustomSelect_warn('Некоторые значения ваших опций имеют разные типы. onChange всегда возвращает строковый тип.', 'error');
41210
41161
  }
41211
41162
  };
41163
+ function defaultRenderOptionFn(_param) {
41164
+ var option = _param.option, props = CustomSelect_object_without_properties(_param, [
41165
+ "option"
41166
+ ]);
41167
+ return /*#__PURE__*/ React.createElement(CustomSelectOption, props);
41168
+ }
41212
41169
  var handleOptionDown = function(e) {
41213
41170
  e.preventDefault();
41214
41171
  };
41172
+ function findSelectedIndex() {
41173
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], value = arguments.length > 1 ? arguments[1] : void 0, withClear = arguments.length > 2 ? arguments[2] : void 0;
41174
+ if (withClear && value === '') {
41175
+ return -1;
41176
+ }
41177
+ var _options_findIndex;
41178
+ return (_options_findIndex = options.findIndex(function(item) {
41179
+ value = typeof item.value === 'number' ? Number(value) : value;
41180
+ return item.value === value;
41181
+ })) !== null && _options_findIndex !== void 0 ? _options_findIndex : -1;
41182
+ }
41215
41183
  var filter = function(options, inputValue, filterFn) {
41216
41184
  return typeof filterFn === 'function' ? options.filter(function(option) {
41217
41185
  return filterFn(inputValue, option);
@@ -41266,16 +41234,13 @@ var filter = function(options, inputValue, filterFn) {
41266
41234
  var scrollBoxRef = React.useRef(null);
41267
41235
  var selectElRef = useExternRef(getRef);
41268
41236
  var optionsWrapperRef = React.useRef(null);
41269
- var selectInputRef = useExternRef(getSelectInputRef);
41270
41237
  var _React_useState1 = CustomSelect_sliced_to_array(React.useState(-1), 2), focusedOptionIndex = _React_useState1[0], setFocusedOptionIndex = _React_useState1[1];
41271
41238
  var _React_useState2 = CustomSelect_sliced_to_array(React.useState(props.value !== undefined), 2), isControlledOutside = _React_useState2[0], setIsControlledOutside = _React_useState2[1];
41272
- var _React_useState3 = CustomSelect_sliced_to_array(React.useState(function() {
41239
+ var _React_useState3 = CustomSelect_sliced_to_array(React.useState(''), 2), inputValue = _React_useState3[0], setInputValue = _React_useState3[1];
41240
+ var _React_useState4 = CustomSelect_sliced_to_array(React.useState(function() {
41273
41241
  var _props_value, _ref;
41274
41242
  return (_ref = (_props_value = props.value) !== null && _props_value !== void 0 ? _props_value : defaultValue) !== null && _ref !== void 0 ? _ref : allowClearButton ? '' : undefined;
41275
- }), 2), nativeSelectValue = _React_useState3[0], setNativeSelectValue = _React_useState3[1];
41276
- var _React_useState4 = CustomSelect_sliced_to_array(React.useState(function() {
41277
- return calculateInputValueFromOptions(optionsProp, nativeSelectValue);
41278
- }), 2), inputValue = _React_useState4[0], setInputValue = _React_useState4[1];
41243
+ }), 2), nativeSelectValue = _React_useState4[0], setNativeSelectValue = _React_useState4[1];
41279
41244
  var _React_useState5 = CustomSelect_sliced_to_array(React.useState(popupDirection), 2), popperPlacement = _React_useState5[0], setPopperPlacement = _React_useState5[1];
41280
41245
  var _React_useState6 = CustomSelect_sliced_to_array(React.useState(optionsProp), 2), options = _React_useState6[0], setOptions = _React_useState6[1];
41281
41246
  var _props_value;
@@ -41402,6 +41367,7 @@ var filter = function(options, inputValue, filterFn) {
41402
41367
  * Сброс происходит в одном из эффекте `updateOptionsAndSelectedOptionIndex()`.
41403
41368
  */ var close = React.useCallback(function() {
41404
41369
  resetKeyboardInput();
41370
+ setInputValue('');
41405
41371
  setOpened(false);
41406
41372
  resetFocusedOption();
41407
41373
  onClose === null || onClose === void 0 ? void 0 : onClose();
@@ -41412,8 +41378,8 @@ var filter = function(options, inputValue, filterFn) {
41412
41378
  ]);
41413
41379
  var selectOption = React.useCallback(function(index) {
41414
41380
  var item = options[index];
41415
- close();
41416
41381
  setNativeSelectValue(item === null || item === void 0 ? void 0 : item.value);
41382
+ close();
41417
41383
  var shouldTriggerOnChangeWhenControlledAndInnerValueIsOutOfSync = isControlledOutside && props.value !== nativeSelectValue && nativeSelectValue === (item === null || item === void 0 ? void 0 : item.value);
41418
41384
  if (shouldTriggerOnChangeWhenControlledAndInnerValueIsOutOfSync) {
41419
41385
  var _selectElRef_current;
@@ -41457,23 +41423,18 @@ var filter = function(options, inputValue, filterFn) {
41457
41423
  bubbles: true
41458
41424
  });
41459
41425
  (_selectElRef_current = selectElRef.current) === null || _selectElRef_current === void 0 ? void 0 : _selectElRef_current.dispatchEvent(event);
41460
- setInputValue(calculateInputValueFromOptions(optionsProp, nativeSelectValue));
41461
41426
  }, [
41462
41427
  close,
41463
- selectElRef,
41464
- optionsProp,
41465
- nativeSelectValue
41428
+ selectElRef
41466
41429
  ]);
41467
41430
  var onFocus = React.useCallback(function() {
41468
- var _selectElRef_current, _selectInputRef_current;
41431
+ var _selectElRef_current;
41469
41432
  var event = new Event('focusin', {
41470
41433
  bubbles: true
41471
41434
  });
41472
41435
  (_selectElRef_current = selectElRef.current) === null || _selectElRef_current === void 0 ? void 0 : _selectElRef_current.dispatchEvent(event);
41473
- (_selectInputRef_current = selectInputRef.current) === null || _selectInputRef_current === void 0 ? void 0 : _selectInputRef_current.select();
41474
41436
  }, [
41475
- selectElRef,
41476
- selectInputRef
41437
+ selectElRef
41477
41438
  ]);
41478
41439
  var onClick = React.useCallback(function() {
41479
41440
  if (opened) {
@@ -41494,11 +41455,11 @@ var filter = function(options, inputValue, filterFn) {
41494
41455
  var focusOption = React.useCallback(function(type) {
41495
41456
  var index = focusedOptionIndex;
41496
41457
  if (type === 'next') {
41497
- var nextIndex = findIndexAfter(options, index);
41498
- index = nextIndex === -1 ? findIndexAfter(options) : nextIndex; // Следующий за index или первый валидный до index
41458
+ var nextIndex = CustomSelect_findIndexAfter(options, index);
41459
+ index = nextIndex === -1 ? CustomSelect_findIndexAfter(options) : nextIndex; // Следующий за index или первый валидный до index
41499
41460
  } else if (type === 'prev') {
41500
- var beforeIndex = findIndexBefore(options, index);
41501
- index = beforeIndex === -1 ? findIndexBefore(options) : beforeIndex; // Предшествующий index или последний валидный после index
41461
+ var beforeIndex = CustomSelect_findIndexBefore(options, index);
41462
+ index = beforeIndex === -1 ? CustomSelect_findIndexBefore(options) : beforeIndex; // Предшествующий index или последний валидный после index
41502
41463
  }
41503
41464
  focusOptionByIndex(index);
41504
41465
  }, [
@@ -41506,38 +41467,21 @@ var filter = function(options, inputValue, filterFn) {
41506
41467
  focusedOptionIndex,
41507
41468
  options
41508
41469
  ]);
41509
- React.useEffect(function filterOptions() {
41470
+ React.useEffect(function updateOptionsAndSelectedOptionIndex() {
41471
+ var _props_value, _ref;
41472
+ var value = (_ref = (_props_value = props.value) !== null && _props_value !== void 0 ? _props_value : nativeSelectValue) !== null && _ref !== void 0 ? _ref : defaultValue;
41510
41473
  var options = searchable && inputValue !== undefined ? filter(optionsProp, inputValue, filterFn) : optionsProp;
41511
41474
  setOptions(options);
41475
+ setSelectedOptionIndex(findSelectedIndex(options, value, allowClearButton));
41512
41476
  }, [
41513
41477
  filterFn,
41514
41478
  inputValue,
41479
+ nativeSelectValue,
41515
41480
  optionsProp,
41516
- searchable
41517
- ]);
41518
- var _props_value1, _ref;
41519
- var selectValue = (_ref = (_props_value1 = props.value) !== null && _props_value1 !== void 0 ? _props_value1 : nativeSelectValue) !== null && _ref !== void 0 ? _ref : defaultValue;
41520
- React.useEffect(function updateSelectedOptionIndexOnValueChange() {
41521
- setSelectedOptionIndex(findSelectedIndex(options, selectValue, allowClearButton));
41522
- }, [
41523
- selectValue,
41524
- allowClearButton,
41525
- options
41526
- ]);
41527
- var prevSelectValueRef = React.useRef(selectValue);
41528
- React.useEffect(function updateInputValueOnSelectValueChange() {
41529
- if (prevSelectValueRef.current === selectValue) {
41530
- return;
41531
- }
41532
- setInputValue(calculateInputValueFromOptions(optionsProp, selectValue));
41533
- }, [
41534
- selectValue,
41535
- optionsProp
41536
- ]);
41537
- React.useEffect(function updatePrevSelectValue() {
41538
- prevSelectValueRef.current = selectValue;
41539
- }, [
41540
- selectValue
41481
+ defaultValue,
41482
+ props.value,
41483
+ searchable,
41484
+ allowClearButton
41541
41485
  ]);
41542
41486
  var onNativeSelectChange = function(e) {
41543
41487
  var newSelectedOptionIndex = findSelectedIndex(options, e.currentTarget.value, allowClearButton);
@@ -41702,6 +41646,7 @@ var filter = function(options, inputValue, filterFn) {
41702
41646
  renderDropdown,
41703
41647
  renderOption
41704
41648
  ]);
41649
+ var selectInputRef = useExternRef(getSelectInputRef);
41705
41650
  var focusOnInputTimerRef = React.useRef();
41706
41651
  var focusOnInput = React.useCallback(function() {
41707
41652
  clearTimeout(focusOnInputTimerRef.current);
@@ -41782,14 +41727,11 @@ var filter = function(options, inputValue, filterFn) {
41782
41727
  selectInputRef
41783
41728
  ]);
41784
41729
  var preventInputBlurWhenClickInsideFocusedSelectArea = function(e) {
41785
- var _selectInputRef_current;
41786
41730
  // Так как инпут больше не оборачивается пустым лэйблом, то клик внутри обертки,
41787
41731
  // но вне инпута (например по иконке дропдауна), будет убирать фокус с инпута.
41788
41732
  // Чтобы в такой ситуации отключить blur инпута мы превентим mousedown событие обёртки
41789
41733
  var isInputFocused = document && document.activeElement === selectInputRef.current;
41790
- var clickTarget = e.target;
41791
- var inputClicked = (_selectInputRef_current = selectInputRef.current) === null || _selectInputRef_current === void 0 ? void 0 : _selectInputRef_current.contains(clickTarget);
41792
- if (isInputFocused && !inputClicked) {
41734
+ if (isInputFocused) {
41793
41735
  e.preventDefault();
41794
41736
  }
41795
41737
  };
@@ -41799,15 +41741,19 @@ var filter = function(options, inputValue, filterFn) {
41799
41741
  var selectInputAriaProps = (_obj = {
41800
41742
  'role': 'combobox',
41801
41743
  'aria-controls': popupAriaId,
41744
+ 'aria-owns': popupAriaId,
41802
41745
  'aria-expanded': opened
41803
41746
  }, CustomSelect_define_property(_obj, 'aria-activedescendant', ariaActiveDescendantId && opened ? "".concat(popupAriaId, "-").concat(ariaActiveDescendantId) : undefined), CustomSelect_define_property(_obj, 'aria-labelledby', ariaLabelledBy), CustomSelect_define_property(_obj, 'aria-haspopup', 'listbox'), CustomSelect_define_property(_obj, 'aria-autocomplete', 'none'), _obj);
41747
+ var focusWithin = useFocusWithin(handleRootRef);
41804
41748
  return /*#__PURE__*/ React.createElement("div", {
41805
41749
  className: classNames("vkuiCustomSelect", sizeY !== 'regular' && CustomSelect_sizeYClassNames[sizeY], className),
41806
41750
  style: style,
41807
41751
  ref: handleRootRef,
41808
41752
  onClick: passClickAndFocusToInputOnClick,
41809
41753
  onMouseDown: preventInputBlurWhenClickInsideFocusedSelectArea
41810
- }, /*#__PURE__*/ React.createElement(CustomSelectInput, CustomSelect_object_spread_props(CustomSelect_object_spread({
41754
+ }, focusWithin && selected && !opened && /*#__PURE__*/ React.createElement(VisuallyHidden, {
41755
+ "aria-live": "polite"
41756
+ }, selected.label), /*#__PURE__*/ React.createElement(CustomSelectInput, CustomSelect_object_spread_props(CustomSelect_object_spread({
41811
41757
  autoComplete: "off",
41812
41758
  autoCapitalize: "none",
41813
41759
  autoCorrect: "off",
@@ -41817,7 +41763,7 @@ var filter = function(options, inputValue, filterFn) {
41817
41763
  onFocus: onFocus,
41818
41764
  onBlur: onBlur,
41819
41765
  className: openedClassNames,
41820
- searchable: searchable,
41766
+ readOnly: !searchable,
41821
41767
  fetching: fetching,
41822
41768
  value: inputValue,
41823
41769
  onKeyUp: handleKeyUp,
@@ -41826,9 +41772,8 @@ var filter = function(options, inputValue, filterFn) {
41826
41772
  onClick: onClick,
41827
41773
  before: before,
41828
41774
  after: afterIcons,
41829
- selectType: selectType,
41830
- selectedOptionLabel: selected === null || selected === void 0 ? void 0 : selected.label
41831
- })), /*#__PURE__*/ React.createElement("select", {
41775
+ selectType: selectType
41776
+ }), selected === null || selected === void 0 ? void 0 : selected.label), /*#__PURE__*/ React.createElement("select", {
41832
41777
  ref: selectElRef,
41833
41778
  name: name,
41834
41779
  onChange: onNativeSelectChange,
@@ -2,12 +2,22 @@ import * as React from 'react';
2
2
  import { type FilterFn } from '../../lib/select';
3
3
  import { TrackerOptionsProps } from '../CustomScrollView/useTrackerVisibility';
4
4
  import { CustomSelectDropdownProps } from '../CustomSelectDropdown/CustomSelectDropdown';
5
+ import { type CustomSelectOptionProps } from '../CustomSelectOption/CustomSelectOption';
5
6
  import { FormFieldProps } from '../FormField/FormField';
6
7
  import { NativeSelectProps } from '../NativeSelect/NativeSelect';
7
8
  import { SelectType } from '../Select/Select';
8
9
  import { type CustomSelectClearButtonProps } from './CustomSelectClearButton';
9
- import type { CustomSelectOptionInterface, CustomSelectRenderOption } from './types';
10
- export type { CustomSelectClearButtonProps, CustomSelectOptionInterface, CustomSelectRenderOption };
10
+ type SelectValue = React.SelectHTMLAttributes<HTMLSelectElement>['value'];
11
+ export interface CustomSelectOptionInterface {
12
+ value: SelectValue;
13
+ label: React.ReactElement | string;
14
+ disabled?: boolean;
15
+ [index: string]: any;
16
+ }
17
+ export interface CustomSelectRenderOption<T extends CustomSelectOptionInterface> extends CustomSelectOptionProps {
18
+ option: T;
19
+ }
20
+ export type { CustomSelectClearButtonProps };
11
21
  export interface SelectProps<OptionInterfaceT extends CustomSelectOptionInterface = CustomSelectOptionInterface> extends NativeSelectProps, Omit<FormFieldProps, 'maxHeight'>, TrackerOptionsProps, Pick<CustomSelectDropdownProps, 'overscrollBehavior' | 'autoHideScrollbar' | 'autoHideScrollbarDelay'> {
12
22
  /**
13
23
  * ref на внутрений компонент input
@@ -1 +1 @@
1
- {"version":3,"file":"CustomSelect.d.ts","sourceRoot":"","sources":["../../../../src/components/CustomSelect/CustomSelect.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGlE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EAEL,yBAAyB,EAC1B,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C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