Skip to content

feat: add default bang input section#150

Open
LokeshShelva wants to merge 2 commits into
T3-Content:mainfrom
LokeshShelva:feat/add-default-bang-selection
Open

feat: add default bang input section#150
LokeshShelva wants to merge 2 commits into
T3-Content:mainfrom
LokeshShelva:feat/add-default-bang-selection

Conversation

@LokeshShelva

@LokeshShelva LokeshShelva commented Jul 4, 2026

Copy link
Copy Markdown
  • Added default bang input field in the home page

This allows users to change the default search from google to any other engine / bang.

Note

Add default bang input section to the landing page settings panel

  • Adds a settings panel to the landing page with a text input for configuring the default bang, persisted to localStorage under the default-bang key.
  • Validates input against known bangs on a 350ms debounce, showing inline error or help text and an invalid CSS class when the value is unrecognized.
  • Fixes defaultBang initialization to fall back to 'g' when the stored value is missing or does not match a known bang.
  • Adds light/dark theme styles for the new settings panel, bang input, and helper/error text in global.css.

Macroscope summarized c1ae340.

Summary by CodeRabbit

  • New Features

    • Added a new settings panel for choosing a default bang.
    • The selected bang is saved locally and restored on return visits.
  • Bug Fixes

    • Improved input validation with clearer error feedback for empty or invalid bang values.
    • Updated input and dark-mode styling for a more consistent, polished appearance.

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a "Default bang" settings panel to the main page, allowing users to configure and persist a preferred bang via localStorage with debounced input validation against the known bangs list. Accompanying CSS adds settings panel, input, help/error, and dark-mode styling.

Changes

Default Bang Settings Panel

Layer / File(s) Summary
Default bang constants and validation logic
src/main.ts
Adds localStorage key/fallback constants, DOM bindings for the new input/error elements, and a debounced validateDefaultBang function that validates input against the bangs list, updates error text/invalid class, persists valid values, and initializes defaultBang from storage or fallback.
Settings panel UI and styling
src/main.ts, src/global.css
Adds the settings panel markup (input, help text, aria-live error message) and corresponding CSS for .settings-panel, .settings-label, .bang-input/.url-input, .bang-help, .bang-error, dark-mode color overrides, and minor .url-container/.copy-button layout tweaks.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Input as DefaultBangInput
  participant Validator as validateDefaultBang
  participant Storage as localStorage

  User->>Input: type bang value
  Input->>Validator: debounced input event (350ms)
  Validator->>Validator: trim/lowercase, check against bangs list
  alt valid bang
    Validator->>Storage: setItem(default-bang, value)
    Validator->>Input: clear error, remove invalid class
  else invalid/empty
    Validator->>Input: show error, add invalid class
  end
Loading

Related Issues: Not specified in the provided information.

Related PRs: Not specified in the provided information.

Suggested labels: enhancement, ui, css

Suggested reviewers: Not specified in the provided information.

Poem:
A bang, a bang, my kingdom for a bang! 🐇
Now saved snug in storage, no longer astray,
With error text glowing should it go astray.
The panel glows dark or bright as you choose,
Type your favorite bang — no more searches to lose!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a default bang input section.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@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

🧹 Nitpick comments (4)
src/main.ts (3)

4-6: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate default-bang fallback resolution logic.

The localStorage.getItem(LS_DEFAULT_BANG) ?? DEFAULT_BANG_FALLBACK pattern is duplicated at Line 87 (input init) and Lines 96-97 (module-level defaultBang computation). Extracting a shared helper reduces the risk of the two diverging if the resolution logic changes later.

♻️ Suggested consolidation
+function getStoredDefaultBangTrigger(): string {
+  return localStorage.getItem(LS_DEFAULT_BANG) ?? DEFAULT_BANG_FALLBACK;
+}
+
 function noSearchDefaultPageRender() {
   ...
-  defaultBangInput.value = localStorage.getItem(LS_DEFAULT_BANG) ?? DEFAULT_BANG_FALLBACK;
+  defaultBangInput.value = getStoredDefaultBangTrigger();
   ...
 }

-const storedDefaultBang = localStorage.getItem(LS_DEFAULT_BANG) ?? DEFAULT_BANG_FALLBACK;
+const storedDefaultBang = getStoredDefaultBangTrigger();
 const defaultBang = bangs.find((b) => b.t === storedDefaultBang) ?? bangs.find((b) => b.t === DEFAULT_BANG_FALLBACK);

Also applies to: 87-87, 96-97

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main.ts` around lines 4 - 6, The default-bang fallback resolution is
duplicated between the input initialization and the module-level defaultBang
computation. Extract the shared `localStorage.getItem(LS_DEFAULT_BANG) ??
DEFAULT_BANG_FALLBACK` logic into a single helper or constant-derived function
in `main.ts`, and use that from both call sites so `LS_DEFAULT_BANG`,
`DEFAULT_BANG_FALLBACK`, and `defaultBang` stay consistent if the resolution
rules change.

27-37: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Link the error message to the input for accessibility.

defaultBangInput has no aria-describedby/aria-invalid tied to .bang-error, so assistive tech users won't be reliably notified of validation state beyond the aria-live region timing.

♻️ Suggested markup addition
 <input
   id="default-bang-input"
   class="bang-input"
   type="text"
   autocomplete="off"
   spellcheck="false"
   inputmode="latin"
   placeholder="g"
+  aria-describedby="default-bang-error"
 />
 <p class="bang-help">Used when a query does not include a bang. Defaults to google</p>
-<p class="bang-error" aria-live="polite"></p>
+<p id="default-bang-error" class="bang-error" aria-live="polite"></p>

And toggle aria-invalid in validateDefaultBang alongside the invalid class.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main.ts` around lines 27 - 37, The default bang input in the main markup
is missing an accessibility link to the error text, so update the input element
for defaultBangInput to reference .bang-error with aria-describedby and to
reflect validation state with aria-invalid. Also adjust validateDefaultBang so
it toggles aria-invalid together with the existing invalid class on the input,
keeping the error message and input state synchronized.

