@@ -72,7 +72,7 @@ const dropdownOptions = computed<DropdownSectionFilter[]>(() => [{
7272 search: props .noSearch === undefined ? true : ! props .noSearch ,
7373 selected: model .value ,
7474 options: props .options ,
75- onClick: handleSelect
75+ onClick: onSelect
7676}])
7777
7878const selected = computed (() => {
@@ -97,35 +97,28 @@ const removable = computed(() => {
9797 return !! props .nullable
9898})
9999
100- async function handleOpen () {
100+ async function onOpen () {
101101 if (! props .disabled ) {
102102 updatePosition ()
103103 open ()
104104 }
105105}
106106
107- function handleSelect (value : OptionValue ) {
107+ function onSelect (value : OptionValue ) {
108108 props .validation ?.$touch ()
109109
110- Array .isArray (model .value ) ? handleArray (value ) : handlePrimitive (value )
111- }
112-
113- function handlePrimitive(value : OptionValue ) {
114- if (value !== model .value ) {
115- model .value = value
116- } else if (props .nullable ) {
117- model .value = null
118- }
119- }
120-
121- function handleArray(value : OptionValue ) {
122- const difference = xor (model .value as ArrayValue , [value ])
123-
124- if (! props .nullable && difference .length === 0 ) {
125- return
110+ if (Array .isArray (model .value )) {
111+ const toggled = xor (model .value , [value ])
112+ if (toggled .length !== 0 || props .nullable ) {
113+ model .value = toggled
114+ }
115+ } else {
116+ if (value !== model .value ) {
117+ model .value = value
118+ } else if (props .nullable ) {
119+ model .value = null
120+ }
126121 }
127-
128- model .value = difference
129122}
130123 </script >
131124
@@ -149,10 +142,10 @@ function handleArray(value: OptionValue) {
149142 class =" box"
150143 role =" button"
151144 tabindex =" 0"
152- @click =" handleOpen "
145+ @click =" onOpen "
153146 @keydown.down.prevent
154- @keyup.enter =" handleOpen "
155- @keyup.down =" handleOpen "
147+ @keyup.enter =" onOpen "
148+ @keyup.down =" onOpen "
156149 >
157150 <div class =" box-content" >
158151 <SInputDropdownItem
@@ -161,7 +154,7 @@ function handleArray(value: OptionValue) {
161154 :size =" size ?? 'small'"
162155 :removable
163156 :disabled =" disabled ?? false"
164- @remove =" handleSelect "
157+ @remove =" onSelect "
165158 />
166159
167160 <div v-else class =" box-placeholder" >{{ placeholder ?? t.ph }}</div >
0 commit comments