Skip to content

Conversation

kaifcoder
Copy link

@kaifcoder kaifcoder commented Sep 9, 2025

Summarize the changes made and the motivation behind them.
Addressed issue number #1617
Reference related issues using # followed by the issue number.

If there are breaking API changes - like adding or removing props, or changing the structure of the theme - describe them, and provide steps to update existing code.

Summary by CodeRabbit

  • New Features

    • Dropdown now supports an onToggle callback to notify when the menu opens or closes, ensuring consistent notifications across open, close, and item selection interactions.
  • Documentation

    • Added a Storybook example showcasing onToggle behavior with multiple items and action logging.

Copy link

changeset-bot bot commented Sep 9, 2025

⚠️ No Changeset found

Latest commit: 61afc97

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Sep 9, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
flowbite-react Ready Ready Preview Comment Sep 9, 2025 9:44am
flowbite-react-storybook Ready Ready Preview Comment Sep 9, 2025 9:44am

Copy link
Contributor

coderabbitai bot commented Sep 9, 2025

Walkthrough

Adds a new onToggle callback prop to the Dropdown component and centralizes open/close state changes to always notify via this handler. Updates selection and programmatic state changes to use the centralized handler. Introduces a new Storybook story (onToggleHandler) demonstrating the onToggle behavior with actions.

Changes

Cohort / File(s) Summary
Dropdown component logic and API
packages/ui/src/components/Dropdown/Dropdown.tsx
Adds onToggle?: (open: boolean) => void to DropdownProps; centralizes open/close via handleOpenChange; routes all open state changes (including selection and floating logic setOpen) through the handler; updates DropdownProps typing to omit "onToggle" from inherited ButtonProps.
Storybook demo for onToggle
apps/storybook/src/Dropdown.stories.tsx
Adds export const onToggleHandler = Template.bind({}); story named "onToggle handlers" that passes onToggle action and renders items with individual onClick actions.

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant Dropdown
  participant FloatingLogic as useBaseFloating
  participant ConsumerOnToggle as onToggle(callback)

  rect rgb(240,248,255)
  note right of Dropdown: Open flow
  User->>Dropdown: Click trigger
  Dropdown->>FloatingLogic: setOpen(true)
  FloatingLogic-->>Dropdown: open=true
  Dropdown->>Dropdown: handleOpenChange(true)
  Dropdown-->>ConsumerOnToggle: onToggle(true)
  end

  rect rgb(245,245,245)
  note right of Dropdown: Item selection closes
  User->>Dropdown: Select item
  Dropdown->>Dropdown: handleOpenChange(false)
  Dropdown->>FloatingLogic: setOpen(false)
  Dropdown-->>ConsumerOnToggle: onToggle(false)
  end

  rect rgb(250,240,230)
  note right of Dropdown: Programmatic close/open
  FloatingLogic-->>Dropdown: open state change
  Dropdown->>Dropdown: handleOpenChange(open)
  Dropdown-->>ConsumerOnToggle: onToggle(open)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks (1 passed, 2 warnings)

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The current description consists solely of boilerplate contributor instructions and does not summarize or explain any of the actual changes made in this pull request, making it unrelated to the changeset. Provide a description that outlines the addition of the onToggle prop, the updated handler flow in the Dropdown component, any new Storybook story, references issue #1617, and details on breaking API changes and migration steps.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title “feat(Dropdown): add onToggle prop and update handlers for dropdown” succinctly highlights the primary change—introducing an onToggle prop and adjusting handler logic in the Dropdown component—using clear and focused wording that aligns with conventional commit style and avoids unnecessary detail.

Poem

I twitch my ears at toggles’ tune,
A dropdown blooms, then sleeps so soon.
Click—awake! Select—goodnight.
onToggle whispers left and right.
In stories bright, I hop with glee—
State flips once, then returns to me.

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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

🧹 Nitpick comments (7)
packages/ui/src/components/Dropdown/Dropdown.tsx (6)

48-49: Don’t Omit a non-existent key from ButtonProps

onToggle isn’t a member of ButtonProps, so including it in the Omit adds noise. Keeping the Omit minimal improves clarity.

-  extends Pick<FloatingProps, "placement" | "trigger">,
-    Omit<ButtonProps, keyof ThemingProps<DropdownTheme> | "onToggle">,
+  extends Pick<FloatingProps, "placement" | "trigger">,
+    Omit<ButtonProps, keyof ThemingProps<DropdownTheme>>,

57-57: Add concise TSDoc to define onToggle semantics

Document when onToggle fires (only on state changes vs. every call). This avoids consumer confusion.

-  onToggle?: (open: boolean) => void;
+  /**
+   * Called when the open state changes due to user interaction or programmatic updates.
+   * Receives the next `open` value.
+   */
+  onToggle?: (open: boolean) => void;

148-155: Fire onToggle only when state actually changes

Currently onToggle is invoked even if newOpen equals the current state, causing redundant callbacks (extra Storybook actions, potential double logs in StrictMode). Guard and include open in deps.

-  const handleOpenChange = useCallback(
-    (newOpen: boolean) => {
-      setOpen(newOpen);
-      onToggle?.(newOpen);
-    },
-    [onToggle],
-  );
+  const handleOpenChange = useCallback(
+    (newOpen: boolean) => {
+      if (newOpen === open) return;
+      setOpen(newOpen);
+      onToggle?.(newOpen);
+    },
+    [open, onToggle],
+  );

156-162: Avoid closing (and notifying) when already closed

When typeahead selects while closed, handleSelect calls handleOpenChange(false), which triggers onToggle(false) unnecessarily. Close only if open.

-  const handleSelect = useCallback(
-    (index: number | null) => {
-      setSelectedIndex(index);
-      handleOpenChange(false);
-    },
-    [handleOpenChange],
-  );
+  const handleSelect = useCallback(
+    (index: number | null) => {
+      setSelectedIndex(index);
+      if (open) handleOpenChange(false);
+    },
+    [open, handleOpenChange],
+  );

177-181: Minor: stabilize the setOpen bridge to avoid new function per render

Not critical, but passing a stable callback reduces churn if useBaseFLoating tracks handler identity.

-  const { context, floatingStyles, refs } = useBaseFLoating<HTMLButtonElement>({
-    open,
-    setOpen: (value) => {
-      const newOpen = typeof value === "function" ? value(open) : value;
-      handleOpenChange(newOpen);
-    },
-    placement,
-  });
+  const setOpenWithNotify = useCallback(
+    (value: SetStateAction<boolean>) => {
+      const next = typeof value === "function" ? (value as (prev: boolean) => boolean)(open) : value;
+      handleOpenChange(next);
+    },
+    [open, handleOpenChange],
+  );
+
+  const { context, floatingStyles, refs } = useBaseFLoating<HTMLButtonElement>({
+    open,
+    setOpen: setOpenWithNotify,
+    placement,
+  });

46-59: API addition: ensure docs and migration notes are updated

This is a new public prop. Please add it to the component docs (Props table), mention behavior in “Events”, and note in the PR description whether it’s a breaking change (it isn’t) and any migration hints.

I can open a docs PR. If helpful, I’ll also add a brief “onToggle” example mirroring the Storybook story.

apps/storybook/src/Dropdown.stories.tsx (1)

133-146: Nice addition; covers the new callback

Story cleanly demonstrates onToggle. Consider capitalizing the story name for consistency with others (“OnToggle handlers”) and optionally adding a quick note in the story description about firing on open/close.

-onToggleHandler.storyName = "onToggle handlers";
+onToggleHandler.storyName = "OnToggle handlers";
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 51621a1 and 61afc97.

📒 Files selected for processing (2)
  • apps/storybook/src/Dropdown.stories.tsx (1 hunks)
  • packages/ui/src/components/Dropdown/Dropdown.tsx (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/ui/src/components/Dropdown/Dropdown.tsx (2)
packages/ui/src/components/Button/Button.tsx (1)
  • ButtonProps (48-59)
packages/ui/src/types/index.ts (1)
  • ThemingProps (20-46)

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