@cloud-ru/ds-fields 3.0.8-preview-63cac1a0.0 → 3.0.8-preview-a132b2c9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-ru/ds-fields",
3
- "version": "3.0.8-preview-63cac1a0.0",
3
+ "version": "3.0.8-preview-a132b2c9.0",
4
4
  "description": "Поля ввода с единой обёрткой label/caption/hint/error и общими осями size/validationState — текст, пароль, число, ползунок, дата, время, выбор, цвет.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,23 +40,23 @@
40
40
  "merge-refs": "^2.0.0",
41
41
  "react-textarea-autosize": "^8.5.9",
42
42
  "@cloud-ru/ds-adaptive": "1.0.3",
43
- "@cloud-ru/ds-bottom-sheet": "2.0.10-preview-63cac1a0.0",
44
43
  "@cloud-ru/ds-button": "1.0.5",
45
- "@cloud-ru/ds-calendar": "1.1.22-preview-63cac1a0.0",
44
+ "@cloud-ru/ds-bottom-sheet": "2.0.10-preview-a132b2c9.0",
45
+ "@cloud-ru/ds-calendar": "1.1.22-preview-a132b2c9.0",
46
46
  "@cloud-ru/ds-divider": "1.0.3",
47
- "@cloud-ru/ds-dropdown": "1.1.11-preview-63cac1a0.0",
48
- "@cloud-ru/ds-color-picker": "1.0.22-preview-63cac1a0.0",
49
- "@cloud-ru/ds-field-decorator": "1.1.10-preview-63cac1a0.0",
47
+ "@cloud-ru/ds-color-picker": "1.0.21",
48
+ "@cloud-ru/ds-dropdown": "1.1.11-preview-a132b2c9.0",
49
+ "@cloud-ru/ds-field-decorator": "1.1.9",
50
50
  "@cloud-ru/ds-icons": "1.7.2",
51
+ "@cloud-ru/ds-list": "3.0.8-preview-a132b2c9.0",
51
52
  "@cloud-ru/ds-input-private": "1.0.15",
52
- "@cloud-ru/ds-list": "3.0.8-preview-63cac1a0.0",
53
53
  "@cloud-ru/ds-loader": "1.0.4",
54
+ "@cloud-ru/ds-skeleton": "1.0.3",
54
55
  "@cloud-ru/ds-materials": "2.0.2",
56
+ "@cloud-ru/ds-slider": "1.0.17",
55
57
  "@cloud-ru/ds-scroll": "1.0.6",
56
- "@cloud-ru/ds-skeleton": "1.0.3",
57
- "@cloud-ru/ds-slider": "1.0.18-preview-63cac1a0.0",
58
- "@cloud-ru/ds-tag": "1.1.21-preview-63cac1a0.0",
59
- "@cloud-ru/ds-tooltip": "1.0.18-preview-63cac1a0.0",
58
+ "@cloud-ru/ds-tag": "1.1.21-preview-a132b2c9.0",
59
+ "@cloud-ru/ds-tooltip": "1.0.17",
60
60
  "@cloud-ru/ds-utils": "1.3.0"
61
61
  }
62
62
  }
@@ -146,25 +146,25 @@ export const FieldSecure = forwardRef<HTMLInputElement, FieldSecureProps>(functi
146
146
  [onChange, setValue],
147
147
  );
148
148
 
149
- const ensureAsyncValue = useCallback(async (): Promise<boolean> => {
149
+ const ensureAsyncValue = useCallback(async (): Promise<{ success: true; value: string } | { success: false }> => {
150
150
  if (!asyncValueGetter || isAsyncLoaded) {
151
- return true;
151
+ return { success: true, value };
152
152
  }
153
153
  setIsLoading(true);
154
154
  try {
155
155
  const next = await asyncValueGetter();
156
156
  setIsAsyncLoaded(true);
157
157
  emitChange(next);
158
- return true;
158
+ return { success: true, value: next };
159
159
  } catch {
160
- return false;
160
+ return { success: false };
161
161
  } finally {
162
162
  setIsLoading(false);
163
163
  }
164
- }, [asyncValueGetter, emitChange, isAsyncLoaded]);
164
+ }, [asyncValueGetter, emitChange, isAsyncLoaded, value]);
165
165
 
166
166
  const toggleHidden = useCallback(() => {
167
- ensureAsyncValue().then(success => {
167
+ ensureAsyncValue().then(({ success }) => {
168
168
  if (!success) {
169
169
  return;
170
170
  }
@@ -198,14 +198,14 @@ export const FieldSecure = forwardRef<HTMLInputElement, FieldSecureProps>(functi
198
198
 
199
199
  const onCopy = useCallback(
200
200
  () =>
201
- ensureAsyncValue().then(async success => {
202
- const copied = success && (await copyTextToClipboard(stringValue));
201
+ ensureAsyncValue().then(async result => {
202
+ const copied = result.success && (await copyTextToClipboard(result.value));
203
203
  if (copied) {
204
204
  onCopyButtonClick?.();
205
205
  }
206
206
  return copied;
207
207
  }),
208
- [ensureAsyncValue, onCopyButtonClick, stringValue],
208
+ [ensureAsyncValue, onCopyButtonClick],
209
209
  );
210
210
 
211
211
  const copyButtonSettings = useCopyButton({
@@ -1,3 +1,4 @@
1
+ import { isMobileLayout, useAdaptiveLayout } from '@cloud-ru/ds-adaptive';
1
2
  import { ChevronDownSVG } from '@cloud-ru/ds-icons/interface/system';
2
3
  import { InputPrivate, useButtonNavigation, useClearButton } from '@cloud-ru/ds-input-private';
3
4
  import { Droplist, ItemId } from '@cloud-ru/ds-list';
@@ -45,6 +46,7 @@ import {
45
46
  getMissingSelectedItems,
46
47
  getSelectedIds,
47
48
  isMultiple,
49
+ resolveAddCustomOptionTriggers,
48
50
  TAG_SIZE_MAP,
49
51
  WithIdContent,
50
52
  } from './utils';
@@ -122,6 +124,7 @@ export const FieldSelect = forwardRef<HTMLInputElement, FieldSelectProps>(functi
122
124
  const onMultipleChange = onChange as FieldSelectMultipleProps['onChange'];
123
125
 
124
126
  const resolvedAutoFocus = useAdaptiveAutoFocus(autoFocus, layoutPresets);
127
+ const { layoutType } = useAdaptiveLayout();
125
128
 
126
129
  const inputRef = useRef<HTMLInputElement>(null);
127
130
  // Отдельный ref на реальный <input>: `inputRef.current` перезаписывается span-обёрткой PopoverPrivate.
@@ -186,6 +189,13 @@ export const FieldSelect = forwardRef<HTMLInputElement, FieldSelectProps>(functi
186
189
  );
187
190
 
188
191
  const allItems = useMemo(() => [...(pinTop ?? []), ...items, ...(pinBottom ?? [])], [items, pinTop, pinBottom]);
192
+ const mobileSearchable = useMemo(
193
+ () =>
194
+ (searchable && flatten(allItems).filter(item => !('items' in item)).length > 5) ||
195
+ autocomplete ||
196
+ resolveAddCustomOptionTriggers({ allowCustomOption, addCustomOptionTriggers, multiple }).includes('enter'),
197
+ [searchable, allItems, autocomplete, allowCustomOption, addCustomOptionTriggers, multiple],
198
+ );
189
199
 
190
200
  const selectedIds = useMemo(
191
201
  () => getSelectedIds({ multiple, multipleValue, singleValue }),
@@ -799,6 +809,22 @@ export const FieldSelect = forwardRef<HTMLInputElement, FieldSelectProps>(functi
799
809
  <Droplist
800
810
  items={filteredItems}
801
811
  label={label}
812
+ search={
813
+ isMobileLayout(layoutType) && mobileSearchable && !readOnly && !disabled
814
+ ? {
815
+ value: inputValue,
816
+ onChange: handleInputChange,
817
+ onKeyDown: event => {
818
+ if (tryCommitFromKeyboard(event)) {
819
+ event.preventDefault();
820
+ event.stopPropagation();
821
+ }
822
+ },
823
+ placeholder,
824
+ loading,
825
+ }
826
+ : undefined
827
+ }
802
828
  pinTop={filteredPinTop}
803
829
  pinBottom={filteredPinBottom}
804
830
  trigger='click'
@@ -133,7 +133,7 @@ export function useCustomOption({
133
133
  );
134
134
 
135
135
  const tryCommitFromKeyboard = useCallback(
136
- (event: KeyboardEvent<HTMLInputElement>) => {
136
+ (event: Pick<KeyboardEvent, 'key'>) => {
137
137
  const trigger = getCustomOptionTriggerByKey(event.key);
138
138
 
139
139
  return trigger !== undefined && tryCommit(trigger);
@@ -123,6 +123,8 @@ type CommonSelectProps = FieldSelectDecoratorProps &
123
123
  widthStrategy?: DroplistProps['widthStrategy'];
124
124
  /**
125
125
  * Включить поиск/ввод в поле — пользователь печатает, список фильтруется по подстроке лейбла.
126
+ * На mobile поиск в sheet появляется при количестве вариантов больше 5.
127
+ * `autocomplete` и создание опции по Enter включают мобильный поиск независимо от количества вариантов.
126
128
  * @default true
127
129
  */
128
130
  searchable?: boolean;
@@ -205,7 +205,7 @@ export const FieldStepper = forwardRef<HTMLInputElement, FieldStepperProps>(func
205
205
 
206
206
  const handleInputChange = useCallback(
207
207
  (raw: string, event?: ChangeEvent<HTMLInputElement>) => {
208
- if (raw === '-') {
208
+ if (raw === '' || raw === '-') {
209
209
  return;
210
210
  }
211
211
  const parsed = Number(raw);
@@ -372,15 +372,7 @@ export const FieldStepper = forwardRef<HTMLInputElement, FieldStepperProps>(func
372
372
  <Divider orientation='vertical' variant='regular' />
373
373
  </div>
374
374
  </div>
375
- {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
376
- <div
377
- className={fieldStyles.fieldContainer}
378
- onClick={() => {
379
- if (!disabled && !readOnly && localRef.current) {
380
- localRef.current.focus();
381
- }
382
- }}
383
- >
375
+ <div className={fieldStyles.fieldContainer}>
384
376
  <div className={fieldStyles.contentWrapper}>
385
377
  <div className={cn(fieldStyles.inputLine, styles.inputLine)}>
386
378
  {prefix && <span className={fieldStyles.prefix}>{prefix}</span>}