@@ -23,8 +23,6 @@ import classNames from 'classnames';
2323
2424import UIStore from "../../../stores/UIStore" ;
2525
26- const MIN_TOOLTIP_HEIGHT = 25 ;
27-
2826export enum Alignment {
2927 Natural , // Pick left or right
3028 Left ,
@@ -33,7 +31,6 @@ export enum Alignment {
3331 Bottom , // Centered
3432 InnerBottom , // Inside the target, at the bottom
3533 TopRight , // On top of the target, right aligned
36- TopCenter , // On top of the target, center aligned
3734}
3835
3936export interface ITooltipProps {
@@ -48,7 +45,6 @@ export interface ITooltipProps {
4845 // the react element to put into the tooltip
4946 label : React . ReactNode ;
5047 alignment ?: Alignment ; // defaults to Natural
51- yOffset ?: number ;
5248 // id describing tooltip
5349 // used to associate tooltip with target for a11y
5450 id ?: string ;
@@ -66,7 +62,6 @@ export default class Tooltip extends React.Component<ITooltipProps> {
6662
6763 public static readonly defaultProps = {
6864 visible : true ,
69- yOffset : 0 ,
7065 alignment : Alignment . Natural ,
7166 } ;
7267
@@ -102,65 +97,60 @@ export default class Tooltip extends React.Component<ITooltipProps> {
10297 // positioned, also taking into account any window zoom
10398 private updatePosition ( style : CSSProperties ) {
10499 const parentBox = this . parent . getBoundingClientRect ( ) ;
105- let offset = 0 ;
106- if ( parentBox . height > MIN_TOOLTIP_HEIGHT ) {
107- offset = Math . floor ( ( parentBox . height - MIN_TOOLTIP_HEIGHT ) / 2 ) ;
108- } else {
109- // The tooltip is larger than the parent height: figure out what offset
110- // we need so that we're still centered.
111- offset = Math . floor ( parentBox . height - MIN_TOOLTIP_HEIGHT ) ;
112- }
113100 const width = UIStore . instance . windowWidth ;
101+ const spacing = 6 ;
114102 const parentWidth = (
115103 this . props . maxParentWidth
116104 ? Math . min ( parentBox . width , this . props . maxParentWidth )
117105 : parentBox . width
118106 ) ;
119- const baseTop = ( parentBox . top - 2 + this . props . yOffset ) + window . scrollY ;
120- const top = baseTop + offset ;
107+ const baseTop = parentBox . top + window . scrollY ;
108+ const centerTop = parentBox . top + window . scrollY + ( parentBox . height / 2 ) ;
121109 const right = width - parentBox . left - window . scrollX ;
122110 const left = parentBox . right + window . scrollX ;
123111 const horizontalCenter = (
124112 parentBox . left - window . scrollX + ( parentWidth / 2 )
125113 ) ;
114+
126115 switch ( this . props . alignment ) {
127116 case Alignment . Natural :
128117 if ( parentBox . right > width / 2 ) {
129- style . right = right ;
130- style . top = top ;
118+ style . right = right + spacing ;
119+ style . top = centerTop ;
120+ style . transform = "translateY(-50%)" ;
131121 break ;
132122 }
133123 // fall through to Right
134124 case Alignment . Right :
135- style . left = left ;
136- style . top = top ;
125+ style . left = left + spacing ;
126+ style . top = centerTop ;
127+ style . transform = "translateY(-50%)" ;
137128 break ;
138129 case Alignment . Left :
139- style . right = right ;
140- style . top = top ;
130+ style . right = right + spacing ;
131+ style . top = centerTop ;
132+ style . transform = "translateY(-50%)" ;
141133 break ;
142134 case Alignment . Top :
143- style . top = baseTop - 16 ;
135+ style . top = baseTop - spacing ;
144136 style . left = horizontalCenter ;
137+ style . transform = "translate(-50%, -100%)" ;
145138 break ;
146139 case Alignment . Bottom :
147- style . top = baseTop + parentBox . height ;
140+ style . top = baseTop + parentBox . height + spacing ;
148141 style . left = horizontalCenter ;
142+ style . transform = "translate(-50%)" ;
149143 break ;
150144 case Alignment . InnerBottom :
151145 style . top = baseTop + parentBox . height - 50 ;
152146 style . left = horizontalCenter ;
153147 style . transform = "translate(-50%)" ;
154148 break ;
155149 case Alignment . TopRight :
156- style . top = baseTop - 5 ;
150+ style . top = baseTop - spacing ;
157151 style . right = width - parentBox . right - window . scrollX ;
158- style . transform = "translate(5px, -100%)" ;
152+ style . transform = "translateY( -100%)" ;
159153 break ;
160- case Alignment . TopCenter :
161- style . top = baseTop - 5 ;
162- style . left = horizontalCenter ;
163- style . transform = "translate(-50%, -100%)" ;
164154 }
165155
166156 return style ;
0 commit comments