@react-md/menu
Version:
Create menus that auto-position themselves within the viewport and adhere to the accessibility guidelines
61 lines (60 loc) • 2.35 kB
TypeScript
import React, { CSSProperties } from "react";
import { RenderConditionalPortalProps } from "@react-md/portal";
import { MenuItemRenderer, ValidMenuItem } from "./defaultMenuItemRenderer";
import { MenuPositionProps, MenuRenderer } from "./defaultMenuRenderer";
import { MenuButtonProps } from "./MenuButton";
export interface BaseDropdownMenuProps extends MenuPositionProps, RenderConditionalPortalProps {
/**
* The id to use for the menu button and used to create the id for the menu.
* The menu's id will just be `${id}-menu`.
*/
id: string;
/**
* The label to use for the menu. Either this or the `menuLabelledBy` props
* are required for a11y.
*/
menuLabel?: string;
/**
* The id for an element to label the menu. Either this or the `menuLabel`
* props are required for a11y. This will be defaulted to the `id` of the menu
* button for convenience since it _should_ normally label the menu but should
* be changed if it does not.
*/
menuLabelledBy?: string;
/**
* An optional style object to pass to the `menuRenderer`/`Menu` component.
*/
menuStyle?: CSSProperties;
/**
* An optional className to pass to the `menuRenderer`/`Menu` component.
*/
menuClassName?: string;
/**
* A custom menu renderer to use. This defaults to just rendering the `Menu`
* component with the base required props and a generated id from the button
* id.
*/
menuRenderer?: MenuRenderer;
/**
* A list of menu items to render. Each item will be passed to the
* `menuItemRenderer` function.
*/
items: ValidMenuItem[];
/**
* A function to call for each `item` in the `items` list to render a
* ReactElement.
*/
itemRenderer?: MenuItemRenderer;
/**
* Boolean if the menu should be visible immediately once this component
* mounts.
*/
defaultVisible?: boolean;
/**
* An optional function to call when the visibility of the menu changes.
*/
onVisibilityChange?: (visible: boolean) => void;
}
export interface DropdownMenuProps extends Omit<MenuButtonProps, "id" | "visible" | "aria-haspopup">, BaseDropdownMenuProps {
}
export declare const DropdownMenu: React.ForwardRefExoticComponent<DropdownMenuProps & React.RefAttributes<HTMLButtonElement>>;