Skip to content

[01088] Fix Button keyboard shortcuts on Mac with Alt/CMD modifiers#2962

Merged
rorychatt merged 2 commits intomainfrom
plan-01088-Ivy-Framework
Apr 3, 2026
Merged

[01088] Fix Button keyboard shortcuts on Mac with Alt/CMD modifiers#2962
rorychatt merged 2 commits intomainfrom
plan-01088-Ivy-Framework

Conversation

@rorychatt
Copy link
Copy Markdown
Collaborator

Summary

Fixed keyboard shortcuts on Mac when using Alt (Option) or CMD modifiers. The root cause was that event.key returns special characters on Mac when Alt is held (e.g., Alt+K produces "˚"), so key comparisons failed. Replaced event.key with event.code which represents the physical key regardless of modifiers. Also fixed the same bug in the useShortcutKey hook used by input widgets.

API Changes

  • Added keyToCode(key: string): string export to shortcut.ts — maps key names (e.g., "k", "Enter", "Delete") to KeyboardEvent.code values (e.g., "KeyK", "Enter", "Delete").

Files Modified

  • Frontend (core fix):

    • src/frontend/src/widgets/inputs/TextInputWidget/utils/shortcut.ts — Added keyToCode utility function
    • src/frontend/src/widgets/button/ButtonWidget.tsx — Replaced event.key comparison with event.code
    • src/frontend/src/widgets/inputs/TextInputWidget/hooks/useShortcutKey.ts — Same fix for input shortcut handling
  • Samples:

    • src/Ivy.Samples.Shared/Apps/Widgets/ButtonApp.cs — Added Alt+C and Cmd+V shortcut buttons
  • Tests:

    • src/frontend/e2e/samples/widgets/button.spec.ts — Added keyboard shortcut Playwright tests

Commits

  • 706685ac9 — Fix keyboard shortcuts on Mac by using event.code instead of event.key
  • bc8a11d80 — Add Alt/CMD shortcut test cases and Playwright tests

…event.key

On Mac, Alt/Option key produces special characters (e.g. Alt+K → ˚) causing
event.key comparison to fail. Using event.code compares the physical key
regardless of modifiers or keyboard layout.

- Add keyToCode() utility in shortcut.ts to map key names to KeyboardEvent.code values
- Update ButtonWidget.tsx to use event.code for shortcut matching
- Update useShortcutKey.ts with the same fix for input widget shortcuts
- Add Alt+C (Copy) and Cmd+V (Paste) buttons to ButtonApp keyboard shortcuts section
- Add Playwright tests for Alt+letter, Ctrl+letter, special key, and Ctrl+Enter shortcuts
- Add test for shortcut key label display on buttons
@rorychatt rorychatt merged commit caf4d67 into main Apr 3, 2026
11 checks passed
@rorychatt rorychatt deleted the plan-01088-Ivy-Framework branch April 3, 2026 13:00
@artem-ivy-ai
Copy link
Copy Markdown
Collaborator

Deploy timed out

I'm preparing your docs & samples for this PR. I'll update the comment as Sliplane reports progress.

Logs

No terminal state received from Sliplane after 30 minutes.

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.

2 participants