Skip to content

Commit

Permalink
fix(components): [select-v2] empty value should be undefined (#10189)
Browse files Browse the repository at this point in the history
  • Loading branch information
holazz committed Oct 22, 2022
1 parent d3a32cd commit 99fe8b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/components/select-v2/__tests__/select.test.ts
Expand Up @@ -473,9 +473,9 @@ describe('Select', () => {
vm.value = vm.options[1].value
await nextTick()
await clickClearButton(wrapper)
expect(vm.value).toBe('')
expect(vm.value).toBeUndefined()
const placeholder = wrapper.find(`.${PLACEHOLDER_CLASS_NAME}`)
expect(placeholder.text()).toBe('')
expect(placeholder.text()).toBe(DEFAULT_PLACEHOLDER)
})

describe('multiple', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/components/select-v2/src/useSelect.ts
Expand Up @@ -57,7 +57,7 @@ const useSelect = (props: ExtractPropTypes<typeof SelectProps>, emit) => {
selectWidth: 200,
initialInputHeight: 0,
previousQuery: null,
previousValue: '',
previousValue: undefined,
query: '',
selectedLabel: '',
softFocus: false,
Expand Down Expand Up @@ -324,7 +324,7 @@ const useSelect = (props: ExtractPropTypes<typeof SelectProps>, emit) => {
const update = (val: any) => {
emit(UPDATE_MODEL_EVENT, val)
emitChange(val)
states.previousValue = val.toString()
states.previousValue = val?.toString()
}

const getValueIndex = (arr = [], value: unknown) => {
Expand Down Expand Up @@ -512,7 +512,7 @@ const useSelect = (props: ExtractPropTypes<typeof SelectProps>, emit) => {
if (isArray(props.modelValue)) {
emptyValue = []
} else {
emptyValue = ''
emptyValue = undefined
}

states.softFocus = true
Expand Down Expand Up @@ -666,7 +666,7 @@ const useSelect = (props: ExtractPropTypes<typeof SelectProps>, emit) => {
})
} else {
states.cachedOptions = []
states.previousValue = ''
states.previousValue = undefined
}
} else {
if (hasModelValue.value) {
Expand All @@ -683,7 +683,7 @@ const useSelect = (props: ExtractPropTypes<typeof SelectProps>, emit) => {
}
} else {
states.selectedLabel = ''
states.previousValue = ''
states.previousValue = undefined
}
}
clearAllNewOption()
Expand Down

0 comments on commit 99fe8b2

Please sign in to comment.