Debian Codegraph @

node/@patternfly/react-core/src/components/Dropdown/examples/Dropdown.md

raw
1 ---
2 id: Dropdown
3 section: components
4 subsection: menus
5 cssPrefix: pf-v6-c-menu
6 propComponents:
7 [
8 'Dropdown',
9 'DropdownGroup',
10 'DropdownItem',
11 'DropdownList',
12 'MenuToggle',
13 'DropdownToggleProps',
14 'TooltipProps',
15 'PopperOptions'
16 ]
17 ---
18
19 import { useState, useRef } from 'react';
20 import RhUiEllipsisVerticalFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-ellipsis-vertical-fill-icon';
21
22 ## Examples
23
24 `Dropdown` builds off of the Menu component suite to wrap commonly used properties and functions for a dropdown menu. See the [Menu documentation](/components/menus/menu) for a full list of properties that may be passed through `Dropdown` to further customize the dropdown menu, or the [custom menu examples](/components/menus/custom-menus) for additional examples of fully functional menus.
25
26 ### Basic dropdowns
27
28 Basic dropdowns present users with a menu of items upon clicking a dropdown toggle.
29
30 A `<Dropdown>` uses a [menu toggle](/components/menus/menu-toggle), which is passed to the `toggle` property, as well as a `<DropdownList>` with multiple `<DropdownItem>` components. To allow a dropdown to change the open state of the menu, pass the `isOpen` property into the `onOpenChange` callback.
31
32 The following example shows a few different states of dropdown items. As shown in this example, dropdown items may:
33
34 - Use the `isDisabled` property to disable an item.
35 - Use the `onClick` property to trigger a callback for an action.
36
37 This example also uses a `<Divider>` which passes in `key=”separator”` to split the menu into 2 sections with a horizontal line.
38
39 ```ts file="./DropdownBasic.tsx"
40
41 ```
42
43 ### With kebab toggle
44
45 To style a dropdown menu's toggle with a kebab icon, pass a "plain" `<MenuToggle>` to the `toggle` property. When there isn't enough space for a labeled button, a kebab icon can be used to toggle the dropdown menu open or closed.
46
47 ```ts file="./DropdownWithKebabToggle.tsx"
48
49 ```
50
51 ### With groups of items
52
53 To group sets of related dropdown items together, use a `<DropdownGroup>`. When more than 1 `<DropdownGroup>` is created in a menu, use the `label` and `labelHeadingLevel` properties to assign a name and heading level to each group.
54
55 ```ts file="./DropdownWithGroups.tsx"
56
57 ```
58
59 ### With item descriptions
60
61 To provide users with more context about a `<DropdownItem>`, pass a short message to `description` property. As shown in the example below, an item's description will appear below its label.
62
63 ```ts file="./DropdownWithDescriptions.tsx"
64
65 ```
66
67 ### Split toggle with checkbox
68
69 To combine a checkbox or other control with a dropdown menu, use a split button.
70
71 A `<MenuToggle>` can be rendered as a split button via `splitButtonItems`. Elements to be displayed before the dropdown toggle button (like the `<MenuToggleCheckbox>`) must be included in the `splitButtonItems`.
72
73 If the dropdown menu closes upon selection, you will need to manually shift focus back to the toggle element after a user selects an item from the menu.
74
75 ```ts file="./DropdownWithSplit.tsx"
76
77 ```