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

fix: remove hide delay if popper is not hoverable #1407

Merged
merged 3 commits into from
Sep 21, 2024

Conversation

therealsujitk
Copy link
Contributor

@therealsujitk therealsujitk commented Aug 6, 2024

Closes #1405

📑 Description

  • I've separated the focus logic from the click logic, this way it's more consistent with the flowbite dropdown and how dropdowns should work in general.
    • Now dropdowns will only open when clicked not focused (unless the trigger is set differently).
    • Because of this, I could also remove the hacky blocking logic.
  • The 100ms delay is only added when the popper trigger is hoverable and the content is active. This way a dropdown can be closed immediately without intersecting with other dropdowns.

Status

  • Not Completed
  • Completed

✅ Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • I have checked the page with https://validator.unl.edu/
  • All the tests have passed
  • My pull request is based on the latest commit (not the npm version).

ℹ Additional Information

None

Summary by CodeRabbit

  • New Features
    • Introduced a focusable feature to enhance popper visibility based on focus events.
    • Refined logic for opening and closing the popper, ensuring it only activates under specific conditions.
    • Improved event handling for click and focus events to enhance responsiveness and control.
    • Added a delay in hiding the popper to prevent unintended disappearance during mouse transitions.

Copy link

vercel bot commented Aug 6, 2024

@therealsujitk is attempting to deploy a commit to the Themesberg Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Aug 6, 2024

Walkthrough

The recent changes to the Popper.svelte file improve the user experience for dropdowns by refining the hide behavior. A conditional delay is introduced before hiding the floating element when hoverable items are present, preventing abrupt disappearances and overlap issues with multiple dropdowns. These enhancements lead to smoother interactions and greater usability.

Changes

Files Change Summary
src/lib/utils/Popper.svelte Added conditional delay to hideHandler for hoverable elements. Introduced focusable variable to manage focus events and refined the handling of focus and click events.

Assessment against linked issues

Objective Addressed Explanation
Dropdown doesn't disappear immediately when focus is lost (#1405)

Poem

In fields of dropdowns, bright and fair,
A rabbit hops with joy in the air.
No more quick hides, just a gentle delay,
Smooth transitions for a better display!
Hooray for the changes, let’s dance and play! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@therealsujitk therealsujitk marked this pull request as ready for review August 7, 2024 06:38
Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e3c3b47 and 305b505.

Files selected for processing (1)
  • src/lib/utils/Popper.svelte (1 hunks)
Additional comments not posted (1)
src/lib/utils/Popper.svelte (1)

71-79: LGTM! But verify the correctness of the conditional delay.

The code changes are approved. The conditional delay based on the hoverable flag improves user experience by preventing abrupt disappearance of the floating element.

However, ensure that the delay logic is correctly implemented and does not introduce any unintended side effects.

Verification successful

Verified: The conditional delay logic in the hideHandler function is correctly implemented.

The hideHandler function includes the conditional delay logic and is used appropriately in various event handlers to ensure the floating element does not hide immediately when the mouse moves from the reference element to the floating element.

  • File: src/lib/utils/Popper.svelte
  • Lines: 71-79
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the conditional delay in the hideHandler function.

# Test: Search for the hideHandler function usage. Expect: Correct implementation of the delay logic.
rg --type svelte -A 10 $'function hideHandler'

Length of output: 78


Script:

#!/bin/bash
# Description: Verify the correctness of the conditional delay in the hideHandler function.

# Find all .svelte files and search for the hideHandler function within those files.
fd --extension svelte --exec rg 'function hideHandler' -A 10

Length of output: 62


Script:

#!/bin/bash
# Description: Verify the correctness of the conditional delay in the hideHandler function.

# Search for the hideHandler function definition using ast-grep.
ast-grep --lang svelte --pattern 'function hideHandler() { $$$ }'

Length of output: 180


Script:

#!/bin/bash
# Description: Verify the correctness of the conditional delay in the hideHandler function.

# Search for the hideHandler function definition in .svelte files using rg.
rg 'function hideHandler' --glob '*.svelte' -A 10

Length of output: 51


Script:

#!/bin/bash
# Description: Verify the correctness of the conditional delay in the hideHandler function.

# Search for the term hideHandler and related event handlers within .svelte files.
rg 'hideHandler' --glob '*.svelte' -A 10

Length of output: 5141

@therealsujitk

This comment was marked as resolved.

@therealsujitk therealsujitk marked this pull request as draft August 9, 2024 10:17
@therealsujitk therealsujitk marked this pull request as ready for review August 9, 2024 12:29
Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 305b505 and 274819d.

Files selected for processing (1)
  • src/lib/utils/Popper.svelte (6 hunks)
Additional comments not posted (8)
src/lib/utils/Popper.svelte (8)

37-38: Introduction of focusable is appropriate.

The new focusable variable effectively separates focus logic from click logic, aligning with the PR objectives.


59-67: Improvement in showHandler logic is effective.

The updated logic prevents unnecessary toggling of the popper, enhancing the dropdown behavior.


76-88: hideHandler logic refinement enhances user experience.

The additional condition for hoverable elements prevents abrupt hiding, aligning with the PR objectives.


134-135: Dynamic event listener adjustments improve control.

The use of focusable and clickable flags in event listeners enhances the component's responsiveness.


165-165: closeOnClickOutside improves cross-browser consistency.

Adding this event listener resolves a known Safari issue, enhancing user experience.


174-179: Proper cleanup logic is implemented.

The removal of event listeners during component destruction prevents memory leaks and enhances reusability.


218-218: Conditional event handling with optional is effective.

Using the optional function for event handlers enhances modularity and aligns with design goals.


Line range hint 218-222: Integration of Frame component aligns with objectives.

The usage of the Frame component with updated logic enhances dropdown functionality and aligns with PR objectives.

@therealsujitk
Copy link
Contributor Author

@shinokada can you help test this and let me know if all the components that use <Popper /> are working correctly. I'm not sure what to do about the failing check, doesn't seem related to this PR.


One more thing, should we add the overflow-hidden class to the <Frame /> component?

Screenshot 2024-08-08 at 10 39 44

Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 274819d and 0457451.

Files selected for processing (1)
  • src/lib/utils/Popper.svelte (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/lib/utils/Popper.svelte

Copy link

vercel bot commented Sep 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flowbite-svelte ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 21, 2024 3:19pm

@shinokada shinokada merged commit c064ff3 into themesberg:main Sep 21, 2024
2 checks passed
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.

Dropdown doesn't disappear immediately when focus is lost
2 participants