77 'input-select_error': errors.length,
88 'input-select_active': isActive
99 }"
10- :tabindex =" !disabled ? 0 : 'none'"
10+ :tabindex =" !disabled ? 0 : 'none' "
1111
1212 @focusout = " deactivate()"
1313 @keyup.enter =" setActive()"
3434 <p
3535 v-for = " option in filteredOptions"
3636 :key = " option.value"
37- :class =" {'input-select-option-list-item_active': modelValue === option.value}"
37+ :class =" {'input-select-option-list-item_active': isActiveItem( option.value) }"
3838 class =" input-select-option-list-item"
3939 :title = " option.value"
4040
41- @click = " onInput (option.value), setActive(false )"
41+ @click = " handleSelect (option.value)"
4242 >{{getLabelFromOptionRow(option)}}</p >
4343 </div >
4444
@@ -59,6 +59,7 @@ import getLabelFromOptionRow from "../../../utils/get-label-from-option-row";
5959import FieldWrap from " ../field-wrap.vue" ;
6060import debounce from " ../../../utils/debounce" ;
6161import store from " ../../../config/store" ;
62+ import toggleValueFromArray from " ../../../utils/toggle-value-from-array" ;
6263
6364const props = defineProps <{
6465 label? : string ,
@@ -67,7 +68,8 @@ const props = defineProps<{
6768 options: OptionRow [],
6869 placeholder? : string ,
6970 errors: string [],
70- hiddenValues? : OptionRow [' value' ][]
71+ hiddenValues? : OptionRow [' value' ][],
72+ multiple? : boolean
7173}>()
7274const emit = defineEmits <{
7375 (e : ' update:modelValue' , v : any ): void
@@ -87,16 +89,23 @@ function setActive(v = !isActive.value) {
8789 if (! v ) filter .value = ' ' ;
8890 if (v ) nextTick (scrollToActiveItem .bind (null ,' auto' ))
8991}
90- function onInput(v : any ) {
91- if (props .disabled ) return ;
92- emit (' update:modelValue' , v )
93- }
92+
9493/**
95- * @description Метка отображаемая в поле.
94+ * @description Метка отображаемая в поле. В случае с одиночной выборкой отображается либо текущий элемент, либо placeholder.
95+ * В случае множественной выборки (multiple) - отображается первый выбранный элемент. Если элементов больше одного,
96+ * то отображается ещё + N, где N - количество выбранных элементов - 1
9697 * */
9798const inputTitle = computed (() => {
98- const selected = props .options .find (x => x .value === props .modelValue );
99- if (selected ) return getLabelFromOptionRow (selected );
99+
100+ const value = props .multiple ? props .modelValue ?.[0 ] : props .modelValue ;
101+
102+ const selected = props .options .find (x => x .value === value );
103+ if (selected ) {
104+ const resultLabel = getLabelFromOptionRow (selected );
105+ if (! props .multiple ) return resultLabel ;
106+
107+ return resultLabel + (props .modelValue .length > 1 ? ` + ${props .modelValue .length - 1 } ` : ' ' )
108+ }
100109
101110 return props .disabled ? ' ' : props .placeholder || ' ' ;
102111})
@@ -145,6 +154,27 @@ const filteredOptions = computed(() => {
145154 )
146155})
147156
157+ /**
158+ * @description Wrapper over data input.
159+ */
160+ function handleSelect(value : any ) {
161+ onInput (value );
162+ if (! props .multiple ) setActive (false )
163+ }
164+ function onInput(value : any ) {
165+ if (props .disabled ) return ;
166+
167+ const resultValue = props .multiple ? toggleValueFromArray (Array .isArray (props .modelValue ) ? props .modelValue : [], value ) : value
168+ emit (' update:modelValue' , resultValue )
169+ }
170+
171+ /**
172+ * @description Является ли данный элемент активным(modelValue) содержит значение
173+ */
174+ function isActiveItem(value : any ) {
175+ return props .multiple ? (Array .isArray (props .modelValue ) ? props .modelValue : []).includes (value ) : props .modelValue === value
176+ }
177+
148178 </script >
149179
150180<style scoped>
@@ -204,6 +234,7 @@ const filteredOptions = computed(() => {
204234.input-select-option-list-item_active {
205235 background-color : #f4f4f4 ;
206236 border-radius : 3px ;
237+ color : var (--vf-input-active );
207238}
208239.input-select-option-list {
209240 overflow : auto ;
0 commit comments