@@ -4,6 +4,20 @@ var React = require('react');
44var focusManager = require ( '../helpers/focusManager' ) ;
55var scopeTab = require ( '../helpers/scopeTab' ) ;
66
7+ // so that our CSS is statically analyzable
8+ var CLASS_NAMES = {
9+ overlay : {
10+ base : 'ReactModal__Overlay' ,
11+ afterOpen : 'ReactModal__Overlay--after-open' ,
12+ beforeClose : 'ReactModal__Overlay--before-close' ,
13+ } ,
14+ content : {
15+ base : 'ReactModal__Content' ,
16+ afterOpen : 'ReactModal__Content--after-open' ,
17+ beforeClose : 'ReactModal__Content--before-close' ,
18+ }
19+ } ;
20+
721function stopPropagation ( event ) {
822 event . stopPropagation ( ) ;
923}
@@ -83,13 +97,8 @@ var ModalPortal = module.exports = React.createClass({
8397 focusManager . teardownScopedFocus ( ) ;
8498 } ,
8599
86- keepTabNavInside : function ( event ) {
87- var node = this . getDOMNode ( ) ;
88- scopeTab ( node , event ) ;
89- } ,
90-
91100 handleKeyDown : function ( event ) {
92- if ( event . keyCode == 9 /*tab*/ ) this . keepTabNavInside ( event ) ;
101+ if ( event . keyCode == 9 /*tab*/ ) scopeTab ( this . getDOMNode ( ) , event ) ;
93102 if ( event . keyCode == 27 /*esc*/ ) this . requestClose ( ) ;
94103 } ,
95104
@@ -113,40 +122,38 @@ var ModalPortal = module.exports = React.createClass({
113122 return ! this . props . isOpen && ! this . state . beforeClose ;
114123 } ,
115124
125+ overlayStyles : { position : 'fixed' , left : 0 , right : 0 , top : 0 , bottom : 0 } ,
126+
127+ buildClassName : function ( which ) {
128+ var className = CLASS_NAMES [ which ] . base ;
129+ if ( this . state . afterOpen )
130+ className += ' ' + CLASS_NAMES [ which ] . afterOpen ;
131+ if ( this . state . beforeClose )
132+ className += ' ' + CLASS_NAMES [ which ] . beforeClose ;
133+ return className ;
134+ } ,
135+
116136 render : function ( ) {
117- if ( this . shouldBeClosed ( ) ) {
137+ if ( this . shouldBeClosed ( ) )
118138 return < div /> ;
119- }
120- else {
121- var style = { position : 'fixed' , left : 0 , right : 0 , top : 0 , bottom : 0 } ;
122- var overlayClassName = 'ReactModal__Overlay' ;
123- var contentClassName = 'ReactModal__Content' ;
124- if ( this . state . afterOpen ) {
125- overlayClassName += ' ReactModal__Overlay--after-open' ;
126- contentClassName += ' ReactModal__Content--after-open' ;
127- }
128- if ( this . state . beforeClose ) {
129- overlayClassName += ' ReactModal__Overlay--before-close' ;
130- contentClassName += ' ReactModal__Content--before-close' ;
131- }
132- return (
139+
140+ return (
141+ < div
142+ className = { this . buildClassName ( 'overlay' ) }
143+ style = { this . overlayStyles }
144+ onClick = { this . handleOverlayClick }
145+ >
133146 < div
134- className = { overlayClassName }
135- style = { style }
136- onClick = { this . handleOverlayClick }
147+ onClick = { stopPropagation }
148+ ref = "content"
149+ onKeyDown = { this . handleKeyDown }
150+ className = { this . buildClassName ( 'content' ) }
151+ tabIndex = "-1"
137152 >
138- < div
139- onClick = { stopPropagation }
140- ref = "content"
141- onKeyDown = { this . handleKeyDown }
142- className = { contentClassName }
143- tabIndex = "-1"
144- >
145- { this . props . children }
146- </ div >
153+ { this . props . children }
147154 </ div >
148- ) ;
149- }
155+ </ div >
156+ ) ;
150157 }
151158
152159} ) ;
0 commit comments