diff --git a/packages/components/src/dropdown-menu/index.tsx b/packages/components/src/dropdown-menu/index.tsx index c21cfa456eb3c..805bcd0661179 100644 --- a/packages/components/src/dropdown-menu/index.tsx +++ b/packages/components/src/dropdown-menu/index.tsx @@ -14,7 +14,7 @@ import { menu } from '@wordpress/icons'; import Button from '../button'; import Dropdown from '../dropdown'; import { NavigableMenu } from '../navigable-container'; -import type { Controls, DropdownMenuProps, NormalizedControls } from './types'; +import type { DropdownMenuProps, DropdownOption } from './types'; function mergeProps< T extends { className?: string; [ key: string ]: unknown } @@ -139,7 +139,7 @@ function DropdownMenu( dropdownMenuProps: DropdownMenuProps ) { } // Normalize controls to nested array of objects (sets of controls) - let controlSets: NormalizedControls; + let controlSets: DropdownOption[][]; if ( controls?.length ) { // @ts-expect-error The check below is needed because `DropdownMenus` // rendered by `ToolBarGroup` receive controls as a nested array. @@ -147,7 +147,7 @@ function DropdownMenu( dropdownMenuProps: DropdownMenuProps ) { if ( ! Array.isArray( controlSets[ 0 ] ) ) { // This is not ideal, but at this point we know that `controls` is // not a nested array, even if TypeScript doesn't. - controlSets = [ controls as Controls ]; + controlSets = [ controls as DropdownOption[] ]; } } diff --git a/packages/components/src/dropdown-menu/types.ts b/packages/components/src/dropdown-menu/types.ts index 7b96d4a138b21..badfcb54d6072 100644 --- a/packages/components/src/dropdown-menu/types.ts +++ b/packages/components/src/dropdown-menu/types.ts @@ -11,7 +11,7 @@ import type { DropdownProps } from '../dropdown/types'; import type { Props as IconProps } from '../icon'; import type { NavigableMenuProps } from '../navigable-container/types'; -type DropdownOption = { +export type DropdownOption = { /** * The Dashicon icon slug to be shown for the option. */ @@ -44,9 +44,6 @@ type DropdownOption = { role?: HTMLElement[ 'role' ]; }; -export type Controls = DropdownOption[]; -export type NormalizedControls = DropdownOption[][]; - type DropdownCallbackProps = { isOpen: boolean; onToggle: () => void; @@ -142,5 +139,5 @@ export type DropdownMenuProps = { * * A valid DropdownMenu must specify a `controls` or `children` prop, or both. */ - controls?: Controls | NormalizedControls; + controls?: DropdownOption[] | DropdownOption[][]; };