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: Fixes clickoutside handler function for issue #1475 #1476

Merged
merged 2 commits into from
Oct 30, 2024

Conversation

bmanth60
Copy link
Contributor

@bmanth60 bmanth60 commented Oct 29, 2024

Closes #1475

📑 Description

Fixes the click outside dom check to find nodes within the datepicker container rather than looking at the input field

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

Recording.2024-10-29.120805.mp4

There is still an issue with the example, the listener is binding to the top level document, and clicks within the iframe is not registered so the example looks broken even though it is functioning

Summary by CodeRabbit

  • New Features
    • Improved click handling for the datepicker, ensuring it closes correctly when clicking outside the component.
  • Bug Fixes
    • Enhanced functionality of the datepicker container to ensure proper interaction and user experience.

Copy link

vercel bot commented Oct 29, 2024

@bmanth60 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 Oct 29, 2024

Walkthrough

The changes made in this pull request involve the Datepicker.svelte component, specifically introducing a new variable datepickerContainerElement to manage the container element of the datepicker. This variable replaces the previous inputElement reference in the click handling logic, ensuring that the datepicker closes correctly when clicks occur outside of its container. The structure and functionality of the datepicker remain unchanged aside from this update.

Changes

File Change Summary
src/lib/datepicker/Datepicker.svelte Added let datepickerContainerElement: HTMLDivElement and updated click handling logic to reference this new variable.

Assessment against linked issues

Objective Addressed Explanation
Datepicker closes when clicking outside of the component (#1475)

Possibly related PRs

  • Update DatePicker #1464: This PR updates the Datepicker.svelte component, which is directly related to the changes made in the main PR, as both involve modifications to the same component.
  • Make isSelected reactive in Datepicker #1466: This PR also modifies the Datepicker.svelte component, focusing on the logic for date selection, which is relevant to the changes in the main PR regarding click handling and date management.
  • fix: datepicker overwriting value #1474: This PR addresses issues within the Datepicker.svelte component, specifically related to date handling, which aligns with the changes made in the main PR regarding the management of the datepicker's container and click events.

🐰 In the garden, where bunnies play,
A datepicker blooms, bright as the day.
With clicks outside, it knows to hide,
A cozy retreat, where joy can abide.
Hooray for the changes, let’s hop and cheer,
For a smoother experience, we hold dear! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2c1166f and 60ad0e5.

📒 Files selected for processing (1)
  • src/lib/datepicker/Datepicker.svelte (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/datepicker/Datepicker.svelte

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>, 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 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.

@bmanth60
Copy link
Contributor Author

I am unable to run tests:

> [email protected] test:integration
> playwright test

[WebServer]
[WebServer] <--- Last few GCs --->
[WebServer]
[WebServer] [60351:0x57dff10]    90911 ms: Mark-Compact 2029.3 (2088.5) -> 2021.8 (2089.0) MB, 345.08 / 0.00 ms  (average mu = 0.389, current mu = 0.223) allocation failure; scavenge might not succeed
[WebServer] [60351:0x57dff10]    91301 ms: Mark-Compact 2026.8 (2089.0) -> 2022.9 (2097.0) MB, 381.93 / 0.00 ms  (average mu = 0.232, current mu = 0.020) allocation failure; scavenge might not succeed
[WebServer]
[WebServer]
[WebServer] <--- JS stacktrace --->
[WebServer]
[WebServer] FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
[WebServer] ----- Native stack trace -----
[WebServer]
[WebServer]  1: 0xb86ecf node::OOMErrorHandler(char const*, v8::OOMDetails const&) [node]
[WebServer]  2: 0xef74d0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node]
[WebServer]  3: 0xef77b7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node]
[WebServer]  4: 0x1109355  [node]
[WebServer]  5: 0x11211d8 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
[WebServer]  6: 0x10f72f1 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
[WebServer]  7: 0x10f8485 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
[WebServer]  8: 0x10d5ad6 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
[WebServer]  9: 0x1531906 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
[WebServer] 10: 0x7fa3d7ed9ef6
[WebServer] Aborted (core dumped)
Error: Process from config.webServer was not able to start. Exit code: 134

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: 1

🧹 Outside diff range and nitpick comments (1)
src/lib/datepicker/Datepicker.svelte (1)

Line range hint 37-45: Consider a more robust click detection strategy.

The current document-level click listener might limit the component's reusability in iframe contexts. For future improvement, consider:

  1. Using a portal/teleport pattern to handle modal-like behavior
  2. Attaching the click listener to a closer ancestor element
  3. Using the composed: true option in event handling to detect clicks across shadow DOM boundaries

This would make the component more versatile for various integration scenarios.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 351b721 and 2c1166f.

📒 Files selected for processing (1)
  • src/lib/datepicker/Datepicker.svelte (3 hunks)
🔇 Additional comments (2)
src/lib/datepicker/Datepicker.svelte (2)

28-28: LGTM: Well-typed container reference.

The new variable is appropriately typed and follows naming conventions.


253-253: LGTM: Correct container binding placement.

The bind:this directive is correctly placed on the root container div, ensuring proper click detection for the entire datepicker component.

Note: As mentioned in the PR description, clicks within iframes won't be detected since the click listener is bound to the top-level document. To verify iframe usage:

src/lib/datepicker/Datepicker.svelte Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

vercel bot commented Oct 29, 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 Oct 29, 2024 8:00pm

@shinokada
Copy link
Collaborator

Chizaruu Are you happy with this?

@Chizaruu
Copy link
Contributor

Chizaruu Are you happy with this?

Looks good!

@shinokada shinokada merged commit 4eda1c2 into themesberg:main Oct 30, 2024
3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Nov 26, 2024
8 tasks
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.

Datepicker is closing when clicking any of the buttons
3 participants