Skip to content

Commit 924f8fb

Browse files
Geoff Pleiss and Kenny WangGeoff Pleiss and Kenny Wang
Geoff Pleiss and Kenny Wang
authored and
Geoff Pleiss and Kenny Wang
committedJul 20, 2015
[fixed] Tooltip accepts a style prop
fixes react-bootstrap#1027
1 parent 91802f6 commit 924f8fb

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed
 

‎src/Tooltip.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ const Tooltip = React.createClass({
4343
/**
4444
* Title text
4545
*/
46-
title: React.PropTypes.node
46+
title: React.PropTypes.node,
47+
/**
48+
* Style hash
49+
*/
50+
style: React.PropTypes.object
4751
},
4852

4953
getDefaultProps() {
@@ -60,7 +64,8 @@ const Tooltip = React.createClass({
6064

6165
const style = {
6266
'left': this.props.positionLeft,
63-
'top': this.props.positionTop
67+
'top': this.props.positionTop,
68+
...this.props.style
6469
};
6570

6671
const arrowStyle = {

‎test/TooltipSpec.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,25 @@ import Tooltip from '../src/Tooltip';
55
describe('Tooltip', function () {
66
it('Should output a tooltip with content', function () {
77
let instance = ReactTestUtils.renderIntoDocument(
8-
<Tooltip>
8+
<Tooltip positionTop={10} positionLeft={20}>
99
<strong>Tooltip Content</strong>
1010
</Tooltip>
1111
);
1212
assert.ok(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'strong'));
1313

14+
const tooltip = ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'tooltip');
15+
assert.deepEqual(tooltip.props.style, {top: 10, left: 20});
1416
});
1517

18+
describe('When a style property is provided', function () {
19+
it('Should render a tooltip with merged styles', function () {
20+
let instance = ReactTestUtils.renderIntoDocument(
21+
<Tooltip style={{opacity: 0.9}} positionTop={10} positionLeft={20}>
22+
<strong>Tooltip Content</strong>
23+
</Tooltip>
24+
);
25+
const tooltip = ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'tooltip');
26+
assert.deepEqual(tooltip.props.style, {opacity: 0.9, top: 10, left: 20});
27+
});
28+
});
1629
});

0 commit comments

Comments
 (0)
Please sign in to comment.