Skip to content

Commit 243efcc

Browse files
FBuervenichKaelWD
andauthored
feat(VDataTable): forward arbitrary row events (#15617)
closes #13332 Co-authored-by: Kael <kaelwd@gmail.com>
1 parent 018525e commit 243efcc

6 files changed

Lines changed: 20 additions & 19 deletions

File tree

packages/api-generator/src/locale/en/v-data-table.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@
6363
},
6464
"events": {
6565
"click:row": "Emits when a table row is clicked. This event provides 3 arguments: the first is the item data that was clicked, the second is the other related data provided by the `item` slot, and the third is the native click event. **NOTE:** will not emit when table rows are defined through a slot such as `item` or `body`.",
66-
"contextmenu:row": "Emits when a table row is right-clicked. The item for the row is included. **NOTE:** will not emit when table rows are defined through a slot such as `item` or `body`.",
67-
"dblclick:row": "Emits when a table row is double-clicked. The item for the row is included. **NOTE:** will not emit when table rows are defined through a slot such as `item` or `body`.",
66+
"<event>:row": "Pass through any native event listener to the table row elements. The first argument is the event object and the second is related data provided to the item slot. **NOTE:** will not emit when table rows are defined through a slot such as `item` or `body`.",
6867
"current-items": "Emits the items provided via the **items** prop, every time the internal **computedItems** is changed.",
6968
"page-count": "Emits when the **pageCount** property of the **pagination** prop is updated",
7069
"pagination": "Emits when something changed to the `pagination` which can be provided via the `pagination` prop",

packages/api-generator/src/maps/v-data-table.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,9 @@ const DataTableEvents = [
3434
value: `any, ${dataString}, MouseEvent`,
3535
},
3636
{
37-
name: 'contextmenu:row',
37+
name: '<event>:row',
3838
source: 'v-data-table',
39-
value: `MouseEvent, ${dataString}`,
40-
},
41-
{
42-
name: 'dblclick:row',
43-
source: 'v-data-table',
44-
value: `MouseEvent, ${dataString}`,
39+
value: `${dataString}, Event`,
4540
},
4641
].concat(DataIteratorEvents)
4742

packages/vuetify/src/components/VCalendar/mixins/calendar-base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import mixins from '../../../util/mixins'
44
import Colorable from '../../../mixins/colorable'
55
import Localable from '../../../mixins/localable'
6-
import Mouse from './mouse'
6+
import Mouse from '../../../mixins/mouse'
77
import Themeable from '../../../mixins/themeable'
88
import Times from './times'
99

packages/vuetify/src/components/VDataTable/VDataTable.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import MobileRow from './MobileRow'
3131

3232
// Mixins
3333
import Loadable from '../../mixins/loadable'
34+
import Mouse from '../../mixins/mouse'
3435

3536
// Directives
3637
import ripple from '../../directives/ripple'
@@ -74,6 +75,7 @@ function searchTableItems (
7475
export default mixins(
7576
VDataIterator,
7677
Loadable,
78+
Mouse,
7779
).extend({
7880
name: 'v-data-table',
7981

@@ -241,11 +243,10 @@ export default mixins(
241243
},
242244
},
243245
on: {
244-
// TODO: for click, the first argument should be the event, and the second argument should be data,
246+
...this.getDefaultMouseEventHandlers(':row', () => data, true),
247+
// TODO: the first argument should be the event, and the second argument should be data,
245248
// but this is a breaking change so it's for v3
246249
click: (event: MouseEvent) => this.$emit('click:row', item, data, event),
247-
contextmenu: (event: MouseEvent) => this.$emit('contextmenu:row', event, data),
248-
dblclick: (event: MouseEvent) => this.$emit('dblclick:row', event, data),
249250
},
250251
}
251252
},

packages/vuetify/src/components/VCalendar/mixins/__tests__/mouse.spec.ts renamed to packages/vuetify/src/mixins/mouse/__tests__/mouse.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import Mouse from '../mouse'
1+
import Mouse from '../index'
22

33
import {
44
mount,
55
Wrapper,
66
MountOptions,
77
} from '@vue/test-utils'
8-
import { ExtractVue } from '../../../../util/mixins'
8+
import { ExtractVue } from '../../../util/mixins'
99

1010
const Mock = Mouse.extend({
1111
render: h => h('div'),

packages/vuetify/src/components/VCalendar/mixins/mouse.ts renamed to packages/vuetify/src/mixins/mouse/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default Vue.extend({
2323
name: 'mouse',
2424

2525
methods: {
26-
getDefaultMouseEventHandlers (suffix: string, getEvent: MouseHandler): MouseEventsMap {
26+
getDefaultMouseEventHandlers (suffix: string, getData: MouseHandler, eventFirst = false): MouseEventsMap {
2727
const listeners = Object.keys(this.$listeners)
2828
.filter(key => key.endsWith(suffix))
2929
.reduce((acc, key) => {
@@ -34,9 +34,9 @@ export default Vue.extend({
3434
return this.getMouseEventHandlers({
3535
...listeners,
3636
['contextmenu' + suffix]: { event: 'contextmenu', prevent: true, result: false },
37-
}, getEvent)
37+
}, getData, eventFirst)
3838
},
39-
getMouseEventHandlers (events: MouseEvents, getEvent: MouseHandler): MouseEventsMap {
39+
getMouseEventHandlers (events: MouseEvents, getData: MouseHandler, eventFirst = false): MouseEventsMap {
4040
const on: MouseEventsMap = {}
4141

4242
for (const event in events) {
@@ -85,7 +85,13 @@ export default Vue.extend({
8585
}
8686
}
8787

88-
this.$emit(event, getEvent(e), e)
88+
// TODO: VCalendar emits the calendar event as the first argument,
89+
// but it really should be the native event instead so modifiers can be used
90+
if (eventFirst) {
91+
this.$emit(event, e, getData(e))
92+
} else {
93+
this.$emit(event, getData(e), e)
94+
}
8995
}
9096

9197
return eventOptions.result

0 commit comments

Comments
 (0)