@@ -44,30 +44,37 @@ export default function (e, target, node, place, effect, offset) {
44
44
45
45
// Judge if the tooltip has over the window(screen)
46
46
const outsideVertical = ( ) => {
47
- // Check for horazontal tooltip, if their vertical out of screen
48
47
let result = false
49
48
let newPlace
50
- if ( getTipOffsetTop ( 'left' ) < 0 && getTipOffsetBottom ( 'left' ) <= windowHeight ) {
49
+ if ( getTipOffsetTop ( 'left' ) < 0 &&
50
+ getTipOffsetBottom ( 'left' ) <= windowHeight &&
51
+ getTipOffsetBottom ( 'bottom' ) <= windowHeight ) {
51
52
result = true
52
53
newPlace = 'bottom'
53
- } else if ( getTipOffsetBottom ( 'left' ) > windowHeight && getTipOffsetTop ( 'left' ) >= 0 ) {
54
+ } else if ( getTipOffsetBottom ( 'left' ) > windowHeight &&
55
+ getTipOffsetTop ( 'left' ) >= 0 &&
56
+ getTipOffsetTop ( 'top' ) >= 0 ) {
54
57
result = true
55
58
newPlace = 'top'
56
59
}
57
- if ( result && outsideHorizontal ( ) . result ) result = false
58
60
return { result, newPlace}
59
61
}
60
62
const outsideLeft = ( ) => {
61
- // For horizontal tooltip, if vertical out of screen, change the vertical place
62
- let { result, newPlace} = outsideVertical ( )
63
+ let { result, newPlace} = outsideVertical ( ) // Deal with vertical as first priority
64
+ if ( result && outsideHorizontal ( ) . result ) {
65
+ return { result : false } // No need to change, if change to vertical will out of space
66
+ }
63
67
if ( ! result && getTipOffsetLeft ( 'left' ) < 0 && getTipOffsetRight ( 'right' ) <= windowWidth ) {
64
- result = true
68
+ result = true // If vertical ok, but let out of side and right won't out of side
65
69
newPlace = 'right'
66
70
}
67
71
return { result, newPlace}
68
72
}
69
73
const outsideRight = ( ) => {
70
74
let { result, newPlace} = outsideVertical ( )
75
+ if ( result && outsideHorizontal ( ) . result ) {
76
+ return { result : false } // No need to change, if change to vertical will out of space
77
+ }
71
78
if ( ! result && getTipOffsetRight ( 'right' ) > windowWidth && getTipOffsetLeft ( 'left' ) >= 0 ) {
72
79
result = true
73
80
newPlace = 'left'
@@ -78,19 +85,24 @@ export default function (e, target, node, place, effect, offset) {
78
85
const outsideHorizontal = ( ) => {
79
86
let result = false
80
87
let newPlace
81
- if ( getTipOffsetLeft ( 'top' ) < 0 && getTipOffsetRight ( 'top' ) <= windowWidth ) {
88
+ if ( getTipOffsetLeft ( 'top' ) < 0 &&
89
+ getTipOffsetRight ( 'top' ) <= windowWidth &&
90
+ getTipOffsetRight ( 'right' ) <= windowWidth ) {
82
91
result = true
83
92
newPlace = 'right'
84
- } else if ( getTipOffsetRight ( 'top' ) > windowWidth && getTipOffsetLeft ( 'top' ) >= 0 ) {
93
+ } else if ( getTipOffsetRight ( 'top' ) > windowWidth &&
94
+ getTipOffsetLeft ( 'top' ) >= 0 &&
95
+ getTipOffsetLeft ( 'left' ) >= 0 ) {
85
96
result = true
86
97
newPlace = 'left'
87
98
}
88
-
89
- if ( result && outsideVertical ( ) . result ) result = false
90
99
return { result, newPlace}
91
100
}
92
101
const outsideTop = ( ) => {
93
102
let { result, newPlace} = outsideHorizontal ( )
103
+ if ( result && outsideVertical ( ) . result ) {
104
+ return { result : false }
105
+ }
94
106
if ( ! result && getTipOffsetTop ( 'top' ) < 0 && getTipOffsetBottom ( 'bottom' ) <= windowHeight ) {
95
107
result = true
96
108
newPlace = 'bottom'
@@ -99,6 +111,9 @@ export default function (e, target, node, place, effect, offset) {
99
111
}
100
112
const outsideBottom = ( ) => {
101
113
let { result, newPlace} = outsideHorizontal ( )
114
+ if ( result && outsideVertical ( ) . result ) {
115
+ return { result : false }
116
+ }
102
117
if ( ! result && getTipOffsetBottom ( 'bottom' ) > windowHeight && getTipOffsetTop ( 'top' ) >= 0 ) {
103
118
result = true
104
119
newPlace = 'top'
0 commit comments