Skip to content

fix: #1789 add onclose prop#1790

Merged
shinokada merged 6 commits intothemesberg:mainfrom
shinokada:main
Oct 17, 2025
Merged

fix: #1789 add onclose prop#1790
shinokada merged 6 commits intothemesberg:mainfrom
shinokada:main

Conversation

@shinokada
Copy link
Copy Markdown
Collaborator

@shinokada shinokada commented Oct 15, 2025

Closes #1789

📑 Description

Add onclose prop to Popper.svelte.

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 and api-check directory as required
  • All the tests and check have passed by running pnpm check && pnpm test:e2e
  • My pull request is based on the latest commit (not the npm version).
  • I have checked the page with https://validator.unl.edu/

Summary by CodeRabbit

  • New Features

    • Components now expose an onclose callback for consistent close-event handling across dropdowns, popovers, and banners.
    • Dropdowns and popovers invoke onclose when they transition to closed; banners call onclose when dismissed.
  • Documentation

    • Added docs and examples demonstrating onclose and ontoggle usage.
    • Added a reusable dismissible-banner example with local persistence showing onclose wiring.

@vercel
Copy link
Copy Markdown

vercel bot commented Oct 15, 2025

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

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 15, 2025

Important

Review skipped

More than 25% of the files skipped due to max files limit. The review is being skipped to prevent a low-quality review.

192 files out of 299 files are above the max files limit of 100. Please upgrade to Pro plan to get higher limits.

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

Walkthrough

Adds optional onclose callbacks across components and types. Banner and Popper now accept and invoke onclose; Dropdown exposes onclose in its prop signature but does not forward it to Popper. Documentation and examples demonstrating onclose/ontoggle were added.

Changes

Cohort / File(s) Summary
Dropdown API
src/lib/dropdown/Dropdown.svelte
Adds onclose to the component's public prop destructuring (exposed in the API). Does not forward onclose via restProps to Popper.
Popper behavior
src/lib/utils/Popper.svelte
Destructures onclose as _onclose and invokes it from on_toggle when ev.newState === "closed".
Banner component
src/lib/banner/Banner.svelte
Adds public onclose prop and calls it from the close handler after setting open = false.
Types
src/lib/types.ts
Adds onclose to BannerProps and PopperProps; updates Omit<HTMLAttributes<...>> omissions to include "onclose".
Docs examples
src/routes/docs-examples/components/banner/Onclose.svelte, src/routes/docs-examples/components/dropdown/Onclose.svelte, src/routes/docs-examples/components/dropdown/Ontoggle.svelte
New example components demonstrating banner dismissal with persistence, dropdown onclose logging, and an ontoggle demo.
Docs content
src/routes/docs/components/banner.md, src/routes/docs/components/dropdown.md, src/routes/docs/components/toast.md
Adds onclose documentation and example references; adjusts Events example heights and toast event text.
Toast example
src/routes/docs-examples/components/toast/Events.svelte
Reworks example to use a standalone Toast, adds onclose handler, and updates click/close behavior and text.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App as Consumer (app)
  participant D as Dropdown
  participant P as Popper
  participant B as Banner

  App->>D: <Dropdown onclose={handler}>
  note right of D: Dropdown extracts `onclose` from props\nbut does NOT forward it to Popper
  D->>P: Mount Popper (without forwarded onclose)
  note over P: User toggles dropdown
  P->>P: on_toggle(ev)
  alt ev.newState == "closed"
    P->>P: invoke internal `_onclose` if provided locally
    P-->>App: (only if Popper received an onclose) calls onclose(ev)
  else
    P-->>D: update state
  end

  %% Banner flow (illustrative)
  App->>B: <Banner onclose={bannerHandler}>
  B->>B: user clicks close -> sets open = false
  B->>App: calls bannerHandler(event)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

Possibly related PRs

Poem

