@@ -17,12 +17,13 @@ import {
17
17
DEFAULT_TABLET_LAYOUT ,
18
18
} from "./constants" ;
19
19
import { LayoutConfiguration , SupportedWideLayout } from "./types" ;
20
- import { getLayoutType , isPersistentLayout } from "./utils" ;
20
+ import { getLayoutType , isPersistentLayout , isToggleableLayout } from "./utils" ;
21
21
22
22
/**
23
23
* @private
24
24
*/
25
25
const notInitialized = ( name : string ) => ( ) : void => {
26
+ /* istanbul ignore next */
26
27
if ( process . env . NODE_ENV !== "production" ) {
27
28
/* eslint-disable no-console */
28
29
console . warn (
@@ -91,6 +92,19 @@ export interface LayoutProviderProps extends LayoutConfiguration {
91
92
children : ReactNode ;
92
93
}
93
94
95
+ /**
96
+ * @since 2.6.0
97
+ * @private
98
+ */
99
+ function isToggleableVisible (
100
+ behavior : boolean | "toggleable" | "toggleable-mini" ,
101
+ layout : SupportedWideLayout
102
+ ) : boolean {
103
+ return typeof behavior === "string"
104
+ ? behavior === layout
105
+ : behavior && isToggleableLayout ( layout ) ;
106
+ }
107
+
94
108
/**
95
109
* Determines the current layout based on the `LayoutConfiguration` and hooks
96
110
* into the `AppSizeListener` to update on resize. This also initializes the
@@ -104,6 +118,7 @@ export function LayoutProvider({
104
118
landscapeTabletLayout = DEFAULT_LANDSCAPE_TABLET_LAYOUT ,
105
119
desktopLayout = DEFAULT_DESKTOP_LAYOUT ,
106
120
largeDesktopLayout,
121
+ defaultToggleableVisible = false ,
107
122
children,
108
123
} : LayoutProviderProps ) : ReactElement {
109
124
const appSize = useAppSize ( ) ;
@@ -119,12 +134,17 @@ export function LayoutProvider({
119
134
const isPersistent = isPersistentLayout ( layout ) ;
120
135
121
136
const { isDesktop } = appSize ;
122
- const [ visible , setVisible ] = useState ( isPersistent && isDesktop ) ;
137
+ const [ visible , setVisible ] = useState (
138
+ ( isPersistent && isDesktop ) ||
139
+ isToggleableVisible ( defaultToggleableVisible , layout )
140
+ ) ;
123
141
const prevLayout = useRef ( layout ) ;
124
142
if ( prevLayout . current !== layout ) {
125
143
prevLayout . current = layout ;
126
- if ( visible !== isPersistent ) {
127
- setVisible ( isPersistent ) ;
144
+ const nextVisible =
145
+ isPersistent || isToggleableVisible ( defaultToggleableVisible , layout ) ;
146
+ if ( visible !== nextVisible ) {
147
+ setVisible ( nextVisible ) ;
128
148
}
129
149
}
130
150
0 commit comments