Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resizeHide option #194

Merged
merged 1 commit into from
Sep 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class | data-class | String | | extra custom class, can use !important to
afterHide | null | Func | () => {} | Function that will be called after tooltip hide
disable | data-tip-disable | Bool | true, false | Disable the tooltip behaviour, default is false
scrollHide | data-scroll-hide | Bool | true, false | Hide the tooltip when scrolling, default is true
resizeHide | null | Bool | true, false | Hide the tooltip when resizing the window, default is true

## Using react component as tooltip
Check the example [React-tooltip Test](http://wwayne.com/react-tooltip)
Expand Down
8 changes: 5 additions & 3 deletions src/decorators/windowListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import CONSTANT from '../constant'

export default function (target) {
target.prototype.bindWindowEvents = function () {
target.prototype.bindWindowEvents = function (resizeHide) {
// ReactTooltip.hide
window.removeEventListener(CONSTANT.GLOBAL.HIDE, this.hideTooltip)
window.addEventListener(CONSTANT.GLOBAL.HIDE, this.hideTooltip, false)
Expand All @@ -18,8 +18,10 @@ export default function (target) {
window.addEventListener(CONSTANT.GLOBAL.SHOW, this.globalShow, false)

// Resize
window.removeEventListener('resize', this.onWindowResize)
window.addEventListener('resize', this.onWindowResize, false)
if (resizeHide) {
window.removeEventListener('resize', this.onWindowResize)
window.addEventListener('resize', this.onWindowResize, false)
}
}

target.prototype.unbindWindowEvents = function () {
Expand Down
11 changes: 8 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ class ReactTooltip extends Component {
afterShow: PropTypes.func,
afterHide: PropTypes.func,
disable: PropTypes.bool,
scrollHide: PropTypes.bool
}
scrollHide: PropTypes.bool,
resizeHide: PropTypes.bool
};

static defaultProps = {
resizeHide: true
};

constructor (props) {
super(props)
Expand Down Expand Up @@ -95,7 +100,7 @@ class ReactTooltip extends Component {
componentDidMount () {
this.setStyleHeader() // Set the style to the <link>
this.bindListener() // Bind listener for tooltip
this.bindWindowEvents() // Bind global event for static method
this.bindWindowEvents(this.props.resizeHide) // Bind global event for static method
}

componentWillReceiveProps (props) {
Expand Down