1818 @focus =" handleFocus"
1919 @visible-change =" handleVisibleChange"
2020 @clear =" handleClear"
21+ @change =" handleChange"
2122 :filterable =" filterable"
2223 >
2324 <slot name =" prefix" slot =" prefix" ></slot >
2829</template >
2930
3031<script lang="ts">
31- import { Component , Mixins , ModelSync , Prop , Watch , Ref , Inject } from ' vue-property-decorator'
32+ import { Component , Mixins , Prop , Watch , Ref , Inject } from ' vue-property-decorator'
3233import ElSelect from ' element-ui/lib/select'
3334import { ElForm } from ' element-ui/types/form'
3435import { ElFormItem } from ' element-ui/types/form-item'
@@ -39,10 +40,18 @@ import DesignSystemInject from '../../DesignSystem/DesignSystemInject'
3940import { Autocomplete } from ' ../../Input/consts'
4041import { InputTypes } from ' ../consts'
4142
43+ type SingleSelectValue = boolean | string | number ;
44+ type MultipleSelectValue = Array <string | number >;
45+ type SelectValue = SingleSelectValue | MultipleSelectValue ;
46+
4247@Component ({
4348 components: { ElSelect }
4449})
4550export default class SSelect extends Mixins (SizeMixin , BorderRadiusMixin , DesignSystemInject ) {
51+ /**
52+ * Selected value. Can be used with `v-model`
53+ */
54+ @Prop ({ type: [Boolean , String , Number , Array ] }) readonly value! : SelectValue
4655 /**
4756 * Input type of the select component. Available values: `"input"`, `"select"`.
4857 *
@@ -121,19 +130,24 @@ export default class SSelect extends Mixins(SizeMixin, BorderRadiusMixin, Design
121130 * `false` by default
122131 */
123132 @Prop ({ type: Boolean , default: false }) readonly filterable! : boolean
124- /**
125- * Selected value. Can be used with `v-model`
126- */
127- @ModelSync (' value' , ' input' )
128- readonly model! : any
133+
134+ get model (): SelectValue {
135+ return this .value
136+ }
137+
138+ set model (value : SelectValue ) {
139+ if (JSON .stringify (value ) !== JSON .stringify (this .value )) {
140+ this .$emit (' input' , value )
141+ }
142+ }
129143
130144 @Ref (' select' ) select! : any
131145
132146 @Inject ({ default: ' ' , from: ' elForm' }) elForm! : ElForm
133147 @Inject ({ default: ' ' , from: ' elFormItem' }) elFormItem! : ElFormItem
134148
135149 @Watch (' model' )
136- private handleValueChange (value : any ): void {
150+ private handleValueChange (): void {
137151 this .updateInputValue ()
138152 }
139153
@@ -148,7 +162,7 @@ export default class SSelect extends Mixins(SizeMixin, BorderRadiusMixin, Design
148162 tags .remove ()
149163 }
150164 const input = this .select .$el .getElementsByClassName (' el-input__inner' )[0 ] as HTMLInputElement
151- input .value = this .model && this .model .length ? ` ${this .multipleTextPrefix || this .placeholder } (${this .model .length }) ` : ' '
165+ input .value = Array . isArray ( this .model ) && ( this .model as MultipleSelectValue ) .length ? ` ${this .multipleTextPrefix || this .placeholder } (${this .model .length }) ` : ' '
152166 }
153167
154168 mounted (): void {
@@ -193,7 +207,7 @@ export default class SSelect extends Mixins(SizeMixin, BorderRadiusMixin, Design
193207 if (this .disabled ) {
194208 cssClasses .push (' s-disabled' )
195209 }
196- if ((! this .multiple && this .model ) || (this .multiple && this .model .length !== 0 )) {
210+ if ((! this .multiple && this .model ) || (this .multiple && Array . isArray ( this . model ) && this .model .length !== 0 )) {
197211 cssClasses .push (' s-has-value' )
198212 }
199213 return cssClasses
@@ -233,6 +247,10 @@ export default class SSelect extends Mixins(SizeMixin, BorderRadiusMixin, Design
233247 this .$emit (' clear' )
234248 }
235249
250+ handleChange (value : SelectValue ): void {
251+ this .$emit (' change' , value )
252+ }
253+
236254 public focus (): void {
237255 this .select .focus ()
238256 }
0 commit comments