Skip to content

feat: add keyboard shortcut for search and accessibility label - #2

Open
itzMRZ wants to merge 4 commits into
mainfrom
palette-search-ux-1375227574019156193
Open

feat: add keyboard shortcut for search and accessibility label#2
itzMRZ wants to merge 4 commits into
mainfrom
palette-search-ux-1375227574019156193

Conversation

@itzMRZ

@itzMRZ itzMRZ commented Jan 10, 2026

Copy link
Copy Markdown
Owner
  • Added / and Ctrl+K keyboard shortcuts to focus search input
  • Added visually hidden label for search input for better accessibility
  • Added visual keyboard hint to search bar on desktop
  • Added .sr-only utility class

Summary by cubic

Adds standard search shortcuts and an accessible label to make search faster and screen-reader friendly. Addresses Linear palette-search-ux-1375227574019156193 by adding keyboard focus and a discoverable desktop hint.

  • New Features
    • Press / or Ctrl/Cmd+K to focus the search input; Escape blurs it.
    • Adds a visually hidden label for the search input using a new .sr-only utility.
    • Shows a desktop-only “/” shortcut hint in the search bar, hidden when typing or focused.

Written for commit cc5dc7a. Summary will update on new commits.

Summary by CodeRabbit

  • New Features

    • Keyboard shortcuts (/ and Ctrl/Cmd+K) focus the search input
    • Clear button for easier query management
    • Desktop shortcut hints visible to guide users
    • Escape blurs/unfocuses the search input
  • Improvements

    • Enhanced screen-reader support and semantic labeling for the search UI
    • Visual utility added to hide labels while keeping them accessible

✏️ Tip: You can customize this high-level summary in your review settings.

- Added `/` and `Ctrl+K` keyboard shortcuts to focus search input
- Added visually hidden label for search input for better accessibility
- Added visual keyboard hint to search bar on desktop
- Added `.sr-only` utility class
@vercel

vercel Bot commented Jan 10, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Review Updated (UTC)
usis-dump-analyser Ready Ready Preview, Comment Jan 10, 2026 9:39pm

@coderabbitai

coderabbitai Bot commented Jan 10, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds search accessibility enhancements: screen-reader label and visible hint, keyboard shortcuts (/, Ctrl/Cmd+K) to focus the search input and Escape to blur, new CSS utilities for visually hidden content and shortcut hint, plus a new Markdown note documenting these choices.

Changes

Cohort / File(s) Summary
Documentation
\.Jules/palette\.md
New Markdown note (dated) documenting search keyboard shortcuts, accessibility guidance, and the use of visually hidden labels plus visible shortcut hints.
UI Markup
index.html
Adds a labeled search input, a screen-reader-only label (.sr-only), a visible clear button, and a keyboard shortcut hint element integrated into the markup.
Keyboard Shortcuts Handler
js/.../uiController.js, js/uiController.js
Adds keydown handling for / and Ctrl/Cmd+K to focus the search input and Escape to blur it; includes guards to avoid firing while typing in other inputs. Note: handler appears wired in more than one place (duplicate wiring).
Accessibility & UI Styling
styles.css
Adds .sr-only utility to visually hide content but keep it accessible to screen readers, and .shortcut-hint styling with positioning, focus/placeholder visibility rules, and responsive visibility via media query.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Tip-tap I hop to the key,
Slash and Command bring focus to me.
Hidden words sing so all can find,
A hint appears for curious mind.
Hooray—search hops happy and free! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding keyboard shortcuts (/ and Ctrl/Cmd+K) for search input focus and a visually hidden accessibility label, which are the primary features introduced across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 4 files

Confidence score: 3/5

  • Potential crash in js/uiController.js because searchInput.focus() is called without the usual null guard; if the element is absent the UI could throw before initializing search.
  • Misleading "Clear search" comment in js/uiController.js while the code only blurs the input, which may confuse future maintenance decisions.
  • Pay close attention to js/uiController.js - add the missing null check and correct the comment to reflect actual behavior.
Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="js/uiController.js">

<violation number="1" location="js/uiController.js:295">
P2: Missing null check for `searchInput`. Other code in this file guards with `if (this.elements.searchInput)` before use. If the element doesn't exist, calling `.focus()` will throw an error.</violation>

<violation number="2" location="js/uiController.js:298">
P3: Misleading comment: says "Clear search" but code only blurs (unfocuses) the input without clearing the search text.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread js/uiController.js
Comment thread js/uiController.js Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @js/uiController.js:
- Around line 282-302: The keydown handler registered via
document.addEventListener('keydown', (e) => ...) uses this.elements.searchInput
multiple times without verifying it exists, which can cause runtime errors; fix
this by adding a defensive null check for this.elements.searchInput at the start
of the handler (or before each use) and early-return if it's missing, and also
guard the Escape branch so it only compares document.activeElement ===
this.elements.searchInput when this.elements.searchInput is non-null; keep the
rest of the shortcut logic unchanged.
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dbec3fb and 43cbcf6.

