Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added focus functionality on home page search bar #962

Merged
merged 5 commits into from
Mar 2, 2025

Conversation

kayashth1
Copy link
Collaborator

@kayashth1 kayashth1 commented Feb 28, 2025

Resolves #929

Summary by CodeRabbit

  • New Features
    • Enhanced the search input behavior to automatically display suggestions when the search field is focused with text entered.
    • Cleared any highlighted suggestions when there is no valid input, providing a smoother and more intuitive search experience for users.
    • Added functionality to remove focus from the search input when the 'Escape' key is pressed.

Copy link

coderabbitai bot commented Feb 28, 2025

Walkthrough

The changes introduce a new reference, inputRef, for the search input field in the MultiSearch component. The handleKeyDown function is modified to call inputRef.current?.blur() when the 'Escape' key is pressed, removing focus from the input field. Additionally, a new function, handleFocusSearch, is added to manage the focus event on the input, checking conditions related to searchQuery and showSuggestions. The input's onFocus event is updated to invoke this new function, enhancing user interaction control.

Changes

File Change Summary
frontend/src/.../MultiSearch.tsx Added new variable inputRef and method handleFocusSearch. Updated the onFocus handler to call handleFocusSearch. Modified handleKeyDown to include inputRef.current?.blur() for 'Escape' key.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant I as Input Field
    participant H as handleFocusSearch()
    
    U->>I: Focus on search input
    I->>H: Trigger onFocus event
    alt searchQuery not empty and suggestions hidden
        H-->>I: Set showSuggestions = true (display suggestions)
    else
        H-->>I: Reset highlightedIndex to null
    end
Loading

Poem

I'm just a little rabbit in the code parade,
Hoping through lines with a skip and a shade.
The focus now shines, suggestions spring anew,
Clearing old highlights, making room for the view.
A joyful hop, a tech delight, in every line I wade!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 94bc6d6 and 5b5f8c4.

📒 Files selected for processing (1)
  • frontend/src/components/MultiSearch.tsx (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Run backend tests
  • GitHub Check: Run frontend unit tests
  • GitHub Check: CodeQL (python)
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: CodeQL (javascript-typescript)
🔇 Additional comments (5)
frontend/src/components/MultiSearch.tsx (5)

36-36: Well-implemented ref for the input element.

Adding this ref enables direct DOM manipulation of the input element, which is necessary for the blur functionality implemented below.


91-91: Great fix for the Escape key behavior.

This directly addresses the prior feedback where pressing Escape would close the dropdown but clicking on the search bar wouldn't reopen it. By explicitly blurring the input when Escape is pressed, you ensure that subsequent focus events will properly trigger the dropdown.


159-165: Good implementation of focus handling logic.

The handleFocusSearch function correctly handles the case where a user focuses on the search bar after previously dismissing the suggestions. The condition checks both that there's content in the search query and that suggestions aren't currently displayed.


192-192: Correct assignment of ref to input element.

This connects the previously defined ref to the actual DOM element.


194-194: Properly wired up focus handler.

This correctly attaches the new focus handler to the input element.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kayashth1 kayashth1 changed the title added onFocusSearch functionality on search bar added focus functionality on home page search bar Feb 28, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

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)
frontend/src/components/MultiSearch.tsx (1)

157-163: Fix spacing in else statement for code style consistency.

The new handleFocusSearch function looks good functionally but has inconsistent formatting in the else statement. There should be spaces around the else keyword to match the code style used throughout the rest of the component.

  const handleFocusSearch = () => {
    if (searchQuery.trim().length > 0 && !showSuggestions) {
      setShowSuggestions(true)
-  }else{
+  } else {
    setHighlightedIndex(null)
  }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 126b0b1 and a4e9303.

📒 Files selected for processing (1)
  • frontend/src/components/MultiSearch.tsx (2 hunks)
🔇 Additional comments (1)
frontend/src/components/MultiSearch.tsx (1)

191-191: Good UX improvement with onFocus handler.

Adding the onFocus handler to show suggestions when the user focuses on the search field is a good UX improvement. This allows users to see their previous search results immediately when they click back into the search field.

@arkid15r arkid15r requested a review from aramattamara March 1, 2025 04:37
Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

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

Thank you for working on this!
One issue I noticed ⬇️

Copy link

sonarqubecloud bot commented Mar 1, 2025

@kayashth1 kayashth1 requested a review from kasya March 1, 2025 22:31
Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

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

LGTM!

@kasya kasya added this pull request to the merge queue Mar 2, 2025
Merged via the queue into OWASP:main with commit 7996008 Mar 2, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve home page search bar behavior
2 participants