11/*eslint-disable react/prop-types */
22import React , { cloneElement } from 'react' ;
3+ import warning from 'warning' ;
34import elementType from 'react-prop-types/lib/elementType' ;
45
56import Portal from './Portal' ;
@@ -154,11 +155,16 @@ const Modal = React.createClass({
154155 return null ;
155156 }
156157
157- if ( dialog . props . role === undefined ) {
158- dialog = cloneElement ( dialog , { role : 'document' } ) ;
158+ let { role, tabIndex } = dialog . props ;
159+
160+ if ( role === undefined || tabIndex === undefined ) {
161+ dialog = cloneElement ( dialog , {
162+ role : role === undefined ? 'document' : role ,
163+ tabIndex : tabIndex == null ? '-1' : tabIndex
164+ } ) ;
159165 }
160166
161- if ( Transition ) {
167+ if ( Transition ) {
162168 dialog = (
163169 < Transition
164170 transitionAppear
@@ -180,7 +186,6 @@ const Modal = React.createClass({
180186 return (
181187 < Portal container = { props . container } >
182188 < div
183- tabIndex = '-1'
184189 ref = { 'modal' }
185190 role = { props . role || 'dialog' }
186191 style = { props . style }
@@ -318,20 +323,28 @@ const Modal = React.createClass({
318323 }
319324 } ,
320325
321- checkForFocus ( ) {
326+ checkForFocus ( ) {
322327 if ( canUseDom ) {
323328 this . lastFocus = activeElement ( ) ;
324329 }
325330 } ,
326331
327332 focus ( ) {
328333 let autoFocus = this . props . autoFocus ;
329- let modalContent = React . findDOMNode ( this . refs . modal ) ;
334+ let modalContent = this . getDialogElement ( ) ;
330335 let current = activeElement ( ownerDocument ( this ) ) ;
331336 let focusInModal = current && contains ( modalContent , current ) ;
332337
333338 if ( modalContent && autoFocus && ! focusInModal ) {
334339 this . lastFocus = current ;
340+
341+ if ( ! modalContent . hasAttribute ( 'tabIndex' ) ) {
342+ modalContent . setAttribute ( 'tabIndex' , - 1 ) ;
343+ warning ( false ,
344+ 'The modal content node does not accept focus. ' +
345+ 'For the benefit of assistive technologies, the tabIndex of the node is being set to "-1".' ) ;
346+ }
347+
335348 modalContent . focus ( ) ;
336349 }
337350 } ,
@@ -352,9 +365,9 @@ const Modal = React.createClass({
352365 }
353366
354367 let active = activeElement ( ownerDocument ( this ) ) ;
355- let modal = React . findDOMNode ( this . refs . modal ) ;
368+ let modal = this . getDialogElement ( ) ;
356369
357- if ( modal && modal !== active && ! contains ( modal , active ) ) {
370+ if ( modal && modal !== active && ! contains ( modal , active ) ) {
358371 modal . focus ( ) ;
359372 }
360373 } ,
0 commit comments