#issue 977 feat: add global keyboard shortcut Alt+T / Option+T (in Mac) to toggle theme …#985
Conversation
… Relocated shortcut listening logic to root Providers to make theme toggling global (works on dashboard, settings, and public profile pages). - Changed trigger from plain 'T' key to 'Alt+T' (Windows/Linux) and 'Option+T' (Mac) to avoid browser shortcuts and typing conflicts. - Ensured shortcuts do not fire when typing inside inputs, textareas, selects, or contenteditable elements. - Updated ShortcutsModal to dynamically show 'Option + T' for macOS users and 'Alt + T' for Windows/Linux based on user-agent detection. - Streamlined header trigger button and maintained standard layout. ## Description This pull request adds a global keyboard shortcut (`Alt + T` on Windows/Linux and `Option + T` on macOS) to toggle the dark/light theme across all application pages (including the dashboard, settings, and public profile pages). It also updates the Shortcuts panel to dynamically reflect the correct keys depending on the client OS. ### Problem Previously, the theme toggle shortcut triggered on the letter `T` alone (prone to accidental triggers) and was only active on the Dashboard page because the listener was coupled with the Dashboard Header component. On the settings or public profile pages, it did not work. Additionally, the shortcuts overlay listed the key as `"T"`. ### Solution 1. **Created `GlobalKeyboardShortcuts.tsx`**: A new root-level, headless keyboard shortcut listener component mounted inside `Providers.tsx`. It handles the global key combinations and includes screen-reader accessibility announcements (`aria-live="polite"`). 2. **OS Auto-Detection**: Integrated dynamic platform detection in `ShortcutsModal.tsx` using `navigator.userAgent` to display `Option + T` on Mac platforms and `Alt + T` on other operating systems. 3. **Decoupled UI & Logic**: Simplified `KeyboardShortcuts.tsx` into a lightweight trigger button that dispatches a custom window event (`openShortcuts`) to open the global shortcuts modal. 4. **Input Avoidance**: Guaranteed that shortcut hotkeys do not fire when a user has focus inside an `input`, `textarea`, `select`, or `contenteditable` container. ### Acceptance Criteria Checklist - [x] `Alt+T` / `Option+T` toggles theme globally. - [x] Works seamlessly on the dashboard, settings, and public profile pages. - [x] Does not fire when the user is typing in an input, textarea, select, or contenteditable. - [x] Shortcut listed in the keyboard shortcuts overlay panel as `Option + T` (on Mac) or `Alt + T` (on Windows/Linux). ### How to Test 1. Press `Alt+T` (or `Option+T` on Mac) on the dashboard, settings page, and public profile page to verify the theme toggles globally. 2. Select any input or textarea on the settings page and type words with 't' and 'Alt+t'. Confirm the theme does not toggle while typing. 3. Click the "Shortcuts" button or press `?` on the keyboard to open the Shortcuts modal. 4. Check that the label for "Toggle theme" dynamically displays `Option + T` on macOS devices and `Alt + T` on Windows/Linux devices.
|
@coutKaustubh is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel. A member of the Team first needs to authorize it. |
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
There was a problem hiding this comment.
Thanks for your first PR on DevTrack! 🎉
A maintainer will review it within 48 hours. While you wait:
- Make sure CI is passing (type-check + lint)
- Double-check the PR description is filled out and the issue is linked
- Feel free to ask questions in Discussions if you need help
If you find DevTrack useful, a ⭐ star on the repo is always appreciated — it helps the project grow and attract more contributors!
|
I have solved the issue .. Please look towards it and tell me if any error @Priyanshu-byte-coder |
Priyanshu-byte-coder
left a comment
There was a problem hiding this comment.
Great feature! One thing to clean up before merge:
package-lock.json has 22k lines of unrelated changes. Please regenerate it by running npm install on a clean checkout of latest main and commit only the lockfile diff related to any packages your PR actually adds.
… match upstream/main
…ustubh/devtrack into Shortcut-Toggle-for-theme
|
Thanks for pointing that out! I've cleaned up the unrelated |
Description
This pull request adds a global keyboard shortcut (
Alt + Ton Windows/Linux andOption + Ton macOS) to toggle the dark/light theme across all application pages (including the dashboard, settings, and public profile pages). It also updates the Shortcuts panel to dynamically reflect the correct keys depending on the client OS.Problem
Previously, the theme toggle shortcut triggered on the letter
Talone (prone to accidental triggers) and was only active on the Dashboard page because the listener was coupled with the Dashboard Header component. On the settings or public profile pages, it did not work. Additionally, the shortcuts overlay listed the key as"T".Solution
GlobalKeyboardShortcuts.tsx: A new root-level, headless keyboard shortcut listener component mounted insideProviders.tsx. It handles the global key combinations and includes screen-reader accessibility announcements (aria-live="polite").ShortcutsModal.tsxusingnavigator.userAgentto displayOption + Ton Mac platforms andAlt + Ton other operating systems.KeyboardShortcuts.tsxinto a lightweight trigger button that dispatches a custom window event (openShortcuts) to open the global shortcuts modal.input,textarea,select, orcontenteditablecontainer.Acceptance Criteria Checklist
Alt+T/Option+Ttoggles theme globally.Option + T(on Mac) orAlt + T(on Windows/Linux).How to Test
Alt+T(orOption+Ton Mac) on the dashboard, settings page, and public profile page to verify the theme toggles globally.?on the keyboard to open the Shortcuts modal.Option + Ton macOS devices andAlt + Ton Windows/Linux devices.