File tree Expand file tree Collapse file tree 2 files changed +47
-3
lines changed Expand file tree Collapse file tree 2 files changed +47
-3
lines changed Original file line number Diff line number Diff line change @@ -10,11 +10,15 @@ import type { DrawerContextProps } from './context';
10
10
11
11
export type Placement = 'left' | 'right' | 'top' | 'bottom' ;
12
12
13
+ export interface PushConfig {
14
+ distance ?: number | string ;
15
+ }
16
+
13
17
export interface DrawerPopupProps {
14
18
prefixCls : string ;
15
19
open ?: boolean ;
16
20
inline ?: boolean ;
17
- push ?: { distance ?: number | string } ;
21
+ push ?: boolean | PushConfig ;
18
22
forceRender ?: boolean ;
19
23
autoFocus ?: boolean ;
20
24
keyboard ?: boolean ;
@@ -94,11 +98,23 @@ export default function DrawerPopup(props: DrawerPopupProps) {
94
98
} = props ;
95
99
96
100
// ============================ Push ============================
97
- const { distance } = push || { } ;
98
101
const [ pushed , setPushed ] = React . useState ( false ) ;
99
102
100
103
const parentContext = React . useContext ( DrawerContext ) ;
101
- const pushDistance = distance ?? parentContext ?. pushDistance ?? 180 ;
104
+
105
+ // Merge push distance
106
+ let pushConfig : PushConfig ;
107
+ if ( push === false ) {
108
+ pushConfig = {
109
+ distance : 0 ,
110
+ } ;
111
+ } else if ( push === true ) {
112
+ pushConfig = { } ;
113
+ } else {
114
+ pushConfig = push || { } ;
115
+ }
116
+ const pushDistance =
117
+ pushConfig ?. distance ?? parentContext ?. pushDistance ?? 180 ;
102
118
103
119
const mergedContext = React . useMemo < DrawerContextProps > (
104
120
( ) => ( {
Original file line number Diff line number Diff line change @@ -91,6 +91,34 @@ describe('rc-drawer-menu', () => {
91
91
} ) ;
92
92
} ) ;
93
93
} ) ;
94
+
95
+ it ( 'disable push' , ( ) => {
96
+ const { container } = render (
97
+ < Drawer push = { false } open getContainer = { false } >
98
+ < Drawer open />
99
+ </ Drawer > ,
100
+ ) ;
101
+
102
+ expect ( container . querySelector ( '.rc-drawer-content-wrapper' ) ) . toHaveStyle (
103
+ {
104
+ transform : '' ,
105
+ } ,
106
+ ) ;
107
+ } ) ;
108
+
109
+ it ( 'truthy' , ( ) => {
110
+ const { container } = render (
111
+ < Drawer push open getContainer = { false } >
112
+ < Drawer open />
113
+ </ Drawer > ,
114
+ ) ;
115
+
116
+ expect ( container . querySelector ( '.rc-drawer-content-wrapper' ) ) . toHaveStyle (
117
+ {
118
+ transform : 'translateX(-180px)' ,
119
+ } ,
120
+ ) ;
121
+ } ) ;
94
122
} ) ;
95
123
96
124
describe ( 'mask' , ( ) => {
You can’t perform that action at this time.
0 commit comments