Skip to content

Commit e71bfe6

Browse files
committed
support delay for 2.3.0. Fixes #7
1 parent 6cc61f0 commit e71bfe6

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# History
22
----
33

4+
### 2.3.0 / 2015-07-07
5+
6+
`new` [#7](https://github.com/react-component/tooltip/issues/7) support delay prop
7+
48
### 2.2.0 / 2015-06-30
59

610
- use mask instead of document click

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ online example: http://react-component.github.io/tooltip/examples/
6868
</tr>
6969
</thead>
7070
<tbody>
71+
<tr>
72+
<td>delay</td>
73+
<td>number</td>
74+
<td></td>
75+
<td>delay time to show or hide, only valid for hover trigger.unit: s.</td>
76+
</tr>
7177
<tr>
7278
<td>overlayStyle</td>
7379
<td>Object</td>

examples/simple.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ var Test = React.createClass({
8484
</div>
8585
<div style={{margin: 100}}>
8686
<Tooltip placement={this.state.placement}
87+
delay={0.1}
8788
renderPopupToBody={this.props.renderPopupToBody}
8889
trigger={Object.keys(this.state.trigger)}
8990
onVisibleChange={this.onVisibleChange}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-tooltip",
3-
"version": "2.2.4",
3+
"version": "2.3.0",
44
"description": "tooltip ui component for react",
55
"keywords": [
66
"react",

src/Tooltip.jsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,27 @@ class Tooltip extends React.Component {
8585
}
8686
}
8787

88-
show() {
89-
this.setVisible(true);
88+
delaySetVisible(visible, e) {
89+
var delay = this.props.delay * 1000;
90+
if (delay && e && e.type.indexOf('mouse') !== -1) {
91+
if (this.delayTimer) {
92+
clearTimeout(this.delayTimer);
93+
}
94+
this.delayTimer = setTimeout(() => {
95+
this.setVisible(visible);
96+
this.delayTimer = null;
97+
}, delay);
98+
} else {
99+
this.setVisible(visible);
100+
}
101+
}
102+
103+
show(e) {
104+
this.delaySetVisible(true, e);
90105
}
91106

92-
hide() {
93-
this.setVisible(false);
107+
hide(e) {
108+
this.delaySetVisible(false, e);
94109
}
95110

96111
componentDidMount() {
@@ -157,14 +172,16 @@ Tooltip.propTypes = {
157172
renderPopupToBody: React.PropTypes.bool,
158173
overlay: React.PropTypes.node.isRequired,
159174
overlayStyle: React.PropTypes.object,
160-
wrapStyle: React.PropTypes.object
175+
wrapStyle: React.PropTypes.object,
176+
delay: React.PropTypes.number
161177
};
162178

163179
Tooltip.defaultProps = {
164180
prefixCls: 'rc-tooltip',
165181
renderPopupToBody: true,
166182
onVisibleChange: function () {
167183
},
184+
delay: 0,
168185
overlayStyle: {},
169186
wrapStyle: {},
170187
placement: 'right',

0 commit comments

Comments
 (0)