Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ online example: http://react-component.github.io/tooltip/examples/
<td>placement</td>
<td>String|Object</td>
<td></td>
<td>one of ['left','right','top','bottom'] or alignConfig of [dom-align](https://github.com/yiminghe/dom-align) </td>
<td>one of ['left','right','top','bottom', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight'] or alignConfig of [dom-align](https://github.com/yiminghe/dom-align) </td>
</tr>
<tr>
<td>overlay</td>
Expand Down
56 changes: 56 additions & 0 deletions assets/bootstrap.less
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,34 @@
}
}

&-topRight {

margin-top: -3px;
padding: 5px 0;

& > .@{tooltipPrefixCls}-arrow {
bottom: 0;
left: 85%;
margin-left: -5px;
border-width: 5px 5px 0;
border-top-color: #000000;
}
}

&-topLeft {

margin-top: -3px;
padding: 5px 0;

& > .@{tooltipPrefixCls}-arrow {
bottom: 0;
left: 15%;
margin-left: -5px;
border-width: 5px 5px 0;
border-top-color: #000000;
}
}

&-bottom {
margin-top: 3px;
padding: 5px 0;
Expand All @@ -56,6 +84,34 @@

}

&-bottomRight {

margin-top: 3px;
padding: 5px 0;

& > .@{tooltipPrefixCls}-arrow {
top: 0;
left: 85%;
margin-left: -5px;
border-width: 0 5px 5px;
border-bottom-color: #000000;
}
}

&-bottomLeft {

margin-top: 3px;
padding: 5px 0;

& > .@{tooltipPrefixCls}-arrow {
top: 0;
left: 15%;
margin-left: -5px;
border-width: 0 5px 5px;
border-bottom-color: #000000;
}
}

&-right {
margin-left: 3px;
padding: 0 5px;
Expand Down
4 changes: 4 additions & 0 deletions examples/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ var Test = React.createClass({
<option>right</option>
<option>top</option>
<option>bottom</option>
<option>topLeft</option>
<option>topRight</option>
<option>bottomRight</option>
<option>bottomLeft</option>
</select>
</label>
&nbsp;&nbsp;&nbsp;&nbsp;
Expand Down
4 changes: 4 additions & 0 deletions src/Popup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const placementAlignMap = {
right: {points: ['cl', 'cr']},
top: {points: ['bc', 'tc']},
bottom: {points: ['tc', 'bc']},
topLeft: { points: ['bl', 'tl'] },
topRight: { points: ['br', 'tr'] },
bottomRight: { points: ['tr', 'br'] },
bottomLeft: { points: ['tl', 'bl'] }
};

const Popup = React.createClass({
Expand Down
82 changes: 82 additions & 0 deletions tests/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,46 @@ describe('rc-tooltip', function () {
}, 20);
});

it('bottomRight works', (done)=> {
var tooltip = React.render(<Tooltip trigger={['click']} placement="bottomRight" overlay={<strong>tooltip</strong>}>
<div className="target">click</div>
</Tooltip>, div);
var domNode = React.findDOMNode(tooltip).firstChild;
Simulate.click(domNode);
setTimeout(()=> {
var popupDomNode = tooltip.getPopupDomNode();
expect(popupDomNode).to.be.ok();
var targetOffset = $(domNode).offset();
var popupOffset = $(popupDomNode).offset();
var arrowOffset = $(popupDomNode).find('.rc-tooltip-arrow').offset();
console.log(popupOffset, targetOffset);
expect(popupOffset.top).to.be(targetOffset.top + $(domNode).outerHeight());
expect(arrowOffset.left).to.be(180);
Simulate.click(domNode);
done();
}, 20);
});

it('bottomLeft works', (done)=> {
var tooltip = React.render(<Tooltip trigger={['click']} placement="bottomLeft" overlay={<strong>tooltip</strong>}>
<div className="target">click</div>
</Tooltip>, div);
var domNode = React.findDOMNode(tooltip).firstChild;
Simulate.click(domNode);
setTimeout(()=> {
var popupDomNode = tooltip.getPopupDomNode();
expect(popupDomNode).to.be.ok();
var targetOffset = $(domNode).offset();
var popupOffset = $(popupDomNode).offset();
var arrowOffset = $(popupDomNode).find('.rc-tooltip-arrow').offset();
console.log(popupOffset, targetOffset);
expect(popupOffset.top).to.be(targetOffset.top + $(domNode).outerHeight());
expect(arrowOffset.left).to.be(110);
Simulate.click(domNode);
done();
}, 20);
});

it('top works', (done)=> {
var tooltip = React.render(<Tooltip trigger={['click']} placement="top" overlay={<strong>tooltip</strong>}>
<div className="target">click</div>
Expand All @@ -142,6 +182,48 @@ describe('rc-tooltip', function () {
done();
}, 20);
});

it('topLeft works', (done)=> {
var tooltip = React.render(<Tooltip trigger={['click']} placement="topLeft" overlay={<strong>tooltip</strong>}>
<div className="target">click</div>
</Tooltip>, div);
var domNode = React.findDOMNode(tooltip).firstChild;
Simulate.click(domNode);
setTimeout(()=> {
var popupDomNode = tooltip.getPopupDomNode();
expect(popupDomNode).to.be.ok();
var targetOffset = $(domNode).offset();
var popupOffset = $(popupDomNode).offset();
var arrowOffset = $(popupDomNode).find('.rc-tooltip-arrow').offset();
console.log(popupOffset, targetOffset);
expect(popupOffset.top).to.be(targetOffset.top - $(popupDomNode).outerHeight());
expect(popupOffset.left).to.be(targetOffset.left);
expect(arrowOffset.left).to.be(110);
Simulate.click(domNode);
done();
}, 20);
});

it('topRight works', (done)=> {
var tooltip = React.render(<Tooltip trigger={['click']} placement="topRight" overlay={<strong>tooltip</strong>}>
<div className="target">click</div>
</Tooltip>, div);
var domNode = React.findDOMNode(tooltip).firstChild;
Simulate.click(domNode);
setTimeout(()=> {
var popupDomNode = tooltip.getPopupDomNode();
expect(popupDomNode).to.be.ok();
var targetOffset = $(domNode).offset();
var popupOffset = $(popupDomNode).offset();
var arrowOffset = $(popupDomNode).find('.rc-tooltip-arrow').offset();
console.log(popupOffset, targetOffset);
expect(popupOffset.top).to.be(targetOffset.top - $(popupDomNode).outerHeight());
expect(popupOffset.left).to.be(targetOffset.left);
expect(arrowOffset.left).to.be(180);
Simulate.click(domNode);
done();
}, 20);
});
});

if (window.TransitionEvent) {
Expand Down