UNPKG

2.93 kBTypeScriptView Raw
1import * as React from 'react';
2import { ListAction, ListState, UseListRootSlotProps } from '../useList';
3import { MenuItemMetadata } from '../useMenuItem';
4import { MenuProviderValue } from './MenuProvider';
5export interface UseMenuParameters {
6 /**
7 * If `true` (Default) will focus the highligted item. If you set this prop to `false`
8 * the focus will not be moved inside the Menu component. This has severe accessibility implications
9 * and should only be considered if you manage focus otherwise.
10 * @default true
11 */
12 autoFocus?: boolean;
13 /**
14 * The id of the menu. If not provided, it will be generated.
15 */
16 id?: string;
17 /**
18 * If `true`, it will be possible to highlight disabled items.
19 * @default true
20 */
21 disabledItemsFocusable?: boolean;
22 /**
23 * If `true`, the highlight will not wrap around the list if arrow keys are used.
24 * @default false
25 */
26 disableListWrap?: boolean;
27 /**
28 * Callback fired when the menu items change.
29 */
30 onItemsChange?: (items: string[]) => void;
31 /**
32 * The ref to the menu's listbox node.
33 */
34 listboxRef?: React.Ref<Element>;
35 /**
36 * The name of the component using useMenu.
37 * For debugging purposes.
38 * @default 'useMenu'
39 */
40 componentName?: string;
41}
42export interface UseMenuReturnValue {
43 /**
44 * The value to be passed into the MenuProvider.
45 */
46 contextValue: MenuProviderValue;
47 /**
48 * Action dispatcher for the menu component.
49 * Allows to programmatically control the menu.
50 */
51 dispatch: (action: ListAction<string>) => void;
52 /**
53 * Resolver for the listbox slot's props.
54 * @param externalProps additional props for the listbox component
55 * @returns props that should be spread on the listbox component
56 */
57 getListboxProps: <ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseMenuListboxSlotProps;
58 /**
59 * The highlighted option in the menu listbox.
60 */
61 highlightedValue: string | null;
62 /**
63 * The ref to the menu's listbox node.
64 */
65 listboxRef: React.RefCallback<Element> | null;
66 /**
67 * Items in the menu listbox.
68 */
69 menuItems: Map<string, MenuItemMetadata>;
70 /**
71 * If `true`, the menu is open.
72 */
73 open: boolean;
74 /**
75 * An element that triggers the visibility of the menu.
76 */
77 triggerElement: HTMLElement | null;
78}
79interface UseMenuListboxSlotEventHandlers {
80 onBlur: React.FocusEventHandler;
81 onKeyDown: React.KeyboardEventHandler;
82}
83export type UseMenuListboxSlotProps<ExternalProps = {}> = UseListRootSlotProps<Omit<ExternalProps, keyof UseMenuListboxSlotEventHandlers> & UseMenuListboxSlotEventHandlers> & {
84 ref: React.RefCallback<Element> | null;
85 role: React.AriaRole;
86};
87export interface MenuInternalState extends ListState<string> {
88}
89export {};