You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Starts menu content edits.
* Content updates and rewording.
* Update packages/react-core/src/components/Menu/examples/Menu.md
Co-authored-by: Eric Olkowski <70952936+thatblindgeye@users.noreply.github.com>
* Adds submenu context and makes a few edits.
* Adds content to with drilldown breadcumbs example and reorganizes.
* Adds danger item content and adds in missing back ticks.
* Content edits.
Co-authored-by: Eric Olkowski <70952936+thatblindgeye@users.noreply.github.com>
Co-authored-by: Nicole Thoen <nthoen@redhat.com>
Copy file name to clipboardExpand all lines: packages/react-core/src/components/Menu/examples/Menu.md
+96-37Lines changed: 96 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,114 +18,173 @@ import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-ico
18
18
19
19
## Examples
20
20
21
-
### Basic
21
+
### Basic menus
22
+
23
+
A menu may contain multiple variations of `<MenuItem>` components. The following example shows a few different states of menu items, where they may:
24
+
25
+
- Use the `itemId` property to link to callbacks. In this example, the `onSelect` property logs information to the console when a menu item is selected. In practice, specific actions can be linked to `onSelect` callbacks.
26
+
- Use the `to` property to direct users to other resources or webpages after selecting a menu item, and the `onClick` property to pass in a callback for specific menu items.
27
+
- Use the `isDisabled` property to disable a menu item.
28
+
- Use the `isPlain` property to remove the outer box shadow and style the menu plainly instead.
22
29
23
30
```ts file="MenuBasic.tsx"
24
31
```
25
32
26
33
### Danger menu item
27
34
35
+
To indicate that a `<MenuItem>` is connected to a potentially destructive action, use the `isDanger` property. The "Delete" item in the following example demonstrates how danger items look.
36
+
28
37
```ts file="MenuDangerMenuItem.tsx"
29
38
```
30
39
31
40
### With icons
32
41
42
+
Use the `icon` property to add a familiar icon before a `<MenuItem>` to accelerate text label recognition.
43
+
33
44
```ts file="MenuWithIcons.tsx"
34
45
```
35
46
36
-
### With checkbox
47
+
### With actions
48
+
49
+
To connect a menu item to an action icon, add a `<MenuItemAction>` to a `<MenuItem>`, and use the `icon` property to load an easily recognizable icon.
37
50
38
-
```ts file="./MenuWithCheckbox.tsx"
39
-
```
51
+
To trigger an action when any menu action icon is selected, pass a callback to the `onActionClick` property of the `<Menu>`. The following example logs to the console any time any action icon is selected.
40
52
41
-
### Filtering with search input
53
+
To trigger an action when a specific item's action icon is selected, pass in the `onClick` property to that `<MenuItemAction>`. The following example logs "clicked on code icon" to the console when the "code" icon is selected.
42
54
43
-
```ts file="MenuFilteringWithSearchInput.tsx"
55
+
```ts file="MenuWithActions.tsx"
44
56
```
45
57
46
58
### With links
47
59
60
+
Use the `to` property to add a link to a `<MenuItem>` that directs users to a new page when the item is selected. Use the `isExternalLink` property when linking to external resources. This will annotate a menu item link with an external link icon when they navigate to the link or hover over it.
61
+
48
62
```ts file="MenuWithLinks.tsx"
49
63
```
50
64
51
-
### With separator(s)
65
+
### With descriptions
52
66
53
-
```ts file="MenuWithSeparators.tsx"
67
+
Use the `description` property to add short descriptive text below any menu item that needs additional context.
68
+
69
+
```ts file="MenuWithDescription.tsx"
54
70
```
55
71
56
-
### With titled groups
72
+
### Item checkbox
57
73
58
-
```ts file="MenuWithTitledGroups.tsx"
74
+
Use the `hasCheck` property to add a checkbox to a `<MenuItem>`. Use the `isSelected` property to indicate when a `<MenuItem>` is selected.
75
+
76
+
```ts file="./MenuWithCheckbox.tsx" isBeta
59
77
```
60
78
61
-
### With description
79
+
### Menu footer
62
80
63
-
```ts file="MenuWithDescription.tsx"
81
+
Add a `<MenuFooter>` that contains separate, but related actions at the bottom of a menu.
82
+
83
+
```ts file="MenuWithFooter.tsx"
64
84
```
65
85
66
-
### With actions
86
+
### Separated items
67
87
68
-
```ts file="MenuWithActions.tsx"
88
+
Use a [divider](/components/divider) to visually separate `<MenuContent>`. Use the `component` property to specify the type of divider component to use.
89
+
90
+
```ts file="MenuWithSeparators.tsx"
91
+
```
92
+
93
+
### Titled groups of items
94
+
95
+
Add a `<MenuGroup>` to organize `<MenuContent>` and use the `label` property to title a group of menu items. Use the `labelHeadingLevel` property to assign a heading level to the menu group label.
96
+
97
+
```ts file="MenuWithTitledGroups.tsx"
69
98
```
70
99
71
100
### With favorites
72
101
102
+
The following menu example allows users to favorite menu items, an action that duplicates a menu item and places it in a separate group at the top of the menu. The `isFavorited` property identifies items that a user has favorited.
103
+
73
104
```ts file="MenuWithFavorites.tsx"
74
105
```
75
106
76
-
### Option single select
107
+
### Filtering with search input
108
+
109
+
A [search input](/components/search-input) component can be placed within `<MenuInput>` to render a search input at the top of the menu. In the following example, the `onChange` property of the text input is passed a callback that filters menu items as a user types.
110
+
111
+
```ts file="MenuFilteringWithSearchInput.tsx"
112
+
```
113
+
114
+
### Option single select menu
115
+
116
+
The following example demonstrates a single option select menu that persists a selected menu item. Use the `selected` property on the `<Menu>` to label a selected item with a checkmark. You can also use the `isSelected` property on a `<MenuItem>` to indicate that it is selected.
77
117
78
118
```ts file="MenuOptionSingleSelect.tsx"
79
119
```
80
120
81
-
### Option multi select
121
+
### Option multi select menu
122
+
123
+
To persist multiple selections that a user makes, use a multiple option select menu. To enable multi select, pass an array containing each selected `itemId` to the `selected` property.
82
124
83
125
```ts file="MenuOptionMultiSelect.tsx"
84
126
```
85
127
86
-
### With drilldown
128
+
### Scrollable menus
87
129
88
-
```ts file="./MenuWithDrilldown.tsx" isBeta
130
+
Use the `isScrollable` property to make a long `<Menu>` scrollable and visually condensed.
131
+
132
+
```ts file="MenuScrollable.tsx"
89
133
```
90
134
91
-
### With drilldown - initial drill in state
135
+
### Scrollable menu with custom height
92
136
93
-
To render an initially drilled in menu, the `menuDrilledIn`, `drilldownPath`, and `activeMenu` states must be set to an initial state. The `menuHeights` state must also be set, defining the height of the root menu. The `setHeight` function passed into the `onGetMenuHeight` property must also account for updating heights, other than the root menu, as menus drill in and out of view.
137
+
Adjust the visual size of a scrollable menu by using the `menuHeight` property within `<MenuContent>`. This example adjusts the height to 200px.
If you want to initially render only a certain number of menu items within a large menu, you can add a "view more" menu item with a callback passed into its `onClick` property that will render additional menu items.
102
145
103
-
### With drilldown breadcrumbs
146
+
In this example, 3 additional menu items are revealed each time the "view more" option is selected, with a loading icon simulating a network call to fetch more items. After all items are visible, the "view more" link disappears.
Use a drilldown menu to contain different levels of menu items. When a parent menu item (an item that has a submenu of children) is selected, the menu is replaced with the children items.
112
154
113
-
### Scrollable
155
+
- To indicate that a menu contains a drilldown, use the `containsDrilldown` property.
156
+
- To indicate the path of drilled-in menu item ids, use the `drilldownItemPath` property.
157
+
- Pass in an array of drilled-in menus with the `drilledInMenus` property.
158
+
- Use the `onDrillIn` and `onDrillOut` properties to contain callbacks for drilling into and drilling out of a submenu, respectively.
159
+
- To account for updated heights as menus drill in and out of use, use the `onGetMenuHeight` property. When starting from a drilled-in state, the `onGetMenuHeight` property must define the height of the root menu.
114
160
115
-
```ts file="MenuScrollable.tsx"
161
+
```ts file="./MenuWithDrilldown.tsx" isBeta
116
162
```
117
163
118
-
### Scrollable with custom menu height
164
+
### Initially drilled-in menu
119
165
120
-
```ts file="MenuScrollableCustomMenuHeight.tsx"
166
+
To render an initially drilled-in menu, the `drilldownItemPath`, `drilledInMenus`, and `activeMenu` properties must be set to default values.
For added flexibility with large menus, you may create a menu by passing a function to `drilldownMenu`. This approach allows you to create menu items dynamically, rather than creating everything up front.
Use [breadcrumbs](/components/breadcrumb) when a drilldown menu has more than 2 levels to offer users better navigation.
181
+
182
+
To control the height of a menu, use the `maxMenuHeight` property. Selecting the "Set max menu height" checkbox in the following example sets the menu height to "100px" and makes the menu scrollable.
0 commit comments