Skip to content

Commit

Permalink
fix(inputs): reset value to null instead of undefined
Browse files Browse the repository at this point in the history
fixes #7429
  • Loading branch information
KaelWD committed Oct 7, 2020
1 parent 8d06d45 commit 4a1bf59
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export default VSelect.extend({
this.selectedIndex = nextIndex
},
clearableCallback () {
this.internalSearch = undefined
this.internalSearch = null

VSelect.options.methods.clearableCallback.call(this)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe('VAutocomplete.ts', () => {

icon.trigger('click')

expect(wrapper.vm.internalSearch).toBeUndefined()
expect(wrapper.vm.internalSearch).toBeNull()
})

it('should propagate content class', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vuetify/src/components/VCombobox/VCombobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export default VAutocomplete.extend({

// Reset search if using slot
// to avoid a double input
if (isUsingSlot) this.internalSearch = undefined
if (isUsingSlot) this.internalSearch = null
},
updateSelf () {
this.multiple ? this.updateTags() : this.updateCombobox()
Expand Down
2 changes: 1 addition & 1 deletion packages/vuetify/src/components/VFileInput/VFileInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default VTextField.extend({

methods: {
clearableCallback () {
this.internalValue = this.isMultiple ? [] : undefined
this.internalValue = this.isMultiple ? [] : null
this.$refs.input.value = ''
},
genChips () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('VFileInput.ts', () => {
})

wrapper.vm.clearableCallback()
expect(wrapper.vm.internalValue).toBeUndefined()
expect(wrapper.vm.internalValue).toBeNull()

const wrapper2 = mountFunction({
attrs: { multiple: '' },
Expand Down
2 changes: 1 addition & 1 deletion packages/vuetify/src/components/VSelect/VSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export default baseMixins.extend<options>().extend({
this.isMenuActive = true
},
clearableCallback () {
this.setValue(this.multiple ? [] : undefined)
this.setValue(this.multiple ? [] : null)
this.setMenuIndex(-1)
this.$nextTick(() => this.$refs.input && this.$refs.input.focus())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ describe('VSelect.ts', () => {

await wrapper.vm.$nextTick()

expect(wrapper.vm.internalValue).toBeUndefined()
expect(input).toHaveBeenCalledWith(undefined)
expect(wrapper.vm.internalValue).toBeNull()
expect(input).toHaveBeenCalledWith(null)
})

it('should be clearable with prop, dirty and single select', async () => {
Expand All @@ -292,7 +292,7 @@ describe('VSelect.ts', () => {

clear.trigger('click')
await wrapper.vm.$nextTick()
expect(wrapper.vm.internalValue).toBeUndefined()
expect(wrapper.vm.internalValue).toBeNull()
expect(wrapper.vm.isMenuActive).toBe(false)
})

Expand Down
10 changes: 0 additions & 10 deletions packages/vuetify/src/components/VSelect/__tests__/VSelect4.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,8 @@ describe('VSelect.ts', () => {
},
})

const icon = wrapper.find('.v-input__append-inner .v-icon')

expect(wrapper.vm.selectedItems).toHaveLength(1)
expect(wrapper.vm.isDirty).toBe(true)

icon.trigger('click')

await wrapper.vm.$nextTick()

expect(wrapper.vm.selectedItems).toHaveLength(0)
expect(wrapper.vm.isDirty).toBe(false)
expect(wrapper.vm.internalValue).toBeUndefined()
})

it('should only calls change once when clearing', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ describe('validatable.ts', () => {
wrapper.vm.reset()

expect(wrapper.vm.isResetting).toBe(true)
expect(wrapper.vm.internalValue).toBeUndefined()
expect(wrapper.vm.internalValue).toBeNull()

wrapper.setProps({ value: ['foobar'] })

Expand Down
2 changes: 1 addition & 1 deletion packages/vuetify/src/mixins/validatable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export default baseMixins.extend({
this.isResetting = true
this.internalValue = Array.isArray(this.internalValue)
? []
: undefined
: null
},
/** @public */
resetValidation () {
Expand Down

0 comments on commit 4a1bf59

Please sign in to comment.