File tree Expand file tree Collapse file tree 4 files changed +23
-4
lines changed
Expand file tree Collapse file tree 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';
112112 labelledby: " heading" ,
113113 describedby: " full_description"
114114 }}
115+ /*
116+ Additional data attributes (optional).
117+ */
118+ data= {{
119+ background: " green"
120+ }}
115121 /*
116122 Overlay ref callback.
117123 */
Original file line number Diff line number Diff line change @@ -393,6 +393,17 @@ export default () => {
393393 unmountModal ( ) ;
394394 } ) ;
395395
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+
396407 it ( "raises an exception if the appElement selector does not match" , ( ) => {
397408 should ( ( ) => ariaAppHider . setElement ( ".test" ) ) . throw ( ) ;
398409 } ) ;
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ class Modal extends Component {
6060 shouldReturnFocusAfterClose : PropTypes . bool ,
6161 parentSelector : PropTypes . func ,
6262 aria : PropTypes . object ,
63+ data : PropTypes . object ,
6364 role : PropTypes . string ,
6465 contentLabel : PropTypes . string ,
6566 shouldCloseOnEsc : PropTypes . bool ,
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ export default class ModalPortal extends Component {
5151 role : PropTypes . string ,
5252 contentLabel : PropTypes . string ,
5353 aria : PropTypes . object ,
54+ data : PropTypes . object ,
5455 children : PropTypes . node ,
5556 shouldCloseOnEsc : PropTypes . bool ,
5657 overlayRef : PropTypes . func ,
@@ -315,9 +316,9 @@ export default class ModalPortal extends Component {
315316 : className ;
316317 } ;
317318
318- ariaAttributes = items =>
319+ attributesFromObject = ( prefix , items ) =>
319320 Object . keys ( items ) . reduce ( ( acc , name ) => {
320- acc [ `aria -${ name } ` ] = items [ name ] ;
321+ acc [ `${ prefix } -${ name } ` ] = items [ name ] ;
321322 return acc ;
322323 } , { } ) ;
323324
@@ -346,8 +347,8 @@ export default class ModalPortal extends Component {
346347 onClick = { this . handleContentOnClick }
347348 role = { this . props . role }
348349 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 || { } ) }
351352 >
352353 { this . props . children }
353354 </ div >
You can’t perform that action at this time.
0 commit comments