Skip to content

Commit

Permalink
[fixed] Fix propTypes for overlays
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Jia committed May 14, 2015
1 parent 5b1bc99 commit 96baa15
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ const Popover = React.createClass({
placement: React.PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
positionLeft: React.PropTypes.number,
positionTop: React.PropTypes.number,
arrowOffsetLeft: React.PropTypes.number,
arrowOffsetTop: React.PropTypes.number,
arrowOffsetLeft: React.PropTypes.oneOfType([
React.PropTypes.number, React.PropTypes.string
]),
arrowOffsetTop: React.PropTypes.oneOfType([
React.PropTypes.number, React.PropTypes.string
]),
title: React.PropTypes.node
},

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

render() {
let classes = {
const classes = {
'popover': true,
[this.props.placement]: true,
'in': this.props.positionLeft != null || this.props.positionTop != null
};

let style = {
const style = {
'left': this.props.positionLeft,
'top': this.props.positionTop,
'display': 'block'
};

let arrowStyle = {
const arrowStyle = {
'left': this.props.arrowOffsetLeft,
'top': this.props.arrowOffsetTop
};
Expand Down
14 changes: 9 additions & 5 deletions src/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ const Tooltip = React.createClass({
placement: React.PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
positionLeft: React.PropTypes.number,
positionTop: React.PropTypes.number,
arrowOffsetLeft: React.PropTypes.number,
arrowOffsetTop: React.PropTypes.number
arrowOffsetLeft: React.PropTypes.oneOfType([
React.PropTypes.number, React.PropTypes.string
]),
arrowOffsetTop: React.PropTypes.oneOfType([
React.PropTypes.number, React.PropTypes.string
])
},

getDefaultProps() {
Expand All @@ -20,18 +24,18 @@ const Tooltip = React.createClass({
},

render() {
let classes = {
const classes = {
'tooltip': true,
[this.props.placement]: true,
'in': this.props.positionLeft != null || this.props.positionTop != null
};

let style = {
const style = {
'left': this.props.positionLeft,
'top': this.props.positionTop
};

let arrowStyle = {
const arrowStyle = {
'left': this.props.arrowOffsetLeft,
'top': this.props.arrowOffsetTop
};
Expand Down
32 changes: 32 additions & 0 deletions test/OverlayTriggerSpec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import ReactTestUtils from 'react/lib/ReactTestUtils';
import OverlayTrigger from '../src/OverlayTrigger';
import Popover from '../src/Popover';
import Tooltip from '../src/Tooltip';

describe('OverlayTrigger', function() {
it('Should create OverlayTrigger element', function() {
Expand Down Expand Up @@ -161,4 +163,34 @@ describe('OverlayTrigger', function() {
});
});
});

describe('overlay types', function() {
[
{
name: 'Popover',
overlay: (<Popover>test</Popover>)
},
{
name: 'Tooltip',
overlay: (<Tooltip>test</Tooltip>)
}
].forEach(function(testCase) {
describe(testCase.name, function() {
let instance, overlayTrigger;

beforeEach(function() {
instance = ReactTestUtils.renderIntoDocument(
<OverlayTrigger trigger="click" overlay={testCase.overlay}>
<button>button</button>
</OverlayTrigger>
);
overlayTrigger = React.findDOMNode(instance);
});

it('Should handle trigger without warnings', function() {
ReactTestUtils.Simulate.click(overlayTrigger);
});
});
});
});
});

0 comments on commit 96baa15

Please sign in to comment.