File tree 4 files changed +23
-4
lines changed
4 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,12 @@ import ReactModal from 'react-modal';
112
112
labelledby: " heading" ,
113
113
describedby: " full_description"
114
114
}}
115
+ /*
116
+ Additional data attributes (optional).
117
+ */
118
+ data= {{
119
+ background: " green"
120
+ }}
115
121
/*
116
122
Overlay ref callback.
117
123
*/
Original file line number Diff line number Diff line change @@ -393,6 +393,17 @@ export default () => {
393
393
unmountModal ( ) ;
394
394
} ) ;
395
395
396
+ it ( "additional data attributes" , ( ) => {
397
+ const modal = renderModal (
398
+ { isOpen : true , data : { background : "green" } } ,
399
+ "hello"
400
+ ) ;
401
+ mcontent ( modal )
402
+ . getAttribute ( "data-background" )
403
+ . should . be . eql ( "green" ) ;
404
+ unmountModal ( ) ;
405
+ } ) ;
406
+
396
407
it ( "raises an exception if the appElement selector does not match" , ( ) => {
397
408
should ( ( ) => ariaAppHider . setElement ( ".test" ) ) . throw ( ) ;
398
409
} ) ;
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ class Modal extends Component {
60
60
shouldReturnFocusAfterClose : PropTypes . bool ,
61
61
parentSelector : PropTypes . func ,
62
62
aria : PropTypes . object ,
63
+ data : PropTypes . object ,
63
64
role : PropTypes . string ,
64
65
contentLabel : PropTypes . string ,
65
66
shouldCloseOnEsc : PropTypes . bool ,
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ export default class ModalPortal extends Component {
51
51
role : PropTypes . string ,
52
52
contentLabel : PropTypes . string ,
53
53
aria : PropTypes . object ,
54
+ data : PropTypes . object ,
54
55
children : PropTypes . node ,
55
56
shouldCloseOnEsc : PropTypes . bool ,
56
57
overlayRef : PropTypes . func ,
@@ -315,9 +316,9 @@ export default class ModalPortal extends Component {
315
316
: className ;
316
317
} ;
317
318
318
- ariaAttributes = items =>
319
+ attributesFromObject = ( prefix , items ) =>
319
320
Object . keys ( items ) . reduce ( ( acc , name ) => {
320
- acc [ `aria -${ name } ` ] = items [ name ] ;
321
+ acc [ `${ prefix } -${ name } ` ] = items [ name ] ;
321
322
return acc ;
322
323
} , { } ) ;
323
324
@@ -346,8 +347,8 @@ export default class ModalPortal extends Component {
346
347
onClick = { this . handleContentOnClick }
347
348
role = { this . props . role }
348
349
aria-label = { this . props . contentLabel }
349
- { ...this . ariaAttributes ( this . props . aria || { } ) }
350
- data-testid = { this . props . testId }
350
+ { ...this . attributesFromObject ( "aria" , this . props . aria || { } ) }
351
+ { ... this . attributesFromObject ( "data" , this . props . data || { } ) }
351
352
>
352
353
{ this . props . children }
353
354
</ div >
You can’t perform that action at this time.
0 commit comments