File tree 2 files changed +37
-1
lines changed
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -502,4 +502,34 @@ describe('modal', () => {
502
502
expect ( onAnimationEnd ) . toHaveBeenCalledTimes ( 1 ) ;
503
503
} ) ;
504
504
} ) ;
505
+
506
+ describe ( 'prop: containerId' , ( ) => {
507
+ it ( 'should renders container div with id' , async ( ) => {
508
+ const containerId = 'container-id' ;
509
+ const { getByTestId } = render (
510
+ < Modal open onClose = { ( ) => null } containerId = { containerId } >
511
+ < div > modal content</ div >
512
+ </ Modal >
513
+ ) ;
514
+
515
+ const containerModal = getByTestId ( 'modal-container' ) ;
516
+ expect ( containerModal . getAttribute ( 'id' ) ) . toBe ( containerId ) ;
517
+ expect ( document . getElementById ( containerId ) ) . toBeInTheDocument ( ) ;
518
+ } ) ;
519
+ } ) ;
520
+
521
+ describe ( 'prop: modalId' , ( ) => {
522
+ it ( 'should renders modal div with id' , async ( ) => {
523
+ const modalId = 'modal-id' ;
524
+ const { getByTestId } = render (
525
+ < Modal open onClose = { ( ) => null } modalId = { modalId } >
526
+ < div > modal content</ div >
527
+ </ Modal >
528
+ ) ;
529
+
530
+ const modal = getByTestId ( 'modal' ) ;
531
+ expect ( modal . getAttribute ( 'id' ) ) . toBe ( modalId ) ;
532
+ expect ( document . getElementById ( modalId ) ) . toBeInTheDocument ( ) ;
533
+ } ) ;
534
+ } ) ;
505
535
} ) ;
Original file line number Diff line number Diff line change @@ -129,9 +129,13 @@ export interface ModalProps {
129
129
*/
130
130
ariaDescribedby ?: string ;
131
131
/**
132
- * Avoid unpleasant flickering effect when body overflow is hidden. For more information see https://www.npmjs.com/package/body-scroll-lock
132
+ * Avoid unpleasant flickering effect when body overflow is hidden. For more information see https://www.npmjs.com/package/body-scroll-lock
133
133
*/
134
134
reserveScrollBarGap ?: boolean ;
135
+ /**
136
+ * id attribute for modal container
137
+ */
138
+ containerId ?: string ;
135
139
/**
136
140
* id attribute for modal
137
141
*/
@@ -177,6 +181,7 @@ export const Modal = React.forwardRef(
177
181
role = 'dialog' ,
178
182
ariaDescribedby,
179
183
ariaLabelledby,
184
+ containerId,
180
185
modalId,
181
186
onClose,
182
187
onEscKeyDown,
@@ -322,6 +327,7 @@ export const Modal = React.forwardRef(
322
327
/>
323
328
< div
324
329
ref = { refModal }
330
+ id = { containerId }
325
331
className = { cx (
326
332
classes . modalContainer ,
327
333
center && classes . modalContainerCenter ,
You can’t perform that action at this time.
0 commit comments