Skip to content

Commit 2247cd3

Browse files
committed
Only display content when showing popover in react
1 parent 340d93c commit 2247cd3

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

dist/index.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4015,6 +4015,10 @@ var Popover = function (_Component) {
40154015

40164016
var _this = _possibleConstructorReturn(this, (Popover.__proto__ || Object.getPrototypeOf(Popover)).call(this, props));
40174017

4018+
_this.state = {
4019+
popoverOpen: _this.props.open
4020+
};
4021+
40184022
_this.update = _this.update.bind(_this);
40194023
return _this;
40204024
}
@@ -4026,7 +4030,6 @@ var Popover = function (_Component) {
40264030
this.open = false;
40274031
this.targetNode = (0, _reactDom.findDOMNode)(this);
40284032
this.createPopover();
4029-
this.update();
40304033
}
40314034
}, {
40324035
key: 'componentDidUpdate',
@@ -4039,12 +4042,30 @@ var Popover = function (_Component) {
40394042
this.mounted = false;
40404043
this.destroy();
40414044
}
4045+
}, {
4046+
key: 'onHideEvent',
4047+
value: function onHideEvent() {
4048+
this.setState({ popoverOpen: false });
4049+
4050+
if (this.props.popoverOptions.onHideEvent) {
4051+
this.props.popoverOptions.onHideEvent();
4052+
}
4053+
}
4054+
}, {
4055+
key: 'onShowEvent',
4056+
value: function onShowEvent() {
4057+
this.setState({ popoverOpen: true });
4058+
4059+
if (this.props.popoverOptions.onShowEvent) {
4060+
this.props.popoverOptions.onShowEvent();
4061+
}
4062+
}
40424063
}, {
40434064
key: 'update',
40444065
value: function update() {
40454066
var _this2 = this;
40464067

4047-
if (this.mounted && this.popoverjs) {
4068+
if (this.mounted && this.popoverjs && this.state.popoverOpen) {
40484069
(0, _reactDom.unstable_renderSubtreeIntoContainer)(this, this.popoverChildNode, this.popoverContentElement, function () {
40494070
_this2.updatePopover();
40504071
});
@@ -4110,7 +4131,10 @@ var Popover = function (_Component) {
41104131
attachmentElement: this.attachmentElement,
41114132
triggerElement: this.attachmentElement,
41124133
popoverElement: this.popoverElement
4113-
}, this.props.popoverOptions, this.props.options);
4134+
}, this.props.popoverOptions, this.props.options, {
4135+
onHideEvent: this.onHideEvent.bind(this),
4136+
onShowEvent: this.onShowEvent.bind(this)
4137+
});
41144138

41154139
if (this.props.themeClass) {
41164140
var themeClass = this.props.themeClass;

src/react/index.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export default class Popover extends Component {
3232
constructor(props) {
3333
super(props);
3434

35+
this.state = {
36+
popoverOpen: this.props.open,
37+
};
38+
3539
this.update = this.update.bind(this);
3640
}
3741

@@ -40,7 +44,6 @@ export default class Popover extends Component {
4044
this.open = false;
4145
this.targetNode = findDOMNode(this);
4246
this.createPopover();
43-
this.update();
4447
}
4548

4649
componentDidUpdate() {
@@ -52,13 +55,31 @@ export default class Popover extends Component {
5255
this.destroy();
5356
}
5457

58+
onHideEvent() {
59+
this.setState({ popoverOpen: false });
60+
61+
if (this.props.popoverOptions.onHideEvent) {
62+
this.props.popoverOptions.onHideEvent();
63+
}
64+
}
65+
66+
onShowEvent() {
67+
this.setState({ popoverOpen: true });
68+
69+
if (this.props.popoverOptions.onShowEvent) {
70+
this.props.popoverOptions.onShowEvent();
71+
}
72+
}
73+
5574
get popoverOptions() {
5675
const options = {
5776
attachmentElement: this.attachmentElement,
5877
triggerElement: this.attachmentElement,
5978
popoverElement: this.popoverElement,
6079
...this.props.popoverOptions,
6180
...this.props.options,
81+
onHideEvent: this.onHideEvent.bind(this),
82+
onShowEvent: this.onShowEvent.bind(this),
6283
};
6384

6485
if (this.props.themeClass) {
@@ -105,7 +126,7 @@ export default class Popover extends Component {
105126
}
106127

107128
update() {
108-
if (this.mounted && this.popoverjs) {
129+
if (this.mounted && this.popoverjs && this.state.popoverOpen) {
109130
renderSubtreeIntoContainer(this, this.popoverChildNode, this.popoverContentElement, () => {
110131
this.updatePopover();
111132
});

0 commit comments

Comments
 (0)