Skip to content

Commit

Permalink
support delay for 2.3.0. Fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed Jul 7, 2015
1 parent 6cc61f0 commit e71bfe6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# History
----

### 2.3.0 / 2015-07-07

`new` [#7](https://github.com/react-component/tooltip/issues/7) support delay prop

### 2.2.0 / 2015-06-30

- use mask instead of document click
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ online example: http://react-component.github.io/tooltip/examples/
</tr>
</thead>
<tbody>
<tr>
<td>delay</td>
<td>number</td>
<td></td>
<td>delay time to show or hide, only valid for hover trigger.unit: s.</td>
</tr>
<tr>
<td>overlayStyle</td>
<td>Object</td>
Expand Down
1 change: 1 addition & 0 deletions examples/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var Test = React.createClass({
</div>
<div style={{margin: 100}}>
<Tooltip placement={this.state.placement}
delay={0.1}
renderPopupToBody={this.props.renderPopupToBody}
trigger={Object.keys(this.state.trigger)}
onVisibleChange={this.onVisibleChange}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-tooltip",
"version": "2.2.4",
"version": "2.3.0",
"description": "tooltip ui component for react",
"keywords": [
"react",
Expand Down
27 changes: 22 additions & 5 deletions src/Tooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,27 @@ class Tooltip extends React.Component {
}
}

show() {
this.setVisible(true);
delaySetVisible(visible, e) {
var delay = this.props.delay * 1000;
if (delay && e && e.type.indexOf('mouse') !== -1) {
if (this.delayTimer) {
clearTimeout(this.delayTimer);
}
this.delayTimer = setTimeout(() => {
this.setVisible(visible);
this.delayTimer = null;
}, delay);
} else {
this.setVisible(visible);
}
}

show(e) {
this.delaySetVisible(true, e);
}

hide() {
this.setVisible(false);
hide(e) {
this.delaySetVisible(false, e);
}

componentDidMount() {
Expand Down Expand Up @@ -157,14 +172,16 @@ Tooltip.propTypes = {
renderPopupToBody: React.PropTypes.bool,
overlay: React.PropTypes.node.isRequired,
overlayStyle: React.PropTypes.object,
wrapStyle: React.PropTypes.object
wrapStyle: React.PropTypes.object,
delay: React.PropTypes.number
};

Tooltip.defaultProps = {
prefixCls: 'rc-tooltip',
renderPopupToBody: true,
onVisibleChange: function () {
},
delay: 0,
overlayStyle: {},
wrapStyle: {},
placement: 'right',
Expand Down

0 comments on commit e71bfe6

Please sign in to comment.