Skip to content

feat(table): Support contextmenu event binding for table rows #2064

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

Merged
merged 1 commit into from
Oct 23, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/components/table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@
}
]
},
{
"event": "row-contextmenu",
"description": "Emitted when a row is right clicked.",
"args": [
{
"arg": "item",
"description": "Item data of the row being right clicked."
},
{
"arg": "index",
"description": "Index of the row being right clicked."
},
{
"arg": "event",
"description": "Native event object."
}
]
},
{
"event": "row-hovered",
"description": "Emitted when a row is hovered.",
Expand Down
10 changes: 10 additions & 0 deletions src/components/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ export default {
click: evt => {
this.rowClicked(evt, item, rowIndex)
},
contextmenu: evt => {
this.rowContextmenu(evt, item, rowIndex)
},
dblclick: evt => {
this.rowDblClicked(evt, item, rowIndex)
},
Expand Down Expand Up @@ -926,6 +929,13 @@ export default {
}
this.$emit('row-hovered', item, index, e)
},
rowContextmenu (e, item, index) {
if (this.stopIfBusy(e)) {
// If table is busy (via provider) then don't propagate
return
}
this.$emit('row-contextmenu', item, index, e)
},
headClicked (e, field) {
if (this.stopIfBusy(e)) {
// If table is busy (via provider) then don't propagate
Expand Down
19 changes: 19 additions & 0 deletions src/components/table/table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,25 @@ describe('table', async () => {
}
})

it('each data row should emit a row-contextmenu event when right clicked', async () => {
const { app: { $refs } } = window
const vm = $refs.table_paginated

const tbody = [...vm.$el.children].find(el => el && el.tagName === 'TBODY')
expect(tbody).toBeDefined()
if (tbody) {
const trs = [...tbody.children]
expect(trs.length).toBe(vm.perPage)
trs.forEach((tr, idx) => {
const spy = jest.fn()
vm.$on('row-contextmenu', spy)
tr.dispatchEvent(new MouseEvent('contextmenu', {button: 2}))
vm.$off('row-contextmenu', spy)
expect(spy).toHaveBeenCalled()
})
}
})

it('each header th should emit a head-clicked event when clicked', async () => {
const { app: { $refs } } = window
const vm = $refs.table_paginated
Expand Down