UNPKG

2.35 kBTypeScriptView Raw
1import * as React from 'react';
2import { ListAction, ListState, UseListRootSlotProps } from '../useList';
3import { MenuItemMetadata } from '../useMenuItem';
4import { EventHandlers } from '../utils/types';
5import { MenuProviderValue } from './MenuProvider';
6export interface UseMenuParameters {
7 /**
8 * If `true`, the menu will be initially open.
9 * @default false
10 */
11 defaultOpen?: boolean;
12 /**
13 * If `true`, the menu will be open.
14 * This is the controlled equivalent of the `defaultOpen` parameter.
15 */
16 open?: boolean;
17 /**
18 * Callback fired when the menu is opened or closed.
19 */
20 onOpenChange?: (open: boolean) => void;
21 /**
22 * Id of the menu listbox.
23 */
24 listboxId?: string;
25 /**
26 * Ref of the menu listbox.
27 */
28 listboxRef?: React.Ref<Element>;
29}
30export interface UseMenuReturnValue {
31 /**
32 * The value to be passed into the MenuProvider.
33 */
34 contextValue: MenuProviderValue;
35 /**
36 * Action dispatcher for the menu component.
37 * Allows to programmatically control the menu.
38 */
39 dispatch: (action: ListAction<string>) => void;
40 /**
41 * Resolver for the listbox component's props.
42 * @param otherHandlers event handlers for the listbox component
43 * @returns props that should be spread on the listbox component
44 */
45 getListboxProps: <TOther extends EventHandlers>(otherHandlers?: TOther) => UseMenuListboxSlotProps;
46 /**
47 * The highlighted option in the menu listbox.
48 */
49 highlightedValue: string | null;
50 /**
51 * The ref to the listbox DOM node.
52 */
53 listboxRef: React.RefCallback<Element> | null;
54 /**
55 * Items in the menu listbox.
56 */
57 menuItems: Map<string, MenuItemMetadata>;
58 /**
59 * If `true`, the menu is open.
60 */
61 open: boolean;
62}
63interface UseMenuListboxSlotEventHandlers {
64 onBlur: React.FocusEventHandler;
65 onKeyDown: React.KeyboardEventHandler;
66}
67export type UseMenuListboxSlotProps<TOther = {}> = UseListRootSlotProps<Omit<TOther, keyof UseMenuListboxSlotEventHandlers> & UseMenuListboxSlotEventHandlers> & {
68 ref: React.RefCallback<Element> | null;
69 role: React.AriaRole;
70};
71export interface MenuInternalState extends ListState<string> {
72 /**
73 * If `true`, the menu is open.
74 */
75 open: boolean;
76}
77export {};