-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Table): add contextmenu handling to table rows (#2283)
- Loading branch information
Showing
3 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
docs/components/content/examples/TableExampleContextmenu.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<script setup lang="ts"> | ||
const people = [{ | ||
id: 1, | ||
name: 'Lindsay Walton', | ||
title: 'Front-end Developer', | ||
email: 'lindsay.walton@example.com', | ||
role: 'Member' | ||
}, { | ||
id: 2, | ||
name: 'Courtney Henry', | ||
title: 'Designer', | ||
email: 'courtney.henry@example.com', | ||
role: 'Admin' | ||
}, { | ||
id: 3, | ||
name: 'Tom Cook', | ||
title: 'Director of Product', | ||
email: 'tom.cook@example.com', | ||
role: 'Member' | ||
}, { | ||
id: 4, | ||
name: 'Whitney Francis', | ||
title: 'Copywriter', | ||
email: 'whitney.francis@example.com', | ||
role: 'Admin' | ||
}, { | ||
id: 5, | ||
name: 'Leonard Krasner', | ||
title: 'Senior Designer', | ||
email: 'leonard.krasner@example.com', | ||
role: 'Owner' | ||
}] | ||
const virtualElement = ref({ getBoundingClientRect: () => ({}) }) | ||
const contextMenuRow = ref() | ||
function contextmenu(event: MouseEvent, row: any) { | ||
// Prevent the default context menu | ||
event.preventDefault() | ||
virtualElement.value.getBoundingClientRect = () => ({ | ||
width: 0, | ||
height: 0, | ||
top: event.clientY, | ||
left: event.clientX | ||
}) | ||
contextMenuRow.value = row | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<UTable :rows="people" @contextmenu.stop="contextmenu" /> | ||
|
||
<UContextMenu | ||
:virtual-element="virtualElement" | ||
:model-value="!!contextMenuRow" | ||
@update:model-value="contextMenuRow = null" | ||
> | ||
<div class="p-4"> | ||
{{ contextMenuRow.id }} - {{ contextMenuRow.name }} | ||
</div> | ||
</UContextMenu> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters