@@ -35,6 +35,33 @@ class Tooltip extends Component {
3535 }
3636 }
3737
38+ //
39+ // Control
40+
41+ computeMaxSize = ( data ) => {
42+ const {
43+ top,
44+ right,
45+ bottom,
46+ left
47+ } = data . offsets . reference ;
48+
49+ const windowWidth = window . innerWidth ;
50+ const windowHeight = window . innerHeight ;
51+
52+ if ( ( / ^ t o p / ) . test ( data . placement ) ) {
53+ data . styles . maxHeight = top - 20 ;
54+ } else if ( ( / ^ b o t t o m / ) . test ( data . placement ) ) {
55+ data . styles . maxHeight = windowHeight - bottom - 20 ;
56+ } else if ( ( / ^ r i g h t / ) . test ( data . placement ) ) {
57+ data . styles . maxWidth = windowWidth - right - 30 ;
58+ } else {
59+ data . styles . maxWidth = left - 30 ;
60+ }
61+
62+ return data ;
63+ }
64+
3865 //
3966 // Listeners
4067
@@ -72,7 +99,8 @@ class Tooltip extends Component {
7299 anchor,
73100 tooltip,
74101 kind,
75- position
102+ position,
103+ canFlip
76104 } = this . props ;
77105
78106 return (
@@ -98,10 +126,18 @@ class Tooltip extends Component {
98126 // are shown (Quality Definitions for example).
99127 eventsEnabled = { false }
100128 modifiers = { {
129+ computeMaxHeight : {
130+ order : 851 ,
131+ enabled : true ,
132+ fn : this . computeMaxSize
133+ } ,
101134 preventOverflow : {
102135 // Fixes positioning for tooltips in the queue
103136 // and likely others.
104137 escapeWithReference : true
138+ } ,
139+ flip : {
140+ enabled : canFlip
105141 }
106142 } }
107143 >
@@ -132,7 +168,9 @@ class Tooltip extends Component {
132168 ) }
133169 />
134170
135- < div className = { bodyClassName } >
171+ < div
172+ className = { bodyClassName }
173+ >
136174 { tooltip }
137175 </ div >
138176 </ div > :
@@ -154,13 +192,15 @@ Tooltip.propTypes = {
154192 anchor : PropTypes . node . isRequired ,
155193 tooltip : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . node ] ) . isRequired ,
156194 kind : PropTypes . oneOf ( [ kinds . DEFAULT , kinds . INVERSE ] ) ,
157- position : PropTypes . oneOf ( tooltipPositions . all )
195+ position : PropTypes . oneOf ( tooltipPositions . all ) ,
196+ canFlip : PropTypes . bool . isRequired
158197} ;
159198
160199Tooltip . defaultProps = {
161200 bodyClassName : styles . body ,
162201 kind : kinds . DEFAULT ,
163- position : tooltipPositions . TOP
202+ position : tooltipPositions . TOP ,
203+ canFlip : true
164204} ;
165205
166206export default Tooltip ;
0 commit comments