@@ -11,6 +11,14 @@ import Arrow from './Arrow';
11
11
import Mask from './Mask' ;
12
12
import PopupContent from './PopupContent' ;
13
13
14
+ export interface MobileConfig {
15
+ mask ?: boolean ;
16
+ /** Set popup motion. You can ref `rc-motion` for more info. */
17
+ motion ?: CSSMotionProps ;
18
+ /** Set mask motion. You can ref `rc-motion` for more info. */
19
+ maskMotion ?: CSSMotionProps ;
20
+ }
21
+
14
22
export interface PopupProps {
15
23
prefixCls : string ;
16
24
className ?: string ;
@@ -63,6 +71,9 @@ export interface PopupProps {
63
71
stretch ?: string ;
64
72
targetWidth ?: number ;
65
73
targetHeight ?: number ;
74
+
75
+ // Mobile
76
+ mobile ?: MobileConfig ;
66
77
}
67
78
68
79
const Popup = React . forwardRef < HTMLDivElement , PopupProps > ( ( props , ref ) => {
@@ -95,6 +106,9 @@ const Popup = React.forwardRef<HTMLDivElement, PopupProps>((props, ref) => {
95
106
motion,
96
107
maskMotion,
97
108
109
+ // Mobile
110
+ mobile,
111
+
98
112
// Portal
99
113
forceRender,
100
114
getPopupContainer,
@@ -126,6 +140,24 @@ const Popup = React.forwardRef<HTMLDivElement, PopupProps>((props, ref) => {
126
140
// We can not remove holder only when motion finished.
127
141
const isNodeVisible = open || keepDom ;
128
142
143
+ // ========================= Mobile =========================
144
+ const isMobile = ! ! mobile ;
145
+
146
+ // ========================== Mask ==========================
147
+ const [ mergedMask , mergedMaskMotion , mergedPopupMotion ] = React . useMemo <
148
+ [
149
+ mask : boolean ,
150
+ maskMotion : CSSMotionProps | undefined ,
151
+ popupMotion : CSSMotionProps | undefined ,
152
+ ]
153
+ > ( ( ) => {
154
+ if ( mobile ) {
155
+ return [ mobile . mask , mobile . maskMotion , mobile . motion ] ;
156
+ }
157
+
158
+ return [ mask , maskMotion , motion ] ;
159
+ } , [ mobile ] ) ;
160
+
129
161
// ======================= Container ========================
130
162
const getPopupContainerNeedParams = getPopupContainer ?. length > 0 ;
131
163
@@ -148,15 +180,17 @@ const Popup = React.forwardRef<HTMLDivElement, PopupProps>((props, ref) => {
148
180
// >>>>> Offset
149
181
const AUTO = 'auto' as const ;
150
182
151
- const offsetStyle : React . CSSProperties = {
152
- left : '-1000vw' ,
153
- top : '-1000vh' ,
154
- right : AUTO ,
155
- bottom : AUTO ,
156
- } ;
183
+ const offsetStyle : React . CSSProperties = isMobile
184
+ ? { }
185
+ : {
186
+ left : '-1000vw' ,
187
+ top : '-1000vh' ,
188
+ right : AUTO ,
189
+ bottom : AUTO ,
190
+ } ;
157
191
158
192
// Set align style
159
- if ( ready || ! open ) {
193
+ if ( ! isMobile && ( ready || ! open ) ) {
160
194
const { points } = align ;
161
195
const dynamicInset =
162
196
align . dynamicInset || ( align as any ) . _experimental ?. dynamicInset ;
@@ -209,8 +243,9 @@ const Popup = React.forwardRef<HTMLDivElement, PopupProps>((props, ref) => {
209
243
prefixCls = { prefixCls }
210
244
open = { open }
211
245
zIndex = { zIndex }
212
- mask = { mask }
213
- motion = { maskMotion }
246
+ mask = { mergedMask }
247
+ motion = { mergedMaskMotion }
248
+ mobile = { isMobile }
214
249
/>
215
250
< ResizeObserver onResize = { onAlign } disabled = { ! open } >
216
251
{ ( resizeObserverRef ) => {
@@ -222,7 +257,7 @@ const Popup = React.forwardRef<HTMLDivElement, PopupProps>((props, ref) => {
222
257
removeOnLeave = { false }
223
258
forceRender = { forceRender }
224
259
leavedClassName = { `${ prefixCls } -hidden` }
225
- { ...motion }
260
+ { ...mergedPopupMotion }
226
261
onAppearPrepare = { onPrepare }
227
262
onEnterPrepare = { onPrepare }
228
263
visible = { open }
@@ -235,7 +270,9 @@ const Popup = React.forwardRef<HTMLDivElement, PopupProps>((props, ref) => {
235
270
{ className : motionClassName , style : motionStyle } ,
236
271
motionRef ,
237
272
) => {
238
- const cls = classNames ( prefixCls , motionClassName , className ) ;
273
+ const cls = classNames ( prefixCls , motionClassName , className , {
274
+ [ `${ prefixCls } -mobile` ] : isMobile ,
275
+ } ) ;
239
276
240
277
return (
241
278
< div
0 commit comments