I nibble through the prop list, find onclose there,
A tiny hop — the Popper waits, the banner says its prayer.
I hide the message in my burrow, saved beneath the loam,
A rabbit hums, the docs now sing, and every component's home. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "fix: #1789 add onclose prop" clearly and concisely summarizes the main change in the changeset. The title directly references the issue being fixed and accurately describes the primary objective of adding the onclose prop to the affected components. The title is specific enough that a developer reviewing the history would immediately understand the core change without requiring additional context.
Linked Issues Check ✅ Passed The pull request successfully implements the requirements from issue #1789. The onclose callback has been added to the Dropdown component via the Popper base component, enabling developers to execute functions when a dropdown closes as requested. The implementation includes updated prop types (PopperProps, DropdownProps, BannerProps), event handlers that invoke the onclose callback when popovers transition to a closed state, and comprehensive documentation with working examples demonstrating the feature for both Dropdown and Banner components.
Out of Scope Changes Check ✅ Passed The vast majority of changes are properly scoped to implementing the onclose feature as requested in issue #1789. The implementation logically extends the onclose prop to Banner and Toast components since they utilize the Popper base component, which is a reasonable extension. However, the addition of Ontoggle.svelte documentation appears to be tangentially related, as the linked issue focuses specifically on onclose functionality, not ontoggle. This file documents what may be existing or tangentially related functionality and does not directly implement requirements from the linked issue.
Description Check ✅ Passed The pull request description follows the required template structure with all critical sections properly completed. It includes a reference to the closed issue (#1789), a clear description section explaining the addition of the onclose prop, a completed status checklist, and comprehensive checks indicating that code style compliance, documentation updates, tests, and latest commit requirements have all been addressed. The description is sufficiently detailed for the scope of this change.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

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.

@shinokada
Copy link
Copy Markdown
Collaborator Author

@jjagielka Please check if this is ok for your side.

Copy link
Copy Markdown
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

🧹 Nitpick comments (2)
src/lib/utils/Popper.svelte (1)

216-240: Update documentation comment to include the new prop.

The component documentation comment at the end of the file should list the onclose prop for completeness.

Apply this diff to update the documentation:

 @prop onbeforetoggle: _onbeforetoggle
 @prop ontoggle: _ontoggle
+@prop onclose: _onclose
 @prop class: className = ""
src/lib/dropdown/Dropdown.svelte (1)

35-49: Update documentation comment to include the new prop.

The component documentation comment should list the onclose prop for completeness.

Apply this diff to update the documentation:

 @prop activeUrl = ""
 @prop isOpen = $bindable(false)
+@prop onclose
 @prop ...restProps
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 87001f4 and 8e04e16.

📒 Files selected for processing (3)
  • src/lib/dropdown/Dropdown.svelte (2 hunks)
  • src/lib/types.ts (2 hunks)
  • src/lib/utils/Popper.svelte (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-11-22T08:37:27.996Z
Learnt from: mrh1997
PR: themesberg/flowbite-svelte#1442
File: src/lib/utils/Popper.svelte:144-145
Timestamp: 2024-11-22T08:37:27.996Z
Learning: In `src/lib/utils/Popper.svelte`, inconsistencies in event handling (e.g., using both `mouseenter`/`mouseleave` and `pointerenter`/`pointerleave`) may be intentional to minimize modifications and reduce the risk of new problems.

Applied to files:

  • src/lib/utils/Popper.svelte
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Playwright and Lint
🔇 Additional comments (3)
src/lib/types.ts (1)

2019-2019: LGTM! Type definition is correct.

The onclose callback has been properly added to PopperProps with the correct type signature (ev: TriggeredToggleEvent) => void, and it's correctly omitted from HTMLAttributes to prevent conflicts.

Also applies to: 2034-2034

src/lib/utils/Popper.svelte (1)

10-10: LGTM! Implementation follows the established pattern.

The onclose callback is properly destructured and invoked when the popover transitions to the closed state. The implementation is consistent with the existing ontoggle and onbeforetoggle handlers.

Also applies to: 141-143

src/lib/dropdown/Dropdown.svelte (1)

10-10: LGTM! Prop forwarding is implemented correctly.

The onclose prop is properly extracted from the component props and forwarded to the Popper component, enabling the callback functionality for dropdown close events.

Also applies to: 25-25

Copy link
Copy Markdown
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

🧹 Nitpick comments (3)
src/routes/docs-examples/components/dropdown/Onclose.svelte (1)

7-7: Consider documenting the event parameter or showing practical usage.

The onclose callback receives an event parameter but doesn't use it. While this simple example demonstrates the feature, consider either:

  1. Showing a more practical use case as mentioned in issue #1789 (e.g., triggering a state update or request)
  2. Adding a comment explaining what event information is available

This would help users understand the full capabilities of the callback.

Example showing the event structure:

-<Dropdown simple onclose={(ev) => console.log('closed by onclose')}>
+<Dropdown simple onclose={(ev) => console.log('Dropdown closed:', ev)}>

Or a more practical example:

-<Dropdown simple onclose={(ev) => console.log('closed by onclose')}>
+<Dropdown simple onclose={(ev) => {
+  console.log('Dropdown closed, triggering update...');
+  // Example: triggerUpdate() or handleSelectionChange()
+}}>
src/routes/docs-examples/components/dropdown/Ontoggle.svelte (1)

7-11: LGTM! Consider adding a comment explaining ontoggle vs onclose.

The implementation correctly demonstrates checking ev.newState === 'closed' with ontoggle. However, users might wonder when to use ontoggle versus onclose since both examples log on close.

Consider adding a brief comment in the example clarifying that:

  • ontoggle fires on all state changes (open/closed), requiring the state check
  • onclose fires only when closing (as shown in Onclose.svelte)

Optional enhancement:

 <Dropdown simple ontoggle={(ev) => {
+  // ontoggle fires on both open and close; check newState
   if (ev.newState === 'closed') {
     console.log('closed by ontoggle');
   }
 }}>
src/routes/docs/components/dropdown.md (1)

237-245: Add explanatory text to clarify onclose vs ontoggle usage.

The new section demonstrates both event handlers but doesn't explain when to use each. Based on the example implementations, users might not understand:

  • onclose: Fires only when the dropdown closes
  • ontoggle: Fires on all state changes (requires checking ev.newState)

Consider adding a brief explanation before the code examples:

 ### onclose and ontoggle
+
+Use `onclose` to run a callback when the dropdown closes. For more control over state changes, use `ontoggle` which fires on both open and close events.
 
 ```svelte example class="flex justify-center items-start h-44" hideResponsiveButtons
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f3f1969 and 42065c2.

📒 Files selected for processing (3)
  • src/routes/docs-examples/components/dropdown/Onclose.svelte (1 hunks)
  • src/routes/docs-examples/components/dropdown/Ontoggle.svelte (1 hunks)
  • src/routes/docs/components/dropdown.md (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-10-18T09:38:03.879Z
Learnt from: Chizaruu
PR: themesberg/flowbite-svelte#1465
File: src/lib/forms/Timepicker.svelte:105-116
Timestamp: 2024-10-18T09:38:03.879Z
Learning: In `Timepicker.svelte`, the `Dropdown` opens as intended and is used exclusively with the 'dropdown' and 'timerange-dropdown' Timepicker types.

Applied to files:

  • src/routes/docs-examples/components/dropdown/Ontoggle.svelte
  • src/routes/docs-examples/components/dropdown/Onclose.svelte
  • src/routes/docs/components/dropdown.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Playwright and Lint
🔇 Additional comments (1)
src/routes/docs/components/dropdown.md (1)

233-233: LGTM!

The height adjustment from h-40 to h-44 maintains consistency with the new examples added below.

Copy link
Copy Markdown
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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42065c2 and 86ddeed.

📒 Files selected for processing (3)
  • src/lib/dropdown/Dropdown.svelte (1 hunks)
  • src/routes/docs-examples/components/toast/Events.svelte (1 hunks)
  • src/routes/docs/components/toast.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/dropdown/Dropdown.svelte
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Playwright and Lint
🔇 Additional comments (1)
src/routes/docs-examples/components/toast/Events.svelte (1)

5-5: No changes needed: Toast supports onclose via restProps forwarding. The component dispatches a close event in its _close handler and spreads unknown props onto the root <div>, so onclose={()=>…} will fire correctly.

@jjagielka
Copy link
Copy Markdown
Contributor

@shinokada have you seen those Nitpick comments from coderabbit?

#1790 (review)

@shinokada
Copy link
Copy Markdown
Collaborator Author

shinokada commented Oct 17, 2025

@jjagielka Yes, gone through the coderabbit issues and updated accordingly.

@shinokada shinokada merged commit 7b6aef1 into themesberg:main Oct 17, 2025
1 of 2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Nov 1, 2025
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.

onclose for Dropdown

2 participants