📒 Files selected for processing (4)
  • .Jules/palette.md
  • index.html
  • js/uiController.js
  • styles.css
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🔇 Additional comments (4)
styles.css (2)

148-159: LGTM! Standard accessibility pattern correctly implemented.

The .sr-only utility follows the well-established pattern for visually hiding content while keeping it accessible to screen readers.


467-492: LGTM! Well-designed keyboard hint with responsive behavior.

The .shortcut-hint styling correctly implements:

  • Desktop-only display via media query
  • Smart hiding when input is focused or has content
  • Proper positioning within the search container

The general sibling combinator (~) on lines 489-491 works well with the HTML structure in index.html.

index.html (1)

68-74: Excellent accessibility implementation!

The search input markup demonstrates best practices:

  • Properly associated label via for="searchInput" (Line 69)
  • Screen-reader-only label using .sr-only class
  • Decorative hint correctly marked with aria-hidden="true" (Line 73)
  • Clear button includes aria-label for screen readers (Line 72)

This ensures the search functionality is accessible to all users while maintaining the intended visual design.

.Jules/palette.md (1)

1-3: Great practice documenting accessibility learnings!

This note captures valuable insights about keyboard shortcuts and accessibility patterns that can guide future feature development.

Comment thread js/uiController.js
@itzMRZ

itzMRZ commented Jan 10, 2026

Copy link
Copy Markdown
Owner Author

@jules
Check if these issues are valid — if so, understand the root cause of each and fix them.

P2: Missing null check for `searchInput`. Other code in this file guards with `if (this.elements.searchInput)` before use. If the element doesn't exist, calling `.focus()` will throw an error. P3: Misleading comment: says "Clear search" but code only blurs (unfocuses) the input without clearing the search text.

cubic-dev-ai[bot] and others added 2 commits January 10, 2026 21:33
- Added `/` and `Ctrl+K` keyboard shortcuts to focus search input
- Added visually hidden label for search input for better accessibility
- Added visual keyboard hint to search bar on desktop
- Added `.sr-only` utility class
- Updated comment for keyboard listener logic
- Added null check for search input in keyboard listener

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
js/uiController.js (1)

282-305: Keyboard shortcuts: don’t steal focus during modals; broaden “typing” guards; handle K case

Nice improvement and the searchInput null guard fixes the reported risk. A couple UX/a11y edge cases remain:

  • If the help modal is open, / or Ctrl/Cmd+K can focus the search input behind the modal (confusing and breaks modal keyboard flow).
  • Guarding only INPUT/TEXTAREA misses SELECT and contenteditable targets.
  • e.key === 'k' won’t fire for uppercase K (Shift+Cmd/Ctrl+K).
Proposed tweak (localized to this block)
 document.addEventListener('keydown', (e) => {
   // Guard clause if search input doesn't exist
   if (!this.elements.searchInput) return;
+  if (e.defaultPrevented) return;
+
+  // Don't steal focus when the help modal is open
+  if (this.elements.infoModal?.classList.contains('visible')) return;
+
+  const target = e.target;
+  const tag = target?.tagName;
+  const isTypingContext =
+    target?.isContentEditable ||
+    tag === 'INPUT' ||
+    tag === 'TEXTAREA' ||
+    tag === 'SELECT';
 
   // Focus search on '/' or Ctrl+K (Cmd+K)
-  if ((e.key === '/' || (e.key === 'k' && (e.metaKey || e.ctrlKey))) &&
+  const key = (e.key || '').toLowerCase();
+  if ((key === '/' || (key === 'k' && (e.metaKey || e.ctrlKey))) &&
       document.activeElement !== this.elements.searchInput) {
 
-    // Don't trigger if user is typing in another input (if any existed)
-    if (document.activeElement.tagName === 'INPUT' ||
-        document.activeElement.tagName === 'TEXTAREA') {
+    // Don't trigger if user is typing in another control
+    if (isTypingContext) {
       return;
     }
 
     e.preventDefault();
     this.elements.searchInput.focus();
   }
 
   // Remove focus from search on Escape
   if (e.key === 'Escape' && document.activeElement === this.elements.searchInput) {
     this.elements.searchInput.blur();
   }
 });
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 43cbcf6 and cc5dc7a.

📒 Files selected for processing (1)
  • js/uiController.js

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.

1 participant