Skip to content
This repository was archived by the owner on May 15, 2019. It is now read-only.

Commit 892ffde

Browse files
author
Brian Genisio
committed
Allow the Tooltip target container to have a custom style
Summary: The target markup is wrapped in a `div` which is a problem if you want the target markup to be inline with other text. Add the ability to style the target markup container to avoid this problem. Use PropTypes.any Test Plan: Use a tooltip and include a `targetContainerStyle` to style the markup found in the target section Reviewers: riley Reviewed By: riley Differential Revision: https://phabricator.khanacademy.org/D32039
1 parent 777fd2f commit 892ffde

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

examples/tooltip.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ var pStyle = {
44
padding: 10,
55
backgroundColor: "white"
66
};
7+
8+
var tStyle = {
9+
display: 'inline-block',
10+
fontWeight: 'bold'
11+
};
712
// }}}
813

914
return <Tooltip className="class-for-tooltip-contents"
@@ -12,6 +17,7 @@ return <Tooltip className="class-for-tooltip-contents"
1217
verticalPosition="bottom"
1318
arrowSize={10}
1419
borderColor="#ccc"
20+
targetContainerStyle={tStyle}
1521
show>
1622
<div>reticulating splines!</div>
1723
<p style={pStyle}>

js/tooltip.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var _ = require("underscore");
2424
* arrowSize={10} // arrow size in pixels
2525
* borderColor="#ccc" // color of the border for the tooltip
2626
* show={true} // whether the tooltip should currently be visible
27+
* targetContainerStyle={targetContainerStyle}
2728
* >
2829
* <TargetElementOfTheTooltip />
2930
* <TooltipContents1 />
@@ -216,7 +217,8 @@ var Tooltip = React.createClass({
216217
),
217218
children: React.PropTypes.arrayOf(
218219
React.PropTypes.element
219-
).isRequired
220+
).isRequired,
221+
targetContainerStyle: React.PropTypes.any, // style object
220222
},
221223

222224
getDefaultProps: function() {
@@ -226,7 +228,8 @@ var Tooltip = React.createClass({
226228
borderColor: "#ccc",
227229
verticalPosition: "bottom",
228230
horizontalPosition: "left",
229-
horizontalAlign: "left"
231+
horizontalAlign: "left",
232+
targetContainerStyle: {},
230233
};
231234
},
232235

@@ -250,7 +253,7 @@ var Tooltip = React.createClass({
250253

251254
{/* We wrap our input in a div so that we can put the tooltip in a
252255
div above/below it */}
253-
<div>
256+
<div style={this.props.targetContainerStyle}>
254257
{_.first(this.props.children)}
255258
</div>
256259

0 commit comments

Comments
 (0)