Skip to content

Commit 96baa15

Browse files
author
Jimmy Jia
committed
[fixed] Fix propTypes for overlays
Fixes react-bootstrap#173
1 parent 5b1bc99 commit 96baa15

File tree

3 files changed

+50
-10
lines changed

3 files changed

+50
-10
lines changed

src/Popover.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ const Popover = React.createClass({
99
placement: React.PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
1010
positionLeft: React.PropTypes.number,
1111
positionTop: React.PropTypes.number,
12-
arrowOffsetLeft: React.PropTypes.number,
13-
arrowOffsetTop: React.PropTypes.number,
12+
arrowOffsetLeft: React.PropTypes.oneOfType([
13+
React.PropTypes.number, React.PropTypes.string
14+
]),
15+
arrowOffsetTop: React.PropTypes.oneOfType([
16+
React.PropTypes.number, React.PropTypes.string
17+
]),
1418
title: React.PropTypes.node
1519
},
1620

@@ -21,19 +25,19 @@ const Popover = React.createClass({
2125
},
2226

2327
render() {
24-
let classes = {
28+
const classes = {
2529
'popover': true,
2630
[this.props.placement]: true,
2731
'in': this.props.positionLeft != null || this.props.positionTop != null
2832
};
2933

30-
let style = {
34+
const style = {
3135
'left': this.props.positionLeft,
3236
'top': this.props.positionTop,
3337
'display': 'block'
3438
};
3539

36-
let arrowStyle = {
40+
const arrowStyle = {
3741
'left': this.props.arrowOffsetLeft,
3842
'top': this.props.arrowOffsetTop
3943
};

src/Tooltip.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ const Tooltip = React.createClass({
99
placement: React.PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
1010
positionLeft: React.PropTypes.number,
1111
positionTop: React.PropTypes.number,
12-
arrowOffsetLeft: React.PropTypes.number,
13-
arrowOffsetTop: React.PropTypes.number
12+
arrowOffsetLeft: React.PropTypes.oneOfType([
13+
React.PropTypes.number, React.PropTypes.string
14+
]),
15+
arrowOffsetTop: React.PropTypes.oneOfType([
16+
React.PropTypes.number, React.PropTypes.string
17+
])
1418
},
1519

1620
getDefaultProps() {
@@ -20,18 +24,18 @@ const Tooltip = React.createClass({
2024
},
2125

2226
render() {
23-
let classes = {
27+
const classes = {
2428
'tooltip': true,
2529
[this.props.placement]: true,
2630
'in': this.props.positionLeft != null || this.props.positionTop != null
2731
};
2832

29-
let style = {
33+
const style = {
3034
'left': this.props.positionLeft,
3135
'top': this.props.positionTop
3236
};
3337

34-
let arrowStyle = {
38+
const arrowStyle = {
3539
'left': this.props.arrowOffsetLeft,
3640
'top': this.props.arrowOffsetTop
3741
};

test/OverlayTriggerSpec.js

+32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22
import ReactTestUtils from 'react/lib/ReactTestUtils';
33
import OverlayTrigger from '../src/OverlayTrigger';
4+
import Popover from '../src/Popover';
5+
import Tooltip from '../src/Tooltip';
46

57
describe('OverlayTrigger', function() {
68
it('Should create OverlayTrigger element', function() {
@@ -161,4 +163,34 @@ describe('OverlayTrigger', function() {
161163
});
162164
});
163165
});
166+
167+
describe('overlay types', function() {
168+
[
169+
{
170+
name: 'Popover',
171+
overlay: (<Popover>test</Popover>)
172+
},
173+
{
174+
name: 'Tooltip',
175+
overlay: (<Tooltip>test</Tooltip>)
176+
}
177+
].forEach(function(testCase) {
178+
describe(testCase.name, function() {
179+
let instance, overlayTrigger;
180+
181+
beforeEach(function() {
182+
instance = ReactTestUtils.renderIntoDocument(
183+
<OverlayTrigger trigger="click" overlay={testCase.overlay}>
184+
<button>button</button>
185+
</OverlayTrigger>
186+
);
187+
overlayTrigger = React.findDOMNode(instance);
188+
});
189+
190+
it('Should handle trigger without warnings', function() {
191+
ReactTestUtils.Simulate.click(overlayTrigger);
192+
});
193+
});
194+
});
195+
});
164196
});

0 commit comments

Comments
 (0)