Debian Codegraph @

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

raw
1 ---
2 id: Popover
3 section: components
4 cssPrefix: pf-v6-c-popover
5 propComponents: ['Popover']
6 ---
7
8 import { useRef, useState } from 'react';
9 import RhUiNotificationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-notification-fill-icon';
10 import RhUiInformationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-information-fill-icon';
11 import RhUiCheckCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-check-circle-fill-icon';
12 import RhUiWarningFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-warning-fill-icon';
13 import RhUiErrorFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-error-fill-icon';
14 import RhUiAttentionBellFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-attention-bell-fill-icon';
15
16 ## Examples
17
18 By default, the `appendTo` prop of the popover will append to the document body in order to avoid the popover content not being fully visible. Another option is to increase the z-index of the element the popover is appended to to be higher than the z-index of the element that is hiding the popover.
19
20 ### Basic
21
22 ```ts file="./PopoverBasic.tsx"
23
24 ```
25
26 ### Hoverable
27
28 Pass the `triggerAction="hover"` property to make a `<Popover>` that is triggered via hover and focus rather than on click. When using a hoverable Popover, you **must not** include any interactive or semantic content (e.g. buttons, links, headings, lists, etc), as focus is not intended to enter a hoverable `<Popover>`. Including such content may cause an inaccessible UI for users who are not able to reach the content when navigating via assistive tech.
29
30 It is instead recommended to use our [tooltip component](/components/tooltip).
31
32 ```ts isDeprecated file="./PopoverHover.tsx"
33
34 ```
35
36 ### Close popover from content (controlled)
37
38 ```ts file="./PopoverCloseControlled.tsx"
39
40 ```
41
42 ### Close popover from content (uncontrolled)
43
44 Note: If you use the isVisible prop, either refer to the example above or if you want to use the hide callback from the content then be sure to keep isVisible in-sync.
45
46 ```ts file="./PopoverCloseUncontrolled.tsx"
47
48 ```
49
50 ### Without header/footer/close and no padding
51
52 ```ts file="./PopoverWithoutHeaderFooterCloseNoPadding.tsx"
53
54 ```
55
56 ### Width auto
57
58 Here the popover goes over the navigation, so the prop `appendTo` is set to the documents body.
59
60 ```ts file="./PopoverWidthAuto.tsx"
61
62 ```
63
64 ### Popover react ref
65
66 ```ts file="./PopoverReactRef.tsx"
67
68 ```
69
70 ### Popover selector ref
71
72 ```ts file="./PopoverSelectorRef.tsx"
73
74 ```
75
76 ### Advanced
77
78 ```ts file="./PopoverAdvanced.tsx"
79
80 ```
81
82 ### Popover with icon in the title
83
84 Here the popover goes over the navigation, so the prop `appendTo` is set to the documents body.
85
86 ```ts file="./PopoverWithIconInTheTitle.tsx"
87
88 ```
89
90 ### Alert popover
91
92 Here the popover goes over the navigation, so the prop `appendTo` is set to the documents body.
93
94 ```ts file="./PopoverAlert.tsx"
95
96 ```
97
98 ### Custom focus
99
100 Use the `elementToFocus` property to customize which element inside the Popover receives focus when opened.
101
102 ```ts file="./PopoverCustomFocus.tsx"
103
104 ```