Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit d262808

Browse files
author
Federico Zivolo
committed
feat: Added outOfBoundaries support
1 parent 438b64c commit d262808

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

.flowconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[ignore]
22
.*/node_modules/config-chain/.*
33
/lib/.*
4+
.*/.cache
45

56
[include]
67

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ children: ({|
8383
ref: (?HTMLElement) => void,
8484
style: { [string]: string | number },
8585
placement: ?Placement,
86+
outOfBoundaries: ?boolean,
8687
scheduleUpdate: () => void,
8788
arrowProps: {
8889
ref: (?HTMLElement) => void,
@@ -121,6 +122,13 @@ One of the accepted placement values listed in the [Popper.js documentation](htt
121122
Your popper is going to be placed according to the value of this property.
122123
Defaults to `bottom`.
123124
125+
```js
126+
outOfBoundaries: ?boolean;
127+
```
128+
129+
A boolean that can be used to hide the popper element in case it's overflowing
130+
from its boundaries. [Read more](https://popper.js.org/popper-documentation.html#modifiers..hide).
131+
124132
##### `eventsEnabled`
125133
126134
```js

src/Popper.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type RenderProp = ({|
1919
ref: getRefFn,
2020
style: Style,
2121
placement: ?Placement,
22+
outOfBoundaries: ?boolean,
2223
scheduleUpdate: () => void,
2324
arrowProps: {
2425
ref: getRefFn,
@@ -110,6 +111,9 @@ export class InnerPopper extends Component<PopperProps, PopperState> {
110111
? initialArrowStyle
111112
: this.state.data.arrowStyles;
112113

114+
getOutOfBoundariesState = () =>
115+
this.state.data ? this.state.data.hide : undefined;
116+
113117
initPopperInstance = () => {
114118
const { referenceElement } = this.props;
115119
const { popperNode, popperInstance } = this.state;
@@ -175,6 +179,7 @@ export class InnerPopper extends Component<PopperProps, PopperState> {
175179
ref: this.setPopperNode,
176180
style: this.getPopperStyle(),
177181
placement: this.getPopperPlacement(),
182+
outOfBoundaries: this.getOutOfBoundariesState(),
178183
scheduleUpdate: this.scheduleUpdate,
179184
arrowProps: {
180185
ref: this.setArrowNode,

typings/react-popper.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface PopperProps {
2222
ref: (ref: HTMLElement | null) => void,
2323
style: React.CSSProperties,
2424
placement: ?PopperJS.Placement,
25+
outOfBoundaries: boolean | null,
2526
scheduleUpdate: () => void,
2627
arrowProps: {
2728
ref: (ref: HTMLElement | null) => void,

typings/tests/main-test.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ const Test = () => (
99
positionFixed
1010
modifiers={{ flip: { enabled: false } }}
1111
>
12-
{({ ref, style, placement, scheduleUpdate, arrowProps }) => (
12+
{({
13+
ref,
14+
style,
15+
placement,
16+
outOfBoundaries,
17+
scheduleUpdate,
18+
arrowProps,
19+
}) => (
1320
<div
1421
ref={ref}
15-
style={style}
22+
style={{ ...style, opacity: outOfBoundaries ? 0 : 1 }}
1623
data-placement={placement}
1724
onClick={() => scheduleUpdate()}
1825
>

0 commit comments

Comments
 (0)