Skip to content

Commit fcf8ddb

Browse files
committed
tooltip horizontal fix
1 parent 7b0faf9 commit fcf8ddb

File tree

3 files changed

+79
-27
lines changed

3 files changed

+79
-27
lines changed

components/SLDSPopover.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,22 @@ module.exports = React.createClass( {
116116
beforeClose (){
117117
},
118118

119+
getPosition () {
120+
let positions = [];
121+
if (this.props.verticalAlign === 'top' || this.props.verticalAlign === 'bottom') {
122+
positions.push(this.props.verticalAlign);
123+
positions.push(this.props.horizontalAlign);
124+
}
125+
else {
126+
positions.push(this.props.horizontalAlign);
127+
positions.push(this.props.verticalAlign);
128+
}
129+
return positions.join(' ');
130+
},
131+
119132
dropOptions () {
120133
const target = this.props.targetElement?React.findDOMNode(this.props.targetElement):React.findDOMNode(this).parentNode;
121-
const position = this.props.verticalAlign+' '+this.props.horizontalAlign;
122-
console.log('position: ',position);
134+
const position = this.getPosition();
123135
return {
124136
target: target,
125137
content: this.popoverElement,

components/SLDSTooltip/index.jsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = React.createClass( {
2828
return {
2929
content:<span>Tooltip</span>,
3030
align: 'top',
31-
hoverCloseDelay:200,
31+
hoverCloseDelay:350,
3232
openOnHover:false
3333
};
3434
},
@@ -66,6 +66,26 @@ module.exports = React.createClass( {
6666
return <div className='slds-popover__body'>{this.props.content}</div>;
6767
},
6868

69+
getHorizontalAlign() {
70+
if (this.props.align==='left') {
71+
return 'right';
72+
}
73+
else if (this.props.align==='right') {
74+
return 'left';
75+
}
76+
return 'center';
77+
},
78+
79+
getVerticalAlign() {
80+
if (this.props.align==='bottom') {
81+
return 'bottom';
82+
}
83+
else if (this.props.align==='top') {
84+
return 'top';
85+
}
86+
return 'middle';
87+
},
88+
6989
getTooltip() {
7090
const style = {
7191
'slds-popover':true,
@@ -82,10 +102,10 @@ module.exports = React.createClass( {
82102
className=''
83103
marginTop='1rem'
84104
marginBottom='1rem'
85-
marginLeft='1rem'
86-
marginRight='1rem'
87-
horizontalAlign={this.props.align==='left' || this.props.align==='right'?this.props.align:'center'}
88-
verticalAlign={this.props.align==='bottom' || this.props.align==='top'?this.props.align:'center'}
105+
marginLeft='1.5rem'
106+
marginRight='1.5rem'
107+
horizontalAlign={this.getHorizontalAlign()}
108+
verticalAlign={this.getVerticalAlign()}
89109
flippable={false}
90110
onClose={this.handleCancel}>
91111
<div className={cx(style)}>

demo/pages/HomePage/TooltipSection.jsx

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {SLDSTooltip,SLDSButton} from '../../../components';
1414

1515
import {default as PrismCode} from 'react-prism/lib/PrismCode';
1616

17-
17+
const alignNames = ['left','right','top','bottom'];
1818

1919
module.exports = React.createClass( {
2020

@@ -23,7 +23,15 @@ module.exports = React.createClass( {
2323
},
2424

2525
getInitialState () {
26-
return {};
26+
return {
27+
alignIndex:0
28+
};
29+
},
30+
31+
componentDidMount () {
32+
setInterval ( ()=>{
33+
this.nextAlign();
34+
},2000);
2735
},
2836

2937
handleOnUpdateHighlighted () {
@@ -38,6 +46,14 @@ module.exports = React.createClass( {
3846
console.log('onClick should be defined');
3947
},
4048

49+
nextAlign() {
50+
let nextAlignIndex = this.state.alignIndex+1;
51+
if (nextAlignIndex >= alignNames.length) {
52+
nextAlignIndex = 0;
53+
}
54+
this.setState({alignIndex:nextAlignIndex});
55+
},
56+
4157
render() {
4258
return (
4359

@@ -51,24 +67,28 @@ module.exports = React.createClass( {
5167
{require("raw-loader!../../code-snippets/SLDSDropdownPage.txt")}
5268
</PrismCode>
5369
*/}
54-
<div ref="super" className="slds-p-vertical--large">
55-
<p>
56-
<SLDSTooltip
57-
content={<span>Tooltip with top alignment</span>}
58-
align='top'
59-
targetElement={this.refs.super}>Tooltip align top</SLDSTooltip>
60-
</p>
61-
</div>
62-
63-
<div ref="super" className="slds-p-vertical--large">
64-
<p>
65-
<SLDSTooltip
66-
content={<span>Tooltip with bottom alignment</span>}
67-
align='bottom'
68-
openOnHover={true}
69-
targetElement={this.refs.super}>Tooltip open on hover</SLDSTooltip>
70-
</p>
71-
</div>
70+
<section style={{paddingLeft:'10rem'}}>
71+
<div className="slds-p-vertical--large">
72+
<p>
73+
<SLDSTooltip
74+
key={'align_'+this.state.alignIndex}
75+
content={<span>Tooltip with top alignment</span>}
76+
align={alignNames[this.state.alignIndex]}>
77+
Tooltip align top
78+
</SLDSTooltip>
79+
</p>
80+
</div>
81+
82+
<div ref="super" className="slds-p-vertical--large">
83+
<p>
84+
<SLDSTooltip
85+
content={<span>Tooltip with bottom alignment</span>}
86+
align='bottom'
87+
openOnHover={true}
88+
targetElement={this.refs.super}>Tooltip open on hover</SLDSTooltip>
89+
</p>
90+
</div>
91+
</section>
7292

7393

7494
</div>

0 commit comments

Comments
 (0)