File tree Expand file tree Collapse file tree 2 files changed +41
-16
lines changed Expand file tree Collapse file tree 2 files changed +41
-16
lines changed Original file line number Diff line number Diff line change @@ -104,8 +104,11 @@ class Popup extends Component<PopupProps, PopupState> {
104
104
105
105
private nextFrameId : number = null ;
106
106
107
- static getDerivedStateFromProps ( { visible, ...props } : PopupProps , { prevVisible } : PopupState ) {
108
- const newState : Partial < PopupState > = { prevVisible : visible } ;
107
+ static getDerivedStateFromProps (
108
+ { visible, ...props } : PopupProps ,
109
+ { prevVisible, status } : PopupState ,
110
+ ) {
111
+ const newState : Partial < PopupState > = { prevVisible : visible , status } ;
109
112
110
113
const mergedMotion = getMotion ( props ) ;
111
114
@@ -115,7 +118,7 @@ class Popup extends Component<PopupProps, PopupState> {
115
118
} else if ( visible !== prevVisible ) {
116
119
newState . status = visible || supportMotion ( mergedMotion ) ? null : 'stable' ;
117
120
118
- if ( ! visible ) {
121
+ if ( visible ) {
119
122
newState . alignClassName = null ;
120
123
}
121
124
}
Original file line number Diff line number Diff line change @@ -87,24 +87,46 @@ describe('Trigger.Point', () => {
87
87
} ) ;
88
88
} ) ;
89
89
90
- it ( 'placement' , ( ) => {
91
- const builtinPlacements = {
90
+ describe ( 'placement' , ( ) => {
91
+ function testPlacement ( name , builtinPlacements , afterAll ) {
92
+ it ( name , ( ) => {
93
+ const wrapper = mount (
94
+ < Demo action = { [ 'click' ] } builtinPlacements = { builtinPlacements } popupPlacement = "right" /> ,
95
+ ) ;
96
+ wrapper . trigger ( 'click' , { pageX : 10 , pageY : 20 } ) ;
97
+
98
+ const popup = wrapper
99
+ . find ( '.rc-trigger-popup' )
100
+ . first ( )
101
+ . getDOMNode ( ) ;
102
+
103
+ expect ( popup . style ) . toEqual ( expect . objectContaining ( { left : '-989px' , top : '-979px' } ) ) ;
104
+
105
+ if ( afterAll ) {
106
+ afterAll ( wrapper ) ;
107
+ }
108
+ } ) ;
109
+ }
110
+
111
+ testPlacement ( 'not hit' , {
92
112
right : {
93
113
// This should not hit
94
114
points : [ 'cl' ] ,
95
115
} ,
96
- } ;
116
+ } ) ;
97
117
98
- const wrapper = mount (
99
- < Demo action = { [ 'click' ] } builtinPlacements = { builtinPlacements } popupPlacement = "right" /> ,
118
+ testPlacement (
119
+ 'hit' ,
120
+ {
121
+ left : {
122
+ points : [ 'tl' ] ,
123
+ } ,
124
+ } ,
125
+ wrapper => {
126
+ expect (
127
+ wrapper . find ( 'div.rc-trigger-popup' ) . hasClass ( 'rc-trigger-popup-placement-left' ) ,
128
+ ) . toBeTruthy ( ) ;
129
+ } ,
100
130
) ;
101
- wrapper . trigger ( 'click' , { pageX : 10 , pageY : 20 } ) ;
102
-
103
- const popup = wrapper
104
- . find ( '.rc-trigger-popup' )
105
- . first ( )
106
- . getDOMNode ( ) ;
107
-
108
- expect ( popup . style ) . toEqual ( expect . objectContaining ( { left : '-989px' , top : '-979px' } ) ) ;
109
131
} ) ;
110
132
} ) ;
You can’t perform that action at this time.
0 commit comments