Skip to content

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

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

Closed
wants to merge 2 commits into from

Conversation

J-Michalek
Copy link
Contributor

πŸ”— 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.

Copy link

pkg-pr-new bot commented May 16, 2025

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
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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

defineShortcuts limit shortcut to a specific element
2 participants