@@ -49,12 +49,14 @@ function getScrollOffset(ele, scrollContainer = document.body, type) {
4949}
5050
5151// 获取方向
52- function getDirection ( tooltip , target , placement ) {
52+ function getDirection ( tooltip , target , placement , defaultPlacement = CONFIG_PLACE . top ) {
5353 const { top, left } = getAbsPosition ( target ) ;
5454 const targetRect = target . getBoundingClientRect ( ) ;
5555
56- let main = 'top' ;
57- let vice = 'center' ;
56+ const [ p1 , p2 ] = defaultPlacement ?. split ( '-' )
57+
58+ let main = p1 || 'top' ;
59+ let vice = p2 || 'center' ;
5860
5961 if ( placement === 'auto' ) {
6062 if ( top - tooltip . offsetHeight < top - targetRect . top ) {
@@ -78,12 +80,13 @@ export function getTooltipPositionInBody(
7880 target ,
7981 placement ,
8082 scrollContainer ,
83+ defaultPlacement = CONFIG_PLACE . top ,
8184) {
8285 const { offsetWidth, offsetHeight } = tooltip ;
8386 const { left, top, right, bottom, width, height } = getAbsPosition ( target ) ;
8487
8588 const style = { } ;
86- const [ main , vice ] = getDirection ( tooltip , target , placement ) ;
89+ const [ main , vice ] = getDirection ( tooltip , target , placement , defaultPlacement ) ;
8790
8891 switch ( main ) {
8992 case CONFIG_PLACE . top :
@@ -144,7 +147,7 @@ export default class ToolView extends Component {
144147 timer = null ;
145148
146149 componentDidMount ( ) {
147- const { placement, target, scrollContainer } = this . props ;
150+ const { placement, defaultPlacement , target, scrollContainer } = this . props ;
148151 const tooltip = this . tipRef . current ;
149152
150153 setTimeout ( ( ) => {
@@ -155,8 +158,9 @@ export default class ToolView extends Component {
155158 target ,
156159 placement ,
157160 scrollContainer ,
161+ defaultPlacement ,
158162 ) ,
159- dir : getDirection ( tooltip , target , placement ) . join ( '-' ) ,
163+ dir : getDirection ( tooltip , target , placement , defaultPlacement ) . join ( '-' ) ,
160164 } ,
161165 ( ) => this . setState ( { show : true } ) ,
162166 ) ;
0 commit comments