Skip to content

Commit 9dabefd

Browse files
committed
Create scroll hide option
1 parent edf3645 commit 9dabefd

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class | data-class | String | | extra custom class, can use !important to
6666
afterShow | null | Func | () => {} | Function that will be called after tooltip show
6767
afterHide | null | Func | () => {} | Function that will be called after tooltip hide
6868
disable | data-tip-disable | Bool | true, false | Disable the tooltip behaviour, default is false
69+
scrollHide | data-scroll-hide | Bool | true, false | Hide the tooltip when scrolling, default is true
6970

7071
## Using react component as tooltip
7172
Check the example [React-tooltip Test](http://wwayne.com/react-tooltip)

example/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const Test = React.createClass({
150150
<div className="example-jsx">
151151
<div className="side">
152152
<a data-for='custom-event' data-tip='custom show' data-event='click focus'>( •̀д•́)</a>
153-
<ReactTooltip id='custom-event' globalEventOff='click'/>
153+
<ReactTooltip id='custom-event' globalEventOff='click' />
154154
</div>
155155
<div className="side">
156156
<a data-for='custom-off-event' data-tip='custom show and hide' data-event='click' data-event-off='dblclick'>( •̀д•́)</a>

src/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class ReactTooltip extends Component {
4343
countTransform: PropTypes.bool,
4444
afterShow: PropTypes.func,
4545
afterHide: PropTypes.func,
46-
disable: PropTypes.bool
46+
disable: PropTypes.bool,
47+
scrollHide: PropTypes.bool
4748
}
4849

4950
constructor (props) {
@@ -231,6 +232,15 @@ class ReactTooltip extends Component {
231232

232233
// If it is focus event or called by ReactTooltip.show, switch to `solid` effect
233234
const switchToSolid = e instanceof window.FocusEvent || isGlobalCall
235+
236+
// if it need to skip adding hide listener to scroll
237+
let scrollHide = true
238+
if (e.currentTarget.getAttribute('data-scroll-hide')) {
239+
scrollHide = e.currentTarget.getAttribute('data-scroll-hide') === 'true'
240+
} else if (this.props.scrollHide != null) {
241+
scrollHide = this.props.scrollHide
242+
}
243+
234244
this.setState({
235245
placeholder,
236246
place: e.currentTarget.getAttribute('data-place') || this.props.place || 'top',
@@ -250,7 +260,7 @@ class ReactTooltip extends Component {
250260
? e.currentTarget.getAttribute('data-count-transform') === 'true'
251261
: (this.props.countTransform != null ? this.props.countTransform : true)
252262
}, () => {
253-
this.addScrollListener(e)
263+
if (scrollHide) this.addScrollListener(e)
254264
this.updateTooltip(e)
255265

256266
if (getContent && Array.isArray(getContent)) {

0 commit comments

Comments
 (0)