Skip to content

🎨 Palette: Add keyboard shortcut hints and functionality to main action#138

Draft
Shin5hi wants to merge 1 commit into
mainfrom
palette-add-keyboard-shortcut-16356147399814882391
Draft

🎨 Palette: Add keyboard shortcut hints and functionality to main action#138
Shin5hi wants to merge 1 commit into
mainfrom
palette-add-keyboard-shortcut-16356147399814882391

Conversation

@Shin5hi

@Shin5hi Shin5hi commented Apr 18, 2026

Copy link
Copy Markdown
Owner

💡 What:

Added a Ctrl+K / Cmd+K keyboard shortcut to the main action button, complete with visual <kbd> hints, semantic aria-keyshortcuts attributes, and functional event binding. Updated the JavaScript state management to safely preserve nested HTML structural state (childNodes) during button loading transitions, avoiding innerHTML. Updated the Content Security Policy (CSP) hash to reflect the inline script modifications.

🎯 Why:

To improve accessibility and provide power users with a faster, frictionless way to interact with the primary action on the page without needing to use a mouse. Safely managing nested HTML states (<kbd>) prevents XSS vulnerabilities while keeping the UI consistent during active/loading states.

📸 Before/After:

Before: Button says "Click Me (Accessible)" with no keyboard shortcuts.
After: Button says "Click Me (Accessible) Ctrl+K", and can be triggered seamlessly via the keyboard shortcut from anywhere on the page.

♿ Accessibility:

  • Added aria-keyshortcuts to expose the shortcut to assistive technologies.
  • Ensures the shortcut focuses the button programmatically before triggering it, maintaining a logical DOM focus state for keyboard users.
  • Maintained strict CSP and safe DOM manipulation (using replaceChildren) to preserve the <kbd> structural elements without risking XSS.

PR created automatically by Jules for task 16356147399814882391 started by @Shin5hi

Summary by CodeRabbit

  • New Features

    • Added keyboard shortcut (Ctrl+K / Cmd+K) to access the primary button action
    • Displays visual keyboard shortcut hint for discoverability
    • Improved button state handling during loading operations
  • Documentation

    • Updated implementation guide with keyboard shortcut approach details

- Adds `aria-keyshortcuts="Control+K Meta+K"` and a visual `<kbd>Ctrl+K</kbd>` hint to the button.
- Updates JavaScript state management to preserve nested HTML (`childNodes`) during the loading state.
- Adds global `keydown` event listener for `Ctrl+K`/`Cmd+K` to focus and trigger the button.
- Recalculates and updates the CSP `script-src` hash.
- Logs critical learning regarding DOM structural state preservation in `.jules/palette.md`.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Apr 18, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ab0c58a5-5c54-48ad-9993-1ed5f6ac4adb

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch palette-add-keyboard-shortcut-16356147399814882391

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.

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@index.html`:
- Around line 126-132: The global keydown handler on document (the listener that
checks (e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'k' and then focuses
and clicks actionBtn) needs guards so it doesn't run when the user is typing or
when other modifiers like Shift are held; update the handler to return early if
e.shiftKey is true and to return early when the event target is an editable
element (target.tagName is INPUT, TEXTAREA, or target.isContentEditable is true)
or a form field role, then proceed to preventDefault(), focus actionBtn and
click it only when those guards pass.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8b1d51c5-16ec-4c14-b697-50303cea99f2

📥 Commits

Reviewing files that changed from the base of the PR and between 717bd1d and 2fde93d.

📒 Files selected for processing (2)
  • .jules/palette.md
  • index.html

Comment thread index.html
Comment on lines +126 to +132
document.addEventListener('keydown', (e) => {
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'k') {
e.preventDefault();
actionBtn.focus();
actionBtn.click();
}
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Scope the global shortcut to avoid hijacking editable contexts.

At Line 127, this handler also fires while users are typing in editable elements and on combos like Ctrl/Cmd+Shift+K. That can trigger unintended actions and suppress expected defaults.

🔧 Proposed guard conditions
 document.addEventListener('keydown', (e) => {
-  if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'k') {
-    e.preventDefault();
-    actionBtn.focus();
-    actionBtn.click();
-  }
+  const isShortcut =
+    (e.ctrlKey || e.metaKey) &&
+    !e.altKey &&
+    !e.shiftKey &&
+    e.key.toLowerCase() === 'k';
+
+  const target = e.target;
+  const isEditable =
+    target instanceof HTMLElement &&
+    (target.isContentEditable ||
+      target.tagName === 'INPUT' ||
+      target.tagName === 'TEXTAREA' ||
+      target.tagName === 'SELECT');
+
+  if (!isShortcut || isEditable || actionBtn.disabled) return;
+
+  e.preventDefault();
+  actionBtn.focus();
+  actionBtn.click();
 });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
document.addEventListener('keydown', (e) => {
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'k') {
e.preventDefault();
actionBtn.focus();
actionBtn.click();
}
});
document.addEventListener('keydown', (e) => {
const isShortcut =
(e.ctrlKey || e.metaKey) &&
!e.altKey &&
!e.shiftKey &&
e.key.toLowerCase() === 'k';
const target = e.target;
const isEditable =
target instanceof HTMLElement &&
(target.isContentEditable ||
target.tagName === 'INPUT' ||
target.tagName === 'TEXTAREA' ||
target.tagName === 'SELECT');
if (!isShortcut || isEditable || actionBtn.disabled) return;
e.preventDefault();
actionBtn.focus();
actionBtn.click();
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@index.html` around lines 126 - 132, The global keydown handler on document
(the listener that checks (e.ctrlKey || e.metaKey) && e.key.toLowerCase() ===
'k' and then focuses and clicks actionBtn) needs guards so it doesn't run when
the user is typing or when other modifiers like Shift are held; update the
handler to return early if e.shiftKey is true and to return early when the event
target is an editable element (target.tagName is INPUT, TEXTAREA, or
target.isContentEditable is true) or a form field role, then proceed to
preventDefault(), focus actionBtn and click it only when those guards pass.

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