@formixru/b2b-ui 4.1.0 → 4.2.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": "@formixru/b2b-ui",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,7 +9,6 @@
9
9
  type="text"
10
10
  :placeholder="props.placeholder"
11
11
  autocomplete="off"
12
- @input="emit('input', $event)"
13
12
  @focusin="emit('focusin', $event)"
14
13
  @focusout="emit('focusout', $event)"
15
14
  @keydown="emit('keydown', $event)"
@@ -22,7 +21,9 @@
22
21
  emit('submit');
23
22
  "
24
23
  >
25
- <span v-show="props.isLoading" class="search-input__spinner"><span class="spinner"></span></span>
24
+ <span v-show="props.isLoading" class="search-input__spinner">
25
+ <span class="spinner"></span>
26
+ </span>
26
27
  <svg v-show="!props.isLoading" class="search-input__submit-icon">
27
28
  <use :href="`${ICONS_PATH}#search`" />
28
29
  </svg>
@@ -40,7 +41,7 @@ import { ref, useTemplateRef, watch, watchEffect } from 'vue';
40
41
 
41
42
  const ICONS_PATH = window.ICONS_PATH;
42
43
 
43
- const emit = defineEmits(['input', 'focusin', 'focusout', 'keydown', 'submit']);
44
+ const emit = defineEmits(['focusin', 'focusout', 'keydown', 'submit']);
44
45
  const model = defineModel({ type: String, default: '' });
45
46
 
46
47
  const props = defineProps({
@@ -118,6 +118,11 @@ $b: '.suggest-input';
118
118
  color: $suggest-input-item-active-color;
119
119
  }
120
120
 
121
+ &_disabled {
122
+ color: $suggest-input-item-disabled-color;
123
+ pointer-events: none;
124
+ }
125
+
121
126
  mark {
122
127
  background-color: transparent;
123
128
  color: $suggest-input-item-mark-color;
@@ -10,7 +10,7 @@
10
10
  :input-delay="0"
11
11
  :input-css-classes="props.inputCssClasses"
12
12
  :is-loading="isLoading"
13
- @input="handleInput()"
13
+ @update:model-value="handleInput()"
14
14
  @focusin="focusin()"
15
15
  @focusout="focusout($event)"
16
16
  @keydown="arrowNavigation($event)"
@@ -33,7 +33,13 @@
33
33
  @keydown="arrowNavigation($event)"
34
34
  />
35
35
  <div v-show="isLoading && !props.searchInput" class="suggest-input__loader"><div class="spinner"></div></div>
36
- <button v-show="isClearVisible && !props.searchInput" ref="$clear" class="suggest-input__clear" type="button" @click="clear()">
36
+ <button
37
+ v-show="isClearVisible && !props.searchInput"
38
+ ref="$clear"
39
+ class="suggest-input__clear"
40
+ type="button"
41
+ @click="clear()"
42
+ >
37
43
  <svg class="suggest-input__clear-icon"><use :href="`${ICONS_PATH}#close`" /></svg>
38
44
  </button>
39
45
  <div v-show="showSuggests" ref="$list" class="suggest-input__list" @mouseover="focusSuggestIndex = -1">
@@ -42,7 +48,10 @@
42
48
  v-for="(item, index) in formattedSuggests"
43
49
  :key="index"
44
50
  class="suggest-input__list-item"
45
- :class="{ 'suggest-input__list-item_focus': index === focusSuggestIndex }"
51
+ :class="{
52
+ 'suggest-input__list-item_focus': index === focusSuggestIndex,
53
+ 'suggest-input__list-item_disabled': item.disabled,
54
+ }"
46
55
  tabindex="0"
47
56
  @click="select(item)"
48
57
  >
@@ -283,13 +292,17 @@ const clear = () => {
283
292
  showSuggests.value = false;
284
293
  };
285
294
 
286
- const select = ({ label, value }) => {
295
+ const select = (item) => {
296
+ if (item.disabled) {
297
+ return;
298
+ }
299
+
287
300
  cancelRequest();
288
- model.value = label;
301
+ model.value = item.label;
289
302
  showSuggests.value = false;
290
303
  emit('select', {
291
304
  input: model.value,
292
- value,
305
+ value: item.value,
293
306
  });
294
307
  };
295
308
 
@@ -298,15 +311,32 @@ const arrowNavigation = async (event) => {
298
311
  if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
299
312
  event.preventDefault();
300
313
 
314
+ const len = suggests.value.length;
315
+ if (len === 0) {
316
+ return;
317
+ }
318
+
301
319
  switch (event.key) {
302
320
  case 'ArrowDown': {
303
- focusSuggestIndex.value =
304
- suggests.value.length === focusSuggestIndex.value + 1 ? 0 : focusSuggestIndex.value + 1;
321
+ let nextIndex = focusSuggestIndex.value;
322
+ for (let i = 0; i < len; i++) {
323
+ nextIndex = (nextIndex + 1) % len;
324
+ if (!suggests.value[nextIndex]?.disabled) {
325
+ focusSuggestIndex.value = nextIndex;
326
+ break;
327
+ }
328
+ }
305
329
  break;
306
330
  }
307
331
  case 'ArrowUp': {
308
- focusSuggestIndex.value =
309
- focusSuggestIndex.value <= 0 ? suggests.value.length - 1 : focusSuggestIndex.value - 1;
332
+ let nextIndex = focusSuggestIndex.value === -1 ? 0 : focusSuggestIndex.value;
333
+ for (let i = 0; i < len; i++) {
334
+ nextIndex = (nextIndex - 1 + len) % len;
335
+ if (!suggests.value[nextIndex]?.disabled) {
336
+ focusSuggestIndex.value = nextIndex;
337
+ break;
338
+ }
339
+ }
310
340
  break;
311
341
  }
312
342
  }
@@ -334,11 +364,16 @@ const arrowNavigation = async (event) => {
334
364
  }
335
365
  }
336
366
  }
367
+
337
368
  if (event.key === 'Enter' && focusSuggestIndex.value >= 0) {
338
- // Ждём, чтобы событие нажатия Enter сработало у других обработчиков (например, в формах)
339
- setTimeout(() => {
340
- select(suggests.value[focusSuggestIndex.value]);
341
- });
369
+ const item = suggests.value[focusSuggestIndex.value];
370
+
371
+ if (item && !item.disabled) {
372
+ // Ждём, чтобы событие нажатия Enter сработало у других обработчиков (например, в формах)
373
+ setTimeout(() => {
374
+ select(item);
375
+ });
376
+ }
342
377
  }
343
378
  }
344
379
  };
@@ -602,6 +602,8 @@ $suggest-input-item-font: ('font-size': $font-size, 'line-height': $line-height)
602
602
  $suggest-input-item-mark-color: inherit !default;
603
603
  $suggest-input-item-mark-font: ('font-weight': bold) !default;
604
604
 
605
+ $suggest-input-item-disabled-color: $font-color-tertiary !default;
606
+
605
607
  $suggest-input-item-active-bg: $color-grey-90 !default;
606
608
  $suggest-input-item-active-color: $font-color-action !default;
607
609