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
{{ message }}
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
[](https://spectrum.chat/popper-js/react-popper)
9
9
10
-
React wrapper around [Popper.js](https://popper.js.org).
10
+
React wrapper around [Popper](https://popper.js.org).
11
11
12
-
**important note:** popper.js is **not** a tooltip library, it's a _positioning engine_ to be used to build features such as (but not restricted to) tooltips.
12
+
**important note:** Popper is **not** a tooltip library, it's a _positioning
13
+
engine_ to be used to build features such as (but not restricted to) tooltips.
describing the necessary CSS properties needed to properly position the two
122
+
elements.
123
+
124
+
You can directly assign the value of the two properties to the React `style`
125
+
property of your components.
126
+
127
+
```js
128
+
<div style={styles.popper} />
129
+
```
130
+
131
+
##### `attributes`
64
132
65
-
> Using React <=15 or Preact? The components created with them don't support to return
66
-
> [fragments](https://reactjs.org/docs/fragments.html), this means that you will need to
67
-
> wrap `<Reference />` and `<Popper />` into a single, common, `<div />` to make `react-popper` work.
133
+
Similar to `styles`, the `attributes` object lists the `popper` and `arrow` HTML
134
+
attributes, by default, only `popper` will hold some attributes (e.g.
135
+
`data-popper-placement`), but more generically, any HTML attribute described by
136
+
the Popper documentation will be available inside these properties.
68
137
69
-
### API documentation
138
+
The easiest way to consume their values is by destructuring them directly onto
139
+
your React component.
70
140
71
-
The `Manager` component is a simple wrapper that needs to surround all the other `react-popper` components in order
72
-
to make them communicate with each others.
141
+
```js
142
+
<div {...attributes.popper} />
143
+
```
144
+
145
+
##### `update`, `forceUpdate`, and `state`
146
+
147
+
These properties match the ones described in the
148
+
[Popper docs](https://popper.js.org/docs/v2/constructors/#types), the only
149
+
difference is that they can be `null` if Popper isn't yet been initialized or
150
+
has been destroyed.
73
151
74
-
The `Popper` component accepts the properties `children`, `placement`, `modifiers` and `strategy`.
152
+
### Render Props
153
+
154
+
The `Manager` component is a simple wrapper that needs to surround all the other
155
+
`react-popper` components in order to make them communicate with each others.
156
+
157
+
The `Popper` component accepts the properties `children`, `placement`,
158
+
`modifiers` and `strategy`.
75
159
76
160
```jsx
77
161
<Popper
@@ -102,19 +186,36 @@ children: ({|
102
186
|}) =>Node
103
187
```
104
188
105
-
A function (render prop) that takes as argument an object containing the following properties:
106
-
107
-
- **`ref`**: used to retrieve the [React refs](https://reactjs.org/docs/refs-and-the-dom.html) of the **popper** element.
108
-
- **`style`**: contains the necessary CSS styles (React CSS properties) which are computed by Popper.js to correctly position the **popper** element.
109
-
- **`placement`**: describes the placement of your popper after Popper.js has applied all the modifiers
110
-
that may have flipped or altered the originally provided `placement` property. You can use this to alter the
111
-
style of the popper and or of the arrow according to the definitive placement. For instance, you can use this
112
-
property to orient the arrow to the right direction.
113
-
- **`isReferenceHidden`**: a boolean signifying the reference element is fully clipped and hidden from view.
114
-
- **`hasPopperEscaped`**: a boolean signifying the popper escapes the reference element's boundary (and so it appears detached).
115
-
- **`update`**: a function you can ask Popper to recompute your tooltip's position . It will directly call the [Popper#update](https://popper.js.org/docs/v2/lifecycle/#manual-update) method.
116
-
- **`arrowProps`**: an object, containing `style` and `ref` properties that are identical to the
117
-
ones provided as the first and second arguments of `children`, but relative to the **arrow** element. The `style` property contains `left` and `top` offset values, which are used to center the arrow within the popper. These values can be merged with further custom styling and positioning. See [the demo](https://github.com/FezVrasta/react-popper/blob/8994933c430e48ab62e71495be71e4f440b48a5a/demo/styles.js#L100) for an example.
189
+
A function (render prop) that takes as argument an object containing the
190
+
following properties:
191
+
192
+
- **`ref`**: used to retrieve the
193
+
[React refs](https://reactjs.org/docs/refs-and-the-dom.html) of the **popper**
194
+
element.
195
+
- **`style`**: contains the necessary CSS styles (React CSS properties) which
196
+
are computed by Popper.js to correctly position the **popper** element.
197
+
- **`placement`**: describes the placement of your popper after Popper.js has
198
+
applied all the modifiers that may have flipped or altered the originally
199
+
provided `placement` property. You can use this to alter the style of the
200
+
popper and or of the arrow according to the definitive placement. For
201
+
instance, you can use this property to orient the arrow to the right
202
+
direction.
203
+
- **`isReferenceHidden`**: a boolean signifying the reference element is fully
204
+
clipped and hidden from view.
205
+
- **`hasPopperEscaped`**: a boolean signifying the popper escapes the reference
206
+
element's boundary (and so it appears detached).
207
+
- **`update`**: a function you can ask Popper to recompute your tooltip's
Your popper is going to be placed according to the value of this property.
135
237
Defaults to `bottom`.
136
238
137
239
##### `strategy`
138
240
139
-
Describes the positioning strategy to use. By default, it is `absolute`, which in the simplest cases does not require repositioning of the popper. If your reference element is in a `fixed` container, use the `fixed` strategy. [Read More](https://popper.js.org/docs/v2/constructors/#strategy)
241
+
Describes the positioning strategy to use. By default, it is `absolute`, which
242
+
in the simplest cases does not require repositioning of the popper. If your
243
+
reference element is in a `fixed` container, use the `fixed` strategy.
Whenever you need to position a popper based on some arbitrary coordinates, you can provide `Popper` with a `referenceElement` property that is going to be used in place of the `referenceProps.getRef` React ref.
298
+
Whenever you need to position a popper based on some arbitrary coordinates, you
299
+
can provide `Popper` with a `referenceElement` property that is going to be used
300
+
in place of the `referenceProps.getRef` React ref.
190
301
191
-
The `referenceElement` property must be an object with an interface compatible with an `HTMLElement` as described in the [Popper.js virtualElement documentation](https://popper.js.org/docs/v2/virtual-elements/), this implies that you may also provide a real HTMLElement if needed.
302
+
The `referenceElement` property must be an object with an interface compatible
0 commit comments