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

feat(VDataTable): forward arbitrary row events #15617

Merged
merged 7 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 8 additions & 0 deletions packages/api-generator/src/locale/en/v-data-table.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
"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`.",
"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`.",
"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`.",
"mousedown:row": "The mousedown event on one of the table's rows. This event provides 2 arguments: the first is the related data provided by the item slot and the second is the item data that was clicked. **NOTE:** will not emit when table rows are defined through a slot such as item or body.",
"mouseenter:row": "The mouseenter event on one of the table's rows. This event provides 2 arguments: the first is the related data provided by the item slot and the second is the item data that was clicked. **NOTE:** will not emit when table rows are defined through a slot such as item or body.",
"mouseleave:row": "The mouseleave event on one of the table's rows. This event provides 2 arguments: the first is the related data provided by the item slot and the second is the item data that was clicked. **NOTE:** will not emit when table rows are defined through a slot such as item or body.",
"mousemove:row": "The mousemove event on one of the table's rows. This event provides 2 arguments: the first is the related data provided by the item slot and the second is the item data that was clicked. **NOTE:** will not emit when table rows are defined through a slot such as item or body.",
"mouseup:row": "The mouseup event on one of the table's rows. This event provides 2 arguments: the first is the related data provided by the item slot and the second is the item data that was clicked. **NOTE:** will not emit when table rows are defined through a slot such as item or body.",
"touchend:row": "The touchend event on one of the table's rows. This event provides 2 arguments: the first is the related data provided by the item slot and the second is the item data that was clicked. **NOTE:** will not emit when table rows are defined through a slot such as item or body.",
"touchmove:row": "The touchmove event on one of the table's rows. This event provides 2 arguments: the first is the related data provided by the item slot and the second is the item data that was clicked. **NOTE:** will not emit when table rows are defined through a slot such as item or body.",
"touchstart:row": "The touchstart event on one of the table's rows. This event provides 2 arguments: the first is the related data provided by the item slot and the second is the item data that was clicked. **NOTE:** will not emit when table rows are defined through a slot such as item or body.",
"current-items": "Emits the items provided via the **items** prop, every time the internal **computedItems** is changed.",
"page-count": "Emits when the **pageCount** property of the **pagination** prop is updated",
"pagination": "Emits when something changed to the `pagination` which can be provided via the `pagination` prop",
Expand Down
40 changes: 40 additions & 0 deletions packages/api-generator/src/maps/v-data-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,46 @@ const DataTableEvents = [
source: 'v-data-table',
value: `MouseEvent, ${dataString}`,
},
{
name: 'mousedown:row',
source: 'v-data-table',
value: `${dataString}, MouseEvent`,
},
{
name: 'mousemove:row',
source: 'v-data-table',
value: `${dataString}, MouseEvent`,
},
{
name: 'mouseup:row',
source: 'v-data-table',
value: `${dataString}, MouseEvent`,
},
{
name: 'mouseenter:row',
source: 'v-data-table',
value: `${dataString}, MouseEvent`,
},
{
name: 'mouseleave:row',
source: 'v-data-table',
value: `${dataString}, MouseEvent`,
},
{
name: 'touchstart:row',
source: 'v-data-table',
value: `${dataString}, TouchEvent`,
},
{
name: 'touchmove:row',
source: 'v-data-table',
value: `${dataString}, TouchEvent`,
},
{
name: 'touchend:row',
source: 'v-data-table',
value: `${dataString}, TouchEvent`,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is really necessary considering it takes any dom event now.

].concat(DataIteratorEvents)

const DataTableHeaderScopedProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import mixins from '../../../util/mixins'
import Colorable from '../../../mixins/colorable'
import Localable from '../../../mixins/localable'
import Mouse from './mouse'
import Mouse from '../../../mixins/mouse'
import Themeable from '../../../mixins/themeable'
import Times from './times'

Expand Down
6 changes: 5 additions & 1 deletion packages/vuetify/src/components/VDataTable/VDataTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import MobileRow from './MobileRow'

// Mixins
import Loadable from '../../mixins/loadable'
import Mouse from '../../mixins/mouse'

// Directives
import ripple from '../../directives/ripple'
Expand Down Expand Up @@ -74,6 +75,7 @@ function searchTableItems (
export default mixins(
VDataIterator,
Loadable,
Mouse,
).extend({
name: 'v-data-table',

Expand Down Expand Up @@ -241,7 +243,9 @@ export default mixins(
},
},
on: {
// TODO: for click, the first argument should be the event, and the second argument should be data,
...this.getDefaultMouseEventHandlers(':row', () => data),
// TODO: for click, contextmenu and dblclick, the first argument should be data,
// and the second argument should be the event,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realise calendar was like this too. This is actually backwards, the first argument has to be the event so modifiers like .prevent work.

// but this is a breaking change so it's for v3
click: (event: MouseEvent) => this.$emit('click:row', item, data, event),
contextmenu: (event: MouseEvent) => this.$emit('contextmenu:row', event, data),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Mouse from '../mouse'
import Mouse from '../index'

import {
mount,
Wrapper,
MountOptions,
} from '@vue/test-utils'
import { ExtractVue } from '../../../../util/mixins'
import { ExtractVue } from '../../../util/mixins'

const Mock = Mouse.extend({
render: h => h('div'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import Vue from 'vue'

export type MouseHandler = (e: MouseEvent | TouchEvent) => any
Expand Down