@@ -212,26 +212,31 @@ export default meta;
212
212
213
213
function useModal ( ) {
214
214
const [ open , toggle ] = React . useState ( true ) ;
215
+ const ref = React . useRef ( null ) ;
216
+
215
217
return {
216
218
Container : ( { children } ) => (
217
219
< >
218
220
{ open && children }
219
- < Button onClick = { ( ) => toggle ( true ) } > Open</ Button >
221
+ < Button ref = { ref } onClick = { ( ) => toggle ( true ) } >
222
+ Open
223
+ </ Button >
220
224
</ >
221
225
) ,
222
226
onClose : ( ) => {
223
227
toggle ( false ) ;
224
228
action ( "onClose" ) ( ) ;
225
229
} ,
230
+ triggerRef : ref ,
226
231
} ;
227
232
}
228
233
229
234
export const RemovableSections : Story = {
230
235
render : ( { showSection, children } ) => {
231
- const { Container, onClose } = useModal ( ) ;
236
+ const { Container, onClose, triggerRef } = useModal ( ) ;
232
237
return (
233
238
< Container >
234
- < Modal onClose = { onClose } >
239
+ < Modal triggerRef = { triggerRef } onClose = { onClose } >
235
240
< ModalHeader
236
241
title = "Enjoy something to eat while you fly"
237
242
illustration = { < Illustration name = "Meal" size = "small" /> }
@@ -277,17 +282,18 @@ export const RemovableSections: Story = {
277
282
"labelClose" ,
278
283
"lockScrolling" ,
279
284
"fixedFooter" ,
285
+ "triggerRef" ,
280
286
] ,
281
287
} ,
282
288
} ,
283
289
} ;
284
290
285
291
export const WithFixedFooter : Story = {
286
292
render : args => {
287
- const { Container, onClose } = useModal ( ) ;
293
+ const { Container, onClose, triggerRef } = useModal ( ) ;
288
294
return (
289
295
< Container >
290
- < Modal onClose = { onClose } { ...args } >
296
+ < Modal triggerRef = { triggerRef } onClose = { onClose } { ...args } >
291
297
< ModalHeader
292
298
title = "Enjoy something to eat while you fly"
293
299
illustration = { < Illustration name = "BaggageDrop" size = "small" /> }
@@ -323,6 +329,7 @@ export const WithFixedFooter: Story = {
323
329
"hasCloseButton" ,
324
330
"disableAnimation" ,
325
331
"labelClose" ,
332
+ "triggerRef" ,
326
333
"lockScrolling" ,
327
334
] ,
328
335
} ,
@@ -331,11 +338,11 @@ export const WithFixedFooter: Story = {
331
338
332
339
export const WithForm : Story = {
333
340
render : ( { showSection } ) => {
334
- const { Container, onClose } = useModal ( ) ;
341
+ const { Container, onClose, triggerRef } = useModal ( ) ;
335
342
336
343
return (
337
344
< Container >
338
- < Modal onClose = { onClose } fixedFooter >
345
+ < Modal triggerRef = { triggerRef } onClose = { onClose } fixedFooter >
339
346
< ModalHeader title = "Refund" description = "Reservation number: 123456789" />
340
347
< ModalSection >
341
348
< Stack >
@@ -402,6 +409,7 @@ export const WithForm: Story = {
402
409
"hasCloseButton" ,
403
410
"disableAnimation" ,
404
411
"labelClose" ,
412
+ "triggerRef" ,
405
413
"lockScrolling" ,
406
414
"fixedFooter" ,
407
415
] ,
@@ -411,11 +419,15 @@ export const WithForm: Story = {
411
419
412
420
export const WithItinerary : Story = {
413
421
render : ( ) => {
414
- const { Container, onClose } = useModal ( ) ;
422
+ const { Container, onClose, triggerRef } = useModal ( ) ;
415
423
416
424
return (
417
425
< Container >
418
- < Modal ariaLabel = "Itinerary from Prague to Frankfurt" onClose = { onClose } >
426
+ < Modal
427
+ triggerRef = { triggerRef }
428
+ ariaLabel = "Itinerary from Prague to Frankfurt"
429
+ onClose = { onClose }
430
+ >
419
431
< ModalSection >
420
432
< Itinerary >
421
433
< ItineraryStatus type = "success" label = "This part is new" >
@@ -457,10 +469,10 @@ export const WithItinerary: Story = {
457
469
458
470
export const WithModalHeaderOnly : Story = {
459
471
render : args => {
460
- const { Container, onClose } = useModal ( ) ;
472
+ const { Container, onClose, triggerRef } = useModal ( ) ;
461
473
return (
462
474
< Container >
463
- < Modal onClose = { onClose } { ...args } >
475
+ < Modal triggerRef = { triggerRef } onClose = { onClose } { ...args } >
464
476
< ModalHeader
465
477
title = "Enjoy something to eat while you fly"
466
478
illustration = { < Illustration name = "BaggageDrop" size = "small" /> }
@@ -488,6 +500,7 @@ export const WithModalHeaderOnly: Story = {
488
500
"hasCloseButton" ,
489
501
"disableAnimation" ,
490
502
"labelClose" ,
503
+ "triggerRef" ,
491
504
"lockScrolling" ,
492
505
] ,
493
506
} ,
@@ -508,11 +521,11 @@ export const Playground: StoryObj<PlaygroundStoryProps> = {
508
521
showSection,
509
522
...args
510
523
} ) => {
511
- const { Container, onClose } = useModal ( ) ;
524
+ const { Container, onClose, triggerRef } = useModal ( ) ;
512
525
513
526
return (
514
527
< Container >
515
- < Modal onClose = { onClose } { ...args } >
528
+ < Modal triggerRef = { triggerRef } onClose = { onClose } { ...args } >
516
529
{ header && (
517
530
< ModalHeader
518
531
title = { title }
@@ -588,18 +601,18 @@ export const Playground: StoryObj<PlaygroundStoryProps> = {
588
601
parameters : {
589
602
info : "Playground of Modal component. Check Orbit.Kiwi for more detailed design guidelines." ,
590
603
controls : {
591
- exclude : [ "children" ] ,
604
+ exclude : [ "children" , "triggerRef" ] ,
592
605
} ,
593
606
} ,
594
607
} ;
595
608
596
609
export const Rtl : Story = {
597
610
render : ( ) => {
598
- const { Container, onClose } = useModal ( ) ;
611
+ const { Container, onClose, triggerRef } = useModal ( ) ;
599
612
return (
600
613
< Container >
601
614
< RenderInRtl >
602
- < Modal onClose = { onClose } >
615
+ < Modal triggerRef = { triggerRef } onClose = { onClose } >
603
616
< ModalHeader
604
617
title = "The title of the ModalHeader"
605
618
illustration = { < Illustration name = "Accommodation" size = "small" /> }
0 commit comments