Skip to content
Prev Previous commit
Next Next commit
Remove ad-hoc storybook example and restore close callback
  • Loading branch information
ciampo committed Sep 8, 2023
commit 17ad46e201ae91887b2870270e904f993e2e6f46
74 changes: 1 addition & 73 deletions packages/components/src/dropdown-menu/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Meta, StoryFn } from '@storybook/react';
/**
* WordPress dependencies
*/
import { useState, useId, createContext, useContext } from '@wordpress/element';
import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
Expand Down Expand Up @@ -136,75 +136,3 @@ WithChildren.args = {
</>
),
};

const OnlyOneDropdownOpenContext = createContext< {
openDropdownId?: string;
setOpenDropdownId: ( id: string | undefined ) => void;
} >( {
openDropdownId: undefined,
setOpenDropdownId: ( _instanceId ) => {},
} );

const ItemWithDropdown = () => {
const { openDropdownId, setOpenDropdownId } = useContext(
OnlyOneDropdownOpenContext
);

const instanceId = useId();

return (
<div>
Some text
<DropdownMenu
label="Open dropdown"
icon={ menu }
controls={ [
{
title: 'First Menu Item Label',
icon: arrowUp,
// eslint-disable-next-line no-console
onClick: () => console.log( 'up!' ),
},
{
title: 'Second Menu Item Label',
icon: arrowDown,
// eslint-disable-next-line no-console
onClick: () => console.log( 'down!' ),
},
] }
open={ openDropdownId === instanceId }
onToggle={ ( willOpen ) => {
if ( willOpen ) {
setOpenDropdownId( instanceId );
} else {
setOpenDropdownId( undefined );
}
} }
/>
</div>
);
};

export const OnlyOneOpened: StoryFn< typeof DropdownMenu > = () => {
const [ openDropdownId, setOpenDropdownId ] = useState<
string | undefined
>( undefined );

return (
<OnlyOneDropdownOpenContext.Provider
value={ { openDropdownId, setOpenDropdownId } }
>
<ItemWithDropdown />
<ItemWithDropdown />
<ItemWithDropdown />
<ItemWithDropdown />
<ItemWithDropdown />
<ItemWithDropdown />
<ItemWithDropdown />
<ItemWithDropdown />
<ItemWithDropdown />
<ItemWithDropdown />
<ItemWithDropdown />
</OnlyOneDropdownOpenContext.Provider>
);
};
4 changes: 1 addition & 3 deletions packages/components/src/dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ const UnconnectedDropdown = (
! containerRef.current.contains( ownerDocument.activeElement ) &&
( ! dialog || dialog.contains( containerRef.current ) )
) {
// Temporarily disable this functionality to make sure that the storybook
// example works
// close();
close();
}
}

Expand Down