Skip to content

Add support for non-Latin keyboard layouts in defineShortcuts composable #2293

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

Open
al1maher opened this issue Oct 2, 2024 · 2 comments · May be fixed by #4251
Open

Add support for non-Latin keyboard layouts in defineShortcuts composable #2293

al1maher opened this issue Oct 2, 2024 · 2 comments · May be fixed by #4251
Labels
enhancement New feature or request v3 #1289 wontfix-v2 This will not be fixed in `v2.x`.

Comments

@al1maher
Copy link

al1maher commented Oct 2, 2024

Description

Problem
The current implementation of the keyboard shortcuts composable (defineShortcuts) doesn't work correctly with non-Latin keyboard layouts, such as Arabic. This limits the usability of the composable for users with different language settings.

Proposed Solution
Implement an optional configuration flag 'layoutIndependent' that, when set to true, makes the composable use KeyboardEvent.code instead of KeyboardEvent.key. This change will allow the shortcuts to work regardless of the keyboard layout or language setting.

Additional context

No response

@al1maher al1maher added enhancement New feature or request triage labels Oct 2, 2024
@Tragio
Copy link
Contributor

Tragio commented Oct 3, 2024

Hi @al1maher 👋 ,

Could you give us a little reproduction so we can have a base to work on? Perhaps this is already fixed on v3, or we can work on it for v3 🤔

@dvrtnkv
Copy link

dvrtnkv commented Jan 10, 2025

I completely agree with the need for this improvement. Currently, I face the same issue where I have to duplicate shortcut definitions for different keyboard layouts. Here's an example from my project:

defineShortcuts({
    ctrl_b: {
      usingInput: true,
      handler: () => toggleSidebar(),
    },
    ctrl_и: {
      usingInput: true,
      handler: () => toggleSidebar(),
    },
  });

It would be incredibly helpful if defineShortcuts allowed binding based on event.code, which is independent of the active keyboard layout. This enhancement would significantly simplify handling shortcuts across different languages.

Thank you for considering this!

al1maher pushed a commit to al1maher/ui that referenced this issue May 29, 2025
Add optional layoutIndependent flag to defineShortcuts composable that enables
layout-agnostic keyboard shortcuts by using KeyboardEvent.code instead of
KeyboardEvent.key.

When enabled, shortcuts work consistently across different keyboard layouts
(Arabic, Hebrew) by matching physical key positions rather than
character values.

Usage:
- layoutIndependent: false (default) - uses e.key for character-based matching
- layoutIndependent: true - uses e.code for physical key matching

Breaking change: When layoutIndependent is true, shortcut definitions must
use physical key codes (e.g., 'ctrl_KeyS' instead of 'ctrl_s').

Closes: nuxt#2293
@github-actions github-actions bot added the stale label Jun 8, 2025
@benjamincanac benjamincanac marked this as a duplicate of #3817 Jun 10, 2025
@benjamincanac benjamincanac added wontfix-v2 This will not be fixed in `v2.x`. v3 #1289 and removed triage stale labels Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v3 #1289 wontfix-v2 This will not be fixed in `v2.x`.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants