Skip to content

Commit 1040ccd

Browse files
committed
fix(inputs): emit icon click events correctly
calling the listener after emit doesn't actually work, tests will need to watch twice for now fixes #4647 see #4545
1 parent 2dec42a commit 1040ccd

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/components/VInput/VInput.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,7 @@ export default {
160160
e.stopPropagation()
161161

162162
this.$emit(eventName, e)
163-
if (this.$listeners[eventName]) {
164-
this.$listeners[eventName](e)
165-
} else if (cb) {
166-
cb(e)
167-
}
163+
cb && cb(e)
168164
},
169165
// Container has mouseup event that will
170166
// trigger menu open if enclosed

test/unit/components/VInput/VInput.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ test('VInput.js', ({ mount }) => {
8888

8989
const click = jest.fn()
9090
wrapper.vm.$on('click', click)
91+
wrapper.vm.$on('click:prepend', cb)
92+
wrapper.vm.$on('click:append', cb)
9193

9294
const prepend = wrapper.find('.v-icon')[0]
9395
const append = wrapper.find('.v-icon')[1]

test/unit/components/VTextField/VTextField.spec.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,22 +170,24 @@ test('VTextField.js', ({ mount }) => {
170170
})
171171

172172
it('should not clear input if not clearable and has appended icon (with callback)', async () => {
173-
const appendIconCb = jest.fn()
173+
const click = jest.fn()
174174
const wrapper = mount(VTextField, {
175175
propsData: {
176176
value: 'foo',
177177
appendIcon: 'block',
178178
},
179179
listeners: {
180-
'click:append': appendIconCb
180+
'click:append': click
181181
}
182182
})
183183

184+
wrapper.vm.$on('click:append', click)
185+
184186
const icon = wrapper.find('.v-input__icon--append .v-icon')[0]
185187
icon.trigger('click')
186188
await wrapper.vm.$nextTick()
187189
expect(wrapper.vm.internalValue).toBe('foo')
188-
expect(appendIconCb.mock.calls).toHaveLength(1)
190+
expect(click.mock.calls).toHaveLength(1)
189191
})
190192

191193
it('should not clear input if not clearable and has appended icon (without callback)', async () => {
@@ -574,20 +576,22 @@ test('VTextField.js', ({ mount }) => {
574576
})
575577

576578
it('should use a custom clear callback', async () => {
577-
const clearIconCb = jest.fn()
579+
const clear = jest.fn()
578580
const wrapper = mount(VTextField, {
579581
propsData: {
580582
clearable: true,
581583
value: 'foo'
582584
},
583585
listeners: {
584-
'click:clear': clearIconCb
586+
'click:clear': clear
585587
}
586588
})
587589

590+
wrapper.vm.$on('click:clear', clear)
591+
588592
wrapper.first('.v-input__icon--clear .v-icon').trigger('click')
589593

590-
expect(clearIconCb).toBeCalled()
594+
expect(clear).toBeCalled()
591595
})
592596

593597
it('should not generate label', () => {

0 commit comments

Comments
 (0)