Skip to content

fix(theme): prevent dark mode toggle on search input keypress#944

Merged
Adityakishore0 merged 2 commits into
Adityakishore0:mainfrom
Ronak120703:main
Apr 30, 2026
Merged

fix(theme): prevent dark mode toggle on search input keypress#944
Adityakishore0 merged 2 commits into
Adityakishore0:mainfrom
Ronak120703:main

Conversation

@Ronak120703

@Ronak120703 Ronak120703 commented Apr 30, 2026

Copy link
Copy Markdown

Description & Technical Solution

Problem

Pressing the D key anywhere in the app was triggering the theme toggle, even when the user was typing inside input fields such as the search modal. This caused a poor user experience, as users were unable to type normally (e.g., typing “d” would switch themes instead of appearing in the input).

Impact

  • Broke typing experience in search input and other form fields
  • Unintended theme toggling during user interaction
  • Affected usability of keyboard-driven UI

Solution

Added a guard in the global keydown listener to detect when the user is interacting with input elements (input, textarea, select, and contenteditable fields).

If the event originates from a typing context, the theme toggle logic is skipped. Otherwise, pressing D continues to toggle between light and dark mode as intended.

This ensures:

  • Normal typing behavior inside inputs
  • Theme shortcut still works globally outside typing contexts

Checklist

  • Already rebased against main branch
  • Fix tested in search input and other interactive fields
  • No regression in global theme toggle behavior

Closes: #943

@vercel

vercel Bot commented Apr 30, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the abhinavvuco-8934's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Adityakishore0

Copy link
Copy Markdown
Owner

@Ronak120703 This PR is incomplete and needs proper documentation before it can be reviewed.

  • The PR description still contains the default template and hasn’t been filled.
  • No clear explanation of the problem, impact, or technical approach.
  • No issue linked (if this is fixing something, it should reference it).
  • Checklist is not addressed.
  • No screenshots or demo (even though this affects user interaction).

Please update the PR with:

  1. A proper description of the issue being fixed
  2. What exactly was causing the bug
  3. How your solution resolves it
  4. Link the related issue
  5. Confirm checklist items

Once that’s done, we can proceed with the technical review.

@Adityakishore0 Adityakishore0 self-assigned this Apr 30, 2026
@Adityakishore0 Adityakishore0 merged commit 33b5794 into Adityakishore0:main Apr 30, 2026
1 of 2 checks passed
@vercel

vercel Bot commented Apr 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
scroll-x-ui Ready Ready Preview, Comment Apr 30, 2026 3:37pm

@Adityakishore0

Adityakishore0 commented Apr 30, 2026

Copy link
Copy Markdown
Owner

@Ronak120703 Nice fix , this correctly prevents theme toggling while typing in inputs. Good handling of edge cases like contenteditable and custom textboxes.

A couple of small improvements i made to this to make it more robust:

  1. Use resolvedTheme instead of theme
    theme can sometimes be undefined or outdated depending on system settings. Using resolvedTheme ensures accurate toggling.

  2. Event listener re-binding
    Since theme is in the dependency array, the event listener gets re-attached on every theme change. It’s better to rely on resolvedTheme for stability.

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.

Typing “d” in the search bar triggers dark mode.

2 participants