36-36: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Minor text nit: capitalize "Google".

✏️ Suggested fix
-<p class="bang-help">Used when a query does not include a bang. Defaults to google</p>
+<p class="bang-help">Used when a query does not include a bang. Defaults to Google</p>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main.ts` at line 36, The help text in the bang query description uses a
lowercase product name; update the string in the main text rendering so it reads
“Google” with the proper capitalization. Locate the copy in the relevant UI text
near the bang-help content and adjust only the displayed wording.
src/global.css (1)

218-228: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider merging dark-mode .url-input/.bang-input rules.

The dark-mode block duplicates the same three properties across .url-input and .bang-input, mirroring what was already consolidated in the light-mode selector at Lines 112-119.

♻️ Suggested consolidation
-  .url-input {
-    border-color: `#3d3d3d`;
-    background-color: `#191919`;
-    color: `#fff`;
-  }
-
-  .bang-input {
-    border-color: `#3d3d3d`;
-    background-color: `#191919`;
-    color: `#fff`;
-  }
+  .url-input,
+  .bang-input {
+    border-color: `#3d3d3d`;
+    background-color: `#191919`;
+    color: `#fff`;
+  }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/global.css` around lines 218 - 228, The dark-mode styling for .url-input
and .bang-input in global.css is duplicated with the same three properties;
consolidate them into a single shared selector the same way the light-mode rules
are already grouped. Update the dark-mode block so one rule targets both classes
together, keeping the existing border-color, background-color, and color values
intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/global.css`:
- Around line 112-123: The `.bang-input` width rule in `global.css` is applying
a button-offset that only makes sense for `.url-input`, so remove the
`max-width: calc(100% - 44px)` override from `.bang-input` and keep that sizing
only for the input that lives beside `.copy-button` in the `.url-container`. Use
the `.bang-input` and `.url-input` selectors to locate the shared styles, and
ensure the settings input can expand to full width in `.settings-panel`.

---

Nitpick comments:
In `@src/global.css`:
- Around line 218-228: The dark-mode styling for .url-input and .bang-input in
global.css is duplicated with the same three properties; consolidate them into a
single shared selector the same way the light-mode rules are already grouped.
Update the dark-mode block so one rule targets both classes together, keeping
the existing border-color, background-color, and color values intact.

In `@src/main.ts`:
- Around line 4-6: The default-bang fallback resolution is duplicated between
the input initialization and the module-level defaultBang computation. Extract
the shared `localStorage.getItem(LS_DEFAULT_BANG) ?? DEFAULT_BANG_FALLBACK`
logic into a single helper or constant-derived function in `main.ts`, and use
that from both call sites so `LS_DEFAULT_BANG`, `DEFAULT_BANG_FALLBACK`, and
`defaultBang` stay consistent if the resolution rules change.
- Around line 27-37: The default bang input in the main markup is missing an
accessibility link to the error text, so update the input element for
defaultBangInput to reference .bang-error with aria-describedby and to reflect
validation state with aria-invalid. Also adjust validateDefaultBang so it
toggles aria-invalid together with the existing invalid class on the input,
keeping the error message and input state synchronized.
- Line 36: The help text in the bang query description uses a lowercase product
name; update the string in the main text rendering so it reads “Google” with the
proper capitalization. Locate the copy in the relevant UI text near the
bang-help content and adjust only the displayed wording.
🪄 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: 5801b0f3-c0b5-48cd-98df-0c41f6233979

📥 Commits

Reviewing files that changed from the base of the PR and between c1b821d and c1ae340.

📒 Files selected for processing (2)
  • src/global.css
  • src/main.ts

Comment thread src/global.css
Comment on lines +112 to +123
.url-input,
.bang-input {
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 4px;
width: 100%;
background: #f5f5f5;
}

.bang-input {
max-width: calc(100% - 44px);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

.bang-input max-width reduction looks misapplied.

.bang-input sits alone in .settings-panel (no adjacent button), unlike .url-input which shares .url-container with .copy-button. The calc(100% - 44px) offset appears intended to reserve space for that button, but it's applied to .bang-input instead, needlessly shrinking the settings input below full width.

🎨 Suggested fix
 .url-input,
 .bang-input {
   padding: 8px 12px;
   border: 1px solid `#ddd`;
   border-radius: 4px;
   width: 100%;
   background: `#f5f5f5`;
 }

-.bang-input {
-  max-width: calc(100% - 44px);
-}
+.url-input {
+  max-width: calc(100% - 44px);
+}
📝 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
.url-input,
.bang-input {
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 4px;
width: 100%;
background: #f5f5f5;
}
.bang-input {
max-width: calc(100% - 44px);
}
.url-input,
.bang-input {
padding: 8px 12px;
border: 1px solid `#ddd`;
border-radius: 4px;
width: 100%;
background: `#f5f5f5`;
}
.url-input {
max-width: calc(100% - 44px);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/global.css` around lines 112 - 123, The `.bang-input` width rule in
`global.css` is applying a button-offset that only makes sense for `.url-input`,
so remove the `max-width: calc(100% - 44px)` override from `.bang-input` and
keep that sizing only for the input that lives beside `.copy-button` in the
`.url-container`. Use the `.bang-input` and `.url-input` selectors to locate the
shared styles, and ensure the settings input can expand to full width in
`.settings-panel`.

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