Skip to content

Commit

Permalink
fix(inputs): reset value to null instead of undefined (#12373)
Browse files Browse the repository at this point in the history
closes #7429
  • Loading branch information
KaelWD committed Nov 3, 2020
1 parent 5695513 commit 8e5554d
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 29 deletions.
13 changes: 6 additions & 7 deletions packages/vuetify/src/components/VAutocomplete/VAutocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ export default VSelect.extend({
},
noFilter: Boolean,
searchInput: {
type: String as PropType<string | undefined>,
default: undefined,
type: String as PropType<string | null>,
},
},

Expand Down Expand Up @@ -96,10 +95,10 @@ export default VSelect.extend({
})
},
internalSearch: {
get (): string | undefined {
get (): string | null {
return this.lazySearch
},
set (val: any) {
set (val: any) { // TODO: this should be `string | null` but it breaks lots of other types
this.lazySearch = val

this.$emit('update:search-input', val)
Expand Down Expand Up @@ -177,7 +176,7 @@ export default VSelect.extend({
isMenuActive (val) {
if (val || !this.hasSlot) return

this.lazySearch = undefined
this.lazySearch = null
},
items (val, oldVal) {
// If we are focused, the menu
Expand Down Expand Up @@ -285,15 +284,15 @@ export default VSelect.extend({
const nextItem = this.selectedItems[nextIndex]

if (!nextItem) {
this.setValue(this.multiple ? [] : undefined)
this.setValue(this.multiple ? [] : null)
} else {
this.selectItem(curItem)
}

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 @@ -401,7 +401,7 @@ describe('VAutocomplete.ts', () => {
wrapper.setData({ isMenuActive: false })
await wrapper.vm.$nextTick()

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

it('should select input text on focus', async () => {
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
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('VAutocomplete.ts', () => {
input.trigger('keydown.backspace')
input.trigger('keydown.backspace')

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

wrapper.setProps({
multiple: true,
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 @@ -290,7 +290,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 @@ -274,8 +274,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 @@ -296,7 +296,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 @@ -76,18 +76,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 8e5554d

Please sign in to comment.