Skip to content

Commit 1ea3fa5

Browse files
authored
Merge pull request #375 from wwayne/is_capture_example
test(scrolling): Add example showing tooltip inside scrolling div
2 parents 72230a5 + 227f0fc commit 1ea3fa5

File tree

5 files changed

+84
-36
lines changed

5 files changed

+84
-36
lines changed

contributing.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
This doc needs help! Please submit your PR...
44

5+
## Commit messages
6+
7+
We are using semantic-release to automate the release process, and this depends on a specific format for commit messages. Please run `npm run commit` to use `commitizen` to properly format your commit messages so they can be automatically processed and included in release notes.
8+
59
## Pull request testing
610

711
Some notes on testing and releasing.
@@ -11,7 +15,7 @@ Some notes on testing and releasing.
1115

1216
## Doing a release
1317

14-
We really want to use semantic-release instead of this:
18+
We are using semantic-release instead of this:
1519

1620
* `make deploy` updates the files in the `standalone` directory
1721
* update the version number in `package.json`

example/src/index.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,39 @@ class Test extends React.Component {
246246
</div>
247247
</pre>
248248
</div>
249+
<div className="section">
250+
<h4 className='title'>Test Scrolling</h4>
251+
<p className="sub-title"></p>
252+
<div className="example-jsx" style={{ height: '200px' }}>
253+
<div className="side" style={{ overflow: 'auto', height: '200px' }}>
254+
<div data-for='scrollContent' data-tip data-iscapture='true' style={{ width: '5000px', height: '5000px' }}>
255+
Scroll me with the mouse wheel.<br/>
256+
The tootlip will hide.<br/>
257+
Make sure you set data-iscapture="true"
258+
</div>
259+
<ReactTooltip id='scrollContent' getContent={() => Math.floor(Math.random() * 100)}/>
260+
</div>
261+
<div className="side" style={{ overflow: 'auto', height: '200px' }}>
262+
<div data-for='scrollTime' data-tip data-iscapture='true' data-scroll-hide='false' style={{ width: '5000px', height: '5000px' }}>
263+
Scroll me with the mouse wheel.<br/>
264+
The tootlip will stay visible.
265+
</div>
266+
<ReactTooltip id='scrollTime'
267+
getContent={[() => {return new Date().toISOString()}, 1000]}/>
268+
</div>
269+
</div>
270+
<br />
271+
<pre className='example-pre'>
272+
<div>
273+
<p>{"<div data-for='scrollContent' data-tip data-iscapture='true'\n style={{ width: '5000px', height: '5000px' }}>...</div>\n" +
274+
"<ReactTooltip id='scrollContent' getContent={() => Math.floor(Math.random() * 100)}/>"}</p>
275+
</div>
276+
<div>
277+
<p>{"<div data-for='scrollTime' data-tip data-iscapture='true' data-scroll-hide='false'\n style={{ width: '5000px', height: '5000px' }}>...</div>\n" +
278+
"<ReactTooltip id='scrollTime' getContent={[() => {return new Date().toISOString()}, 1000]}/>"}</p>
279+
</div>
280+
</pre>
281+
</div>
249282
</section>
250283
</div>
251284
)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-tooltip",
3-
"version": "3.4.3",
3+
"version": "0.0.0-semantic-release",
44
"description": "react tooltip component",
55
"main": "dist/index.js",
66
"scripts": {

standalone/react-tooltip.js

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,6 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
16151615
effect: 'float', // float or fixed
16161616
show: false,
16171617
border: false,
1618-
placeholder: '',
16191618
offset: {},
16201619
extraClass: '',
16211620
html: false,
@@ -1627,10 +1626,12 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
16271626
currentTarget: null, // Current target of mouse event
16281627
ariaProps: (0, _aria.parseAria)(props), // aria- and role attributes
16291628
isEmptyTip: false,
1630-
disable: false
1629+
disable: false,
1630+
originTooltip: null,
1631+
isMultiline: false
16311632
};
16321633

1633-
_this.bind(['showTooltip', 'updateTooltip', 'hideTooltip', 'globalRebuild', 'globalShow', 'globalHide', 'onWindowResize']);
1634+
_this.bind(['showTooltip', 'updateTooltip', 'hideTooltip', 'getTooltipContent', 'globalRebuild', 'globalShow', 'globalHide', 'onWindowResize']);
16341635

16351636
_this.mount = true;
16361637
_this.delayShowLoop = null;
@@ -1793,6 +1794,31 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
17931794
target.removeEventListener('mousemove', this.updateTooltip, isCaptureMode);
17941795
target.removeEventListener('mouseleave', this.hideTooltip, isCaptureMode);
17951796
}
1797+
}, {
1798+
key: 'getTooltipContent',
1799+
value: function getTooltipContent() {
1800+
var _props4 = this.props,
1801+
getContent = _props4.getContent,
1802+
children = _props4.children;
1803+
1804+
// Generate tooltip content
1805+
1806+
var content = void 0;
1807+
if (getContent) {
1808+
if (Array.isArray(getContent)) {
1809+
content = getContent[0] && getContent[0]();
1810+
} else {
1811+
content = getContent();
1812+
}
1813+
}
1814+
1815+
return (0, _getTipContent2.default)(this.state.originTooltip, children, content, this.state.isMultiline);
1816+
}
1817+
}, {
1818+
key: 'isEmptyTip',
1819+
value: function isEmptyTip(placeholder) {
1820+
return typeof placeholder === 'string' && placeholder === '' || placeholder === null;
1821+
}
17961822

17971823
/**
17981824
* When mouse enter, show the tooltip
@@ -1813,26 +1839,13 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
18131839
}
18141840
// Get the tooltip content
18151841
// calculate in this phrase so that tip width height can be detected
1816-
var _props4 = this.props,
1817-
children = _props4.children,
1818-
multiline = _props4.multiline,
1819-
getContent = _props4.getContent;
1842+
var _props5 = this.props,
1843+
multiline = _props5.multiline,
1844+
getContent = _props5.getContent;
18201845

18211846
var originTooltip = e.currentTarget.getAttribute('data-tip');
18221847
var isMultiline = e.currentTarget.getAttribute('data-multiline') || multiline || false;
18231848

1824-
// Generate tootlip content
1825-
var content = void 0;
1826-
if (getContent) {
1827-
if (Array.isArray(getContent)) {
1828-
content = getContent[0] && getContent[0]();
1829-
} else {
1830-
content = getContent();
1831-
}
1832-
}
1833-
var placeholder = (0, _getTipContent2.default)(originTooltip, children, content, isMultiline);
1834-
var isEmptyTip = typeof placeholder === 'string' && placeholder === '' || placeholder === null;
1835-
18361849
// If it is focus event or called by ReactTooltip.show, switch to `solid` effect
18371850
var switchToSolid = e instanceof window.FocusEvent || isGlobalCall;
18381851

@@ -1848,8 +1861,8 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
18481861
this.clearTimer();
18491862

18501863
this.setState({
1851-
placeholder: placeholder,
1852-
isEmptyTip: isEmptyTip,
1864+
originTooltip: originTooltip,
1865+
isMultiline: isMultiline,
18531866
desiredPlace: e.currentTarget.getAttribute('data-place') || this.props.place || 'top',
18541867
place: e.currentTarget.getAttribute('data-place') || this.props.place || 'top',
18551868
type: e.currentTarget.getAttribute('data-type') || this.props.type || 'dark',
@@ -1870,11 +1883,10 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
18701883
if (_this5.mount) {
18711884
var _getContent = _this5.props.getContent;
18721885

1873-
var _placeholder = (0, _getTipContent2.default)(originTooltip, '', _getContent[0](), isMultiline);
1874-
var _isEmptyTip = typeof _placeholder === 'string' && _placeholder === '';
1886+
var placeholder = (0, _getTipContent2.default)(originTooltip, '', _getContent[0](), isMultiline);
1887+
var isEmptyTip = _this5.isEmptyTip(placeholder);
18751888
_this5.setState({
1876-
placeholder: _placeholder,
1877-
isEmptyTip: _isEmptyTip
1889+
isEmptyTip: isEmptyTip
18781890
});
18791891
}
18801892
}, getContent[1]);
@@ -1894,15 +1906,14 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
18941906
var _state = this.state,
18951907
delayShow = _state.delayShow,
18961908
show = _state.show,
1897-
isEmptyTip = _state.isEmptyTip,
18981909
disable = _state.disable;
18991910
var afterShow = this.props.afterShow;
1900-
var placeholder = this.state.placeholder;
19011911

1912+
var placeholder = this.getTooltipContent();
19021913
var delayTime = show ? 0 : parseInt(delayShow, 10);
19031914
var eventTarget = e.currentTarget;
19041915

1905-
if (isEmptyTip || disable) return; // if the tooltip is empty, disable the tooltip
1916+
if (this.isEmptyTip(placeholder) || disable) return; // if the tooltip is empty, disable the tooltip
19061917
var updateState = function updateState() {
19071918
if (Array.isArray(placeholder) && placeholder.length > 0 || placeholder) {
19081919
var isInvisible = !_this6.state.show;
@@ -1936,12 +1947,12 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
19361947

19371948
var _state2 = this.state,
19381949
delayHide = _state2.delayHide,
1939-
isEmptyTip = _state2.isEmptyTip,
19401950
disable = _state2.disable;
19411951
var afterHide = this.props.afterHide;
19421952

1953+
var placeholder = this.getTooltipContent();
19431954
if (!this.mount) return;
1944-
if (isEmptyTip || disable) return; // if the tooltip is empty, disable the tooltip
1955+
if (this.isEmptyTip(placeholder) || disable) return; // if the tooltip is empty, disable the tooltip
19451956
if (hasTarget) {
19461957
// Don't trigger other elements belongs to other ReactTooltip
19471958
var targetArray = this.getTargetArray(this.props.id);
@@ -2046,13 +2057,13 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
20462057
key: 'render',
20472058
value: function render() {
20482059
var _state4 = this.state,
2049-
placeholder = _state4.placeholder,
20502060
extraClass = _state4.extraClass,
20512061
html = _state4.html,
20522062
ariaProps = _state4.ariaProps,
2053-
disable = _state4.disable,
2054-
isEmptyTip = _state4.isEmptyTip;
2063+
disable = _state4.disable;
20552064

2065+
var placeholder = this.getTooltipContent();
2066+
var isEmptyTip = this.isEmptyTip(placeholder);
20562067
var tooltipClass = (0, _classnames2.default)('__react_component_tooltip', { 'show': this.state.show && !disable && !isEmptyTip }, { 'border': this.state.border }, { 'place-top': this.state.place === 'top' }, { 'place-bottom': this.state.place === 'bottom' }, { 'place-left': this.state.place === 'left' }, { 'place-right': this.state.place === 'right' }, { 'type-dark': this.state.type === 'dark' }, { 'type-success': this.state.type === 'success' }, { 'type-warning': this.state.type === 'warning' }, { 'type-error': this.state.type === 'error' }, { 'type-info': this.state.type === 'info' }, { 'type-light': this.state.type === 'light' });
20572068

20582069
var Wrapper = this.props.wrapper;

standalone/react-tooltip.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)