@@ -116,6 +116,11 @@ export function FloatingDelayGroup(
116
116
}
117
117
118
118
interface UseGroupOptions {
119
+ /**
120
+ * Whether delay grouping should be enabled.
121
+ * @default true
122
+ */
123
+ enabled ?: boolean ;
119
124
id ?: any ;
120
125
}
121
126
@@ -129,14 +134,15 @@ export function useDelayGroup(
129
134
options : UseGroupOptions = { } ,
130
135
) : GroupContext {
131
136
const { open, onOpenChange, floatingId} = context ;
132
- const { id : optionId } = options ;
137
+ const { id : optionId , enabled = true } = options ;
133
138
const id = optionId ?? floatingId ;
134
139
135
140
const groupContext = useDelayGroupContext ( ) ;
136
141
const { currentId, setCurrentId, initialDelay, setState, timeoutMs} =
137
142
groupContext ;
138
143
139
144
useModernLayoutEffect ( ( ) => {
145
+ if ( ! enabled ) return ;
140
146
if ( ! currentId ) return ;
141
147
142
148
setState ( {
@@ -149,14 +155,15 @@ export function useDelayGroup(
149
155
if ( currentId !== id ) {
150
156
onOpenChange ( false ) ;
151
157
}
152
- } , [ id , onOpenChange , setState , currentId , initialDelay ] ) ;
158
+ } , [ enabled , id , onOpenChange , setState , currentId , initialDelay ] ) ;
153
159
154
160
useModernLayoutEffect ( ( ) => {
155
161
function unset ( ) {
156
162
onOpenChange ( false ) ;
157
163
setState ( { delay : initialDelay , currentId : null } ) ;
158
164
}
159
165
166
+ if ( ! enabled ) return ;
160
167
if ( ! currentId ) return ;
161
168
162
169
if ( ! open && currentId === id ) {
@@ -169,12 +176,22 @@ export function useDelayGroup(
169
176
170
177
unset ( ) ;
171
178
}
172
- } , [ open , setState , currentId , id , onOpenChange , initialDelay , timeoutMs ] ) ;
179
+ } , [
180
+ enabled ,
181
+ open ,
182
+ setState ,
183
+ currentId ,
184
+ id ,
185
+ onOpenChange ,
186
+ initialDelay ,
187
+ timeoutMs ,
188
+ ] ) ;
173
189
174
190
useModernLayoutEffect ( ( ) => {
191
+ if ( ! enabled ) return ;
175
192
if ( setCurrentId === NOOP || ! open ) return ;
176
193
setCurrentId ( id ) ;
177
- } , [ open , setCurrentId , id ] ) ;
194
+ } , [ enabled , open , setCurrentId , id ] ) ;
178
195
179
196
return groupContext ;
180
197
}
0 commit comments