You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the Issues to see if this bug has already been reported
I have tested the latest version
Summary
Describe how it should work, and provide examples of the solution, which might include screenshots or code snippets.
<Dropdown /> should have exposed just a few properties and I'd have not ended up double bag it.
I think I'd need:
On close callback
Option to use <FloatingPortal />
useBaseFloating, useFloatingInteractions
Base button
Context
What are you trying to accomplish? How is your use case affected by not having this feature?
I've needed to implement a context menu (triple dot) as the last column in a table's row. The last row's <Dropdown /> can have it's elements cut off by the table (or any container's) overflow, or worse cause scrolling if it's overflow-x-auto. I need a way to remove it from dom, portaling, floating etc to achieve the below:
It should have been so much easier.
Here's a quick hack I'm using to get around the current implementation:
import{FloatingPortal,useFloating}from"@floating-ui/react";import{Dropdown,typeDropdownProps}from"flowbite-react";import{useEffect,useId,useState,typeFC,typeReactNode}from"react";import{useBaseFloating}from"../../../hooks";exporttypeDropdownPortalProps=Omit<DropdownProps,"label"|"trigger">&{/** Elements to act as trigger. You must supply your own <button>, unlike standard <Dropdown label /> */label: ReactNode;"data-testid"?: string;};exportconstDropdownPortal: FC<DropdownPortalProps>=({
label,
...props})=>{const{ refs, floatingStyles }=useBaseFloating({placement: "bottom",});constid=useId();const[isOpen,setIsOpen]=useState(false);consthandleOpen=()=>{setIsOpen(true);setDropdownState(true);};consthandleClose=()=>{setIsOpen(false);setDropdownState(false);};constsetDropdownState=(isOpen: boolean)=>{constdropdownTrigger=refs.floating.current?.querySelector("button");if(!dropdownTrigger)return;constisExpanded=dropdownTrigger.getAttribute("aria-expanded")==="true";if(isExpanded!==isOpen){dropdownTrigger.click();}};// Create a click outside listener sync between the trigger's state and our isOpen.// Click outside events can cause the dropdown to fire, without us being made aware.// <Dropdown /> offers no event hooks to broadcast it's state handling this.useEffect(()=>{if(!isOpen)return;constonDocumentClick=(event: MouseEvent)=>{constreference=refs.reference.current;constfloating=refs.floating.current;if(!reference||!floating)return;if(// @ts-expect-error Meh!reference.contains(event.target)&&// @ts-expect-error Meh!floating.contains(event.target)){setIsOpen(false);}};document.addEventListener("click",onDocumentClick);return()=>{document.removeEventListener("click",onDocumentClick);};},[isOpen,refs.floating,refs.reference]);return(<><divaria-controls={id}aria-haspopup="menu"aria-expanded={isOpen}ref={refs.setReference}onClick={isOpen ? handleClose : handleOpen}data-testid="flowbite-dropdown-portal">{label}</div><FloatingPortal><divaria-expanded={isOpen}data-testid="flowbite-dropdown-portal"id={id}ref={refs.setFloating}style={floatingStyles}><Dropdownlabel={null}placement="bottom"inlinearrowIcon={false}{...props}/></div></FloatingPortal></>);};
The text was updated successfully, but these errors were encountered:
If it helps, here's the story file for reproducing:
importtype{Meta,StoryObj}from"@storybook/react";import{Dropdown}from"flowbite-react";import{PrimaryButton}from"../../Buttons";import{ViewIcon}from"../../Icons";import{DropdownPortal}from"./DropdownPortal";// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-exportconstmeta: Meta<typeofDropdownPortal>={component: DropdownPortal,// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/7.0/react/writing-docs/docs-pagetags: ["autodocs"],parameters: {// More on Story layout: https://storybook.js.org/docs/react/configure/story-layoutlayout: "centered",},// More on argTypes: https://storybook.js.org/docs/react/api/argtypesargTypes: {},args: {children: (<><Dropdown.Itemicon={ViewIcon}>A</Dropdown.Item><Dropdown.Itemicon={ViewIcon}>B</Dropdown.Item><Dropdown.Itemicon={ViewIcon}>C</Dropdown.Item><Dropdown.Itemicon={ViewIcon}>D</Dropdown.Item><Dropdown.Itemicon={ViewIcon}>F</Dropdown.Item></>),label: <PrimaryButton>Dropdown</PrimaryButton>,},};exportdefaultmeta;typeStory=StoryObj<typeofDropdownPortal>;// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-argsexportconstDefault: Story={// More on args: https://storybook.js.org/docs/react/writing-stories/argsargs: {},};exportconstOverflowXAuto: Story={args: {},render: (args)=>(<divclassName="h-8 w-40 overflow-x-auto bg-orange-500"><DropdownPortal{...args}/></div>),};
Summary
Describe how it should work, and provide examples of the solution, which might include screenshots or code snippets.
<Dropdown />
should have exposed just a few properties and I'd have not ended up double bag it.I think I'd need:
<FloatingPortal />
useBaseFloating
,useFloatingInteractions
Context
What are you trying to accomplish? How is your use case affected by not having this feature?
I've needed to implement a context menu (triple dot) as the last column in a table's row. The last row's
<Dropdown />
can have it's elements cut off by the table (or any container's) overflow, or worse cause scrolling if it's overflow-x-auto. I need a way to remove it from dom, portaling, floating etc to achieve the below:It should have been so much easier.
Here's a quick hack I'm using to get around the current implementation:
The text was updated successfully, but these errors were encountered: