@@ -542,7 +542,10 @@ var portalClassName = exports.portalClassName = "ReactModalPortal";
542
542
var bodyOpenClassName = exports . bodyOpenClassName = "ReactModal__Body--open" ;
543
543
544
544
var isReact16 = _reactDom2 . default . createPortal !== undefined ;
545
- var createPortal = isReact16 ? _reactDom2 . default . createPortal : _reactDom2 . default . unstable_renderSubtreeIntoContainer ;
545
+
546
+ var getCreatePortal = function getCreatePortal ( ) {
547
+ return isReact16 ? _reactDom2 . default . createPortal : _reactDom2 . default . unstable_renderSubtreeIntoContainer ;
548
+ } ;
546
549
547
550
function getParentElement ( parentSelector ) {
548
551
return parentSelector ( ) ;
@@ -569,6 +572,7 @@ var Modal = function (_Component) {
569
572
} , _this . portalRef = function ( ref ) {
570
573
_this . portal = ref ;
571
574
} , _this . renderPortal = function ( props ) {
575
+ var createPortal = getCreatePortal ( ) ;
572
576
var portal = createPortal ( _this , _react2 . default . createElement ( _ModalPortal2 . default , _extends ( { defaultStyles : Modal . defaultStyles } , props ) ) , _this . node ) ;
573
577
_this . portalRef ( portal ) ;
574
578
} , _temp ) , _possibleConstructorReturn ( _this , _ret ) ;
@@ -652,6 +656,7 @@ var Modal = function (_Component) {
652
656
this . node = document . createElement ( "div" ) ;
653
657
}
654
658
659
+ var createPortal = getCreatePortal ( ) ;
655
660
return createPortal ( _react2 . default . createElement ( _ModalPortal2 . default , _extends ( {
656
661
ref : this . portalRef ,
657
662
defaultStyles : Modal . defaultStyles
@@ -1629,7 +1634,7 @@ var ModalPortal = function (_Component) {
1629
1634
1630
1635
// Remove classes.
1631
1636
1632
- classList . remove ( document . body , bodyOpenClassName ) ;
1637
+ bodyOpenClassName && classList . remove ( document . body , bodyOpenClassName ) ;
1633
1638
1634
1639
htmlOpenClassName && classList . remove ( document . getElementsByTagName ( "html" ) [ 0 ] , htmlOpenClassName ) ;
1635
1640
@@ -1843,7 +1848,7 @@ var ModalPortal = function (_Component) {
1843
1848
1844
1849
// Add classes.
1845
1850
1846
- classList . add ( document . body , bodyOpenClassName ) ;
1851
+ bodyOpenClassName && classList . add ( document . body , bodyOpenClassName ) ;
1847
1852
1848
1853
htmlOpenClassName && classList . add ( document . getElementsByTagName ( "html" ) [ 0 ] , htmlOpenClassName ) ;
1849
1854
@@ -1888,7 +1893,9 @@ var ModalPortal = function (_Component) {
1888
1893
onClick : this . handleContentOnClick ,
1889
1894
role : this . props . role ,
1890
1895
"aria-label" : this . props . contentLabel
1891
- } , this . attributesFromObject ( "aria" , this . props . aria || { } ) , this . attributesFromObject ( "data" , this . props . data || { } ) ) ,
1896
+ } , this . attributesFromObject ( "aria" , this . props . aria || { } ) , this . attributesFromObject ( "data" , this . props . data || { } ) , {
1897
+ "data-testid" : this . props . testId
1898
+ } ) ,
1892
1899
this . props . children
1893
1900
)
1894
1901
) ;
@@ -2117,6 +2124,15 @@ function scopeTab(node, event) {
2117
2124
x += shiftKey ? - 1 : 1 ;
2118
2125
}
2119
2126
2127
+ // If the tabbable element does not exist,
2128
+ // focus head/tail based on shiftKey
2129
+ if ( typeof tabbable [ x ] === "undefined" ) {
2130
+ event . preventDefault ( ) ;
2131
+ target = shiftKey ? tail : head ;
2132
+ target . focus ( ) ;
2133
+ return ;
2134
+ }
2135
+
2120
2136
event . preventDefault ( ) ;
2121
2137
2122
2138
tabbable [ x ] . focus ( ) ;
0 commit comments