Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(VSelect): change onMouseUp to handle menu toggle on mouse events #9476

Merged
merged 1 commit into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 deletions packages/vuetify/src/components/VSelect/VSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface options extends InstanceType<typeof baseMixins> {
label: HTMLElement
input: HTMLInputElement
'prepend-inner': HTMLElement
'append-inner': HTMLElement
prefix: HTMLElement
suffix: HTMLElement
}
Expand Down Expand Up @@ -550,10 +551,12 @@ export default baseMixins.extend<options>().extend({
}
this.selectedIndex = -1
},
onClick () {
onClick (e: MouseEvent) {
if (this.isDisabled) return

this.isMenuActive = true
if (!this.isAppendInner(e.target)) {
this.isMenuActive = true
}

if (!this.isFocused) {
this.isFocused = true
Expand Down Expand Up @@ -654,16 +657,10 @@ export default baseMixins.extend<options>().extend({
},
onMouseUp (e: MouseEvent) {
if (this.hasMouseDown && e.which !== 3) {
const appendInner = this.$refs['append-inner']

// If append inner is present
// and the target is itself
// or inside, toggle menu
if (this.isMenuActive &&
appendInner &&
(appendInner === e.target ||
(appendInner as { [key: string]: any }).contains(e.target))
) {
if (this.isAppendInner(e.target)) {
this.$nextTick(() => (this.isMenuActive = !this.isMenuActive))
// If user is clicking in the container
// and field is enclosed, activate it
Expand Down Expand Up @@ -803,5 +800,12 @@ export default baseMixins.extend<options>().extend({
this.internalValue = value
value !== oldValue && this.$emit('change', value)
},
isAppendInner (target: any) {
// return true if append inner is present
// and the target is itself or inside
const appendInner = this.$refs['append-inner']

return appendInner && (appendInner === target || appendInner.contains(target))
},
},
})
34 changes: 34 additions & 0 deletions packages/vuetify/src/components/VSelect/__tests__/VSelect4.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,38 @@ describe('VSelect.ts', () => {
await wrapper.vm.$nextTick()
expect(listIndexUpdate).toHaveBeenCalledWith(1)
})

it('should close menu when append icon is clicked', async () => {
const wrapper = mountFunction({
propsData: {
items: ['foo', 'bar'],
},
})

const append = wrapper.find('.v-input__append-inner')
const slot = wrapper.find('.v-input__slot')
slot.trigger('click')
expect(wrapper.vm.isMenuActive).toBe(true)
append.trigger('mousedown')
append.trigger('mouseup')
append.trigger('click')
await wrapper.vm.$nextTick()
expect(wrapper.vm.isMenuActive).toBe(false)
})

it('should open menu when append icon is clicked', async () => {
const wrapper = mountFunction({
propsData: {
items: ['foo', 'bar'],
},
})

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

append.trigger('mousedown')
append.trigger('mouseup')
append.trigger('click')
await wrapper.vm.$nextTick()
expect(wrapper.vm.isMenuActive).toBe(true)
})
})