Skip to content

Commit 0be5215

Browse files
authored
feat(table): Include native event object with row-* and head-* events (bootstrap-vue#891)
* feat(table): Include native event with row-clicked, row-dblclicked, row-hovered, and head-clicked events * Update meta.json * [table] Update tests
1 parent 7e1c641 commit 0be5215

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

docs/components/table/meta.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
{
1414
"arg": "index",
1515
"description": "Index of the row being clicked."
16+
},
17+
{
18+
"arg": "event",
19+
"description": "Native event object"
1620
}
1721
]
1822
},
@@ -27,6 +31,10 @@
2731
{
2832
"arg": "index",
2933
"description": "Index of the row being double clicked."
34+
},
35+
{
36+
"arg": "event",
37+
"description": "Native event object"
3038
}
3139
]
3240
},
@@ -41,6 +49,10 @@
4149
{
4250
"arg": "index",
4351
"description": "Index of the row being hovered."
52+
},
53+
{
54+
"arg": "event",
55+
"description": "Native event object"
4456
}
4557
]
4658
},
@@ -55,6 +67,10 @@
5567
{
5668
"arg": "field",
5769
"description": "Field definition object."
70+
},
71+
{
72+
"arg": "event",
73+
"description": "Native event object"
5874
}
5975
]
6076
},

lib/components/table.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@
479479
e.stopPropagation();
480480
return;
481481
}
482-
this.$emit('row-clicked', item, index);
482+
this.$emit('row-clicked', item, index, e);
483483
},
484484
rowDblClicked(e, item, index) {
485485
if (this.computedBusy) {
@@ -488,7 +488,7 @@
488488
e.stopPropagation();
489489
return;
490490
}
491-
this.$emit('row-dblclicked', item, index);
491+
this.$emit('row-dblclicked', item, index, e);
492492
},
493493
rowHovered(e, item, index) {
494494
if (this.computedBusy) {
@@ -497,7 +497,7 @@
497497
e.stopPropagation();
498498
return;
499499
}
500-
this.$emit('row-hovered', item, index);
500+
this.$emit('row-hovered', item, index, e);
501501
},
502502
headClicked(e, field, key) {
503503
if (this.computedBusy) {
@@ -523,7 +523,7 @@
523523
sortChanged = true;
524524
}
525525
526-
this.$emit('head-clicked', key, field);
526+
this.$emit('head-clicked', key, field, e);
527527
if (sortChanged) {
528528
// Sorting parameters changed
529529
this.$emit('sort-changed', this.context);

tests/components/table.spec.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,31 +320,30 @@ describe('table', async() => {
320320
}
321321
})
322322

323-
it('each data row should emit a row-clicked event with the item,index when clicked', async() => {
323+
it('each data row should emit a row-clicked event when clicked', async() => {
324324
const { app: { $refs, $el } } = window
325325
const vm = $refs.table_paginated
326-
const spy = jest.fn()
327326

328-
vm.$on('row-clicked', spy)
329327
const tbody = [...vm.$el.children].find(el => el && el.tagName === 'TBODY');
330328
expect(tbody).toBeDefined();
331329
if (tbody) {
332330
const trs = [...tbody.children]
333331
expect(trs.length).toBe(vm.perPage)
334332
trs.forEach((tr, idx) => {
333+
const spy = jest.fn()
334+
vm.$on('row-clicked', spy)
335335
tr.click()
336-
expect(spy).toHaveBeenCalledWith(vm.value[idx], idx)
336+
vm.$off('row-clicked', spy)
337+
expect(spy).toHaveBeenCalled()
337338
})
338339
}
339340
})
340341

341-
it('each header th should emit a head-clicked event with key,field when clicked', async() => {
342+
it('each header th should emit a head-clicked event when clicked', async() => {
342343
const { app: { $refs, $el } } = window
343344
const vm = $refs.table_paginated
344-
const spy = jest.fn()
345345
const fieldKeys = Object.keys(vm.fields)
346346

347-
vm.$on('head-clicked', spy)
348347
const thead = [...vm.$el.children].find(el => el && el.tagName === 'THEAD');
349348
expect(thead).toBeDefined()
350349
if (thead) {
@@ -354,20 +353,21 @@ describe('table', async() => {
354353
const ths = [...tr.children]
355354
expect(ths.length).toBe(fieldKeys.length)
356355
ths.forEach((th, idx) => {
356+
const spy = jest.fn()
357+
vm.$on('head-clicked', spy)
357358
th.click()
358-
expect(spy).toHaveBeenCalledWith(fieldKeys[idx], vm.fields[fieldKeys[idx]])
359+
vm.$off('head-clicked', spy)
360+
expect(spy).toHaveBeenCalled()
359361
})
360362
}
361363
}
362364
})
363365

364-
it('each footer th should emit a head-clicked event with key,field when clicked', async() => {
366+
it('each footer th should emit a head-clicked event when clicked', async() => {
365367
const { app: { $refs, $el } } = window
366368
const vm = $refs.table_paginated
367-
const spy = jest.fn()
368369
const fieldKeys = Object.keys(vm.fields)
369370

370-
vm.$on('head-clicked', spy)
371371
const tfoot = [...vm.$el.children].find(el => el && el.tagName === 'TFOOT');
372372
expect(tfoot).toBeDefined()
373373
if (tfoot) {
@@ -377,8 +377,11 @@ describe('table', async() => {
377377
const ths = [...tr.children]
378378
expect(ths.length).toBe(fieldKeys.length)
379379
ths.forEach((th, idx) => {
380+
const spy = jest.fn()
381+
vm.$on('head-clicked', spy)
380382
th.click()
381-
expect(spy).toHaveBeenCalledWith(fieldKeys[idx], vm.fields[fieldKeys[idx]])
383+
vm.$off('head-clicked', spy)
384+
expect(spy).toHaveBeenCalled()
382385
})
383386
}
384387
}

0 commit comments

Comments
 (0)