Skip to content

Commit

Permalink
fix(NcListItem): fix native open link in a new tab
Browse files Browse the repository at this point in the history
Signed-off-by: Grigorii Shartsev <[email protected]>
  • Loading branch information
ShGKme committed Apr 4, 2023
1 parent 2aade31 commit a432ff5
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/components/NcListItem/NcListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,23 @@ export default {
},
methods: {
// forward click event
/**
* Handle link click
*
* @param {PointerEvent} event - Native click event
* @param {Function} [navigate] - VueRouter link's navigate if any
* @param {string} [routerLinkHref] - VueRouter link's href
*/
onClick(event, navigate, routerLinkHref) {
// Navigate is only defined if it is a router-link
navigate?.(event)
// Always forward native event
this.$emit('click', event)
// Prevent default link behaviour if it's a router-link
// Do not navigate with control keys - it is opening in a new tab
if (event.metaKey || event.altKey || event.ctrlKey || event.shiftKey) {
return
}
// Prevent default link behaviour if it's a router-link and navigate manually
if (routerLinkHref) {
navigate?.(event)
event.preventDefault()
}
},
Expand Down

0 comments on commit a432ff5

Please sign in to comment.