Skip to content

feat(defineShortcuts): add cursorTarget to scope the shortcut to specific element - #4169

Closed
J-Michalek wants to merge 2 commits into
nuxt:v3from
J-Michalek:feat/define-shortcuts-element
Closed

J-Michalek wants to merge 2 commits into
nuxt:v3from
J-Michalek:feat/define-shortcuts-element

Conversation

@J-Michalek

Copy link
Copy Markdown
Collaborator

🔗 Linked issue

Resolves: #4165

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

I have added the option to specify which element can trigger the keyboard shortcut. This is useful when the user doesn't want to use a global shortcut but instead scope it to the cursorTarget element.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@pkg-pr-new

pkg-pr-new Bot commented May 16, 2025

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxt/ui@4169

commit: c06353b

@benjamincanac benjamincanac changed the title feat(define-shortcuts): add cursorTarget to scope the shortcut to specific element feat(defineShortcuts): add cursorTarget to scope the shortcut to specific element May 30, 2025
@benjamincanac
benjamincanac self-requested a review as a code owner June 6, 2025 10:28
@benjamincanac

Copy link
Copy Markdown
Member

@J-Michalek Closing this as it brings too much complexity for something you can already achieve easily, here is an example:

<script setup lang="ts">
import { useElementHover } from '@vueuse/core'

const cursorTarget = ref<HTMLElement | null>(null)
const isTargetHovered = useElementHover(cursorTarget)
const open = ref(false)

const shortcuts = computed(() => ({
  i: isTargetHovered.value
    ? {
        handler: () => {
          open.value = !open.value
        }
      }
    : undefined
}))

defineShortcuts(shortcuts)
</script>

<template>
  <UPopover v-model:open="open">
    <Placeholder ref="cursorTarget" class="size-48" />

    <template #content>
      <Placeholder class="size-48 m-4 inline-flex" />
    </template>
  </UPopover>
</template>

@benjamincanac benjamincanac added the v3 #1289 label Aug 27, 2025
@J-Michalek
J-Michalek deleted the feat/define-shortcuts-element branch August 17, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v3 #1289

Projects

None yet

Development

Successfully merging this pull request may close these issues.

defineShortcuts limit shortcut to a specific element

2 participants