UNPKG

4.73 kBTypeScriptView Raw
1import * as React from "react";
2import { ActionProps } from "../../common/props";
3import { PopoverProps } from "../popover/popover";
4import { MenuProps } from "./menu";
5/**
6 * Note that the HTML attributes supported by this component are spread to the nested `<a>` element, while the
7 * `ref` is attached to the root `<li>` element. This is an unfortunate quirk in the API which we keep around
8 * for backwards-compatibility.
9 */
10export interface MenuItemProps extends ActionProps<HTMLAnchorElement>, React.AnchorHTMLAttributes<HTMLAnchorElement>, React.RefAttributes<HTMLLIElement> {
11 /** Item text, required for usability. */
12 text: React.ReactNode;
13 /**
14 * Whether this item should appear _active_, often useful to
15 * indicate keyboard focus. Note that this is distinct from _selected_
16 * appearance, which has its own prop.
17 */
18 active?: boolean;
19 /**
20 * Children of this component will be rendered in a _submenu_
21 * that appears in a popover when hovering or clicking on this item.
22 *
23 * Use `text` prop for the content of the menu item itself.
24 */
25 children?: React.ReactNode;
26 /**
27 * Whether this menu item is non-interactive. Enabling this prop will ignore `href`, `tabIndex`,
28 * and mouse event handlers (in particular click, down, enter, leave).
29 */
30 disabled?: boolean;
31 /**
32 * Right-aligned label text content, useful for displaying hotkeys.
33 *
34 * This prop actually supports JSX elements, but TypeScript will throw an error because
35 * `HTMLAttributes` only allows strings. Use `labelElement` to supply a JSX element in TypeScript.
36 */
37 label?: string;
38 /**
39 * A space-delimited list of class names to pass along to the right-aligned label wrapper element.
40 */
41 labelClassName?: string;
42 /**
43 * Right-aligned label content, useful for displaying hotkeys.
44 */
45 labelElement?: React.ReactNode;
46 /**
47 * Changes the ARIA `role` property structure of this MenuItem to accomodate for various
48 * different `role`s of the parent Menu `ul` element.
49 *
50 * If `menuitem`, role structure becomes:
51 *
52 * `<li role="none"><a role="menuitem" /></li>`
53 *
54 * which is proper role structure for a `<ul role="menu"` parent (this is the default `role` of a `Menu`).
55 *
56 * If `listoption`, role structure becomes:
57 *
58 * `<li role="option"><a role={undefined} /></li>`
59 *
60 * which is proper role structure for a `<ul role="listbox"` parent, or a `<select>` parent.
61 *
62 * If `listitem`, role structure becomes:
63 *
64 * `<li role={undefined}><a role={undefined} /></li>`
65 *
66 * which can be used if this item is within a basic `<ul/>` (or `role="list"`) parent.
67 *
68 * If `none`, role structure becomes:
69 *
70 * `<li role="none"><a role={undefined} /></li>`
71 *
72 * which can be used if wrapping this item in a custom `<li>` parent.
73 *
74 * @default "menuitem"
75 */
76 roleStructure?: "menuitem" | "listoption" | "listitem" | "none";
77 /**
78 * Whether the text should be allowed to wrap to multiple lines.
79 * If `false`, text will be truncated with an ellipsis when it reaches `max-width`.
80 *
81 * @default false
82 */
83 multiline?: boolean;
84 /**
85 * Props to spread to the submenu popover. Note that `content` and `minimal` cannot be
86 * changed and `usePortal` defaults to `false` so all submenus will live in
87 * the same container.
88 */
89 popoverProps?: Partial<Omit<PopoverProps, "content" | "minimal">>;
90 /**
91 * Whether this item should appear selected.
92 * Defining this will set the `aria-selected` attribute and apply a
93 * "check" or "blank" icon on the item (unless the `icon` prop is set,
94 * which always takes precedence).
95 *
96 * @default undefined
97 */
98 selected?: boolean;
99 /**
100 * Whether an enabled item without a submenu should automatically close its parent popover when clicked.
101 *
102 * @default true
103 */
104 shouldDismissPopover?: boolean;
105 /**
106 * Props to spread to the child `Menu` component if this item has a submenu.
107 */
108 submenuProps?: Partial<MenuProps>;
109 /**
110 * Name of the HTML tag that wraps the MenuItem.
111 *
112 * @default "a"
113 */
114 tagName?: keyof JSX.IntrinsicElements;
115 /**
116 * A space-delimited list of class names to pass along to the text wrapper element.
117 */
118 textClassName?: string;
119 /**
120 * HTML title to be passed to the <Text> component
121 */
122 htmlTitle?: string;
123}
124/**
125 * Menu item component.
126 *
127 * @see https://blueprintjs.com/docs/#core/components/menu.menu-item
128 */
129export declare const MenuItem: React.FC<MenuItemProps>;