|
1 | 1 | import classnames from 'classnames'; |
| 2 | +import FocusTrap from 'focus-trap-react'; |
2 | 3 | import PropTypes from 'prop-types'; |
3 | 4 | import ReactDOM from 'react-dom'; |
4 | 5 | import React, { Component } from 'react'; |
@@ -43,43 +44,53 @@ export class Modal extends Component { |
43 | 44 | } |
44 | 45 |
|
45 | 46 | return ReactDOM.createPortal( |
46 | | - <div |
47 | | - {...rest} |
48 | | - className={modalClasses}> |
49 | | - <div className='modal-demo-bg'> |
50 | | - <div className='fd-modal'> |
| 47 | + <FocusTrap |
| 48 | + focusTrapOptions={{ |
| 49 | + initialFocus: 'div.modal-demo-bg > span' |
| 50 | + }}> |
| 51 | + <div |
| 52 | + {...rest} |
| 53 | + className={modalClasses}> |
| 54 | + <div className='modal-demo-bg'> |
| 55 | + <span tabIndex='-1' /> |
51 | 56 | <div |
52 | | - {...contentProps} |
53 | | - className='fd-modal__content' |
54 | | - role='document'> |
55 | | - <div {...headerProps} className='fd-modal__header'> |
56 | | - <h1 {...titleProps} className='fd-modal__title'> |
57 | | - {title} |
58 | | - </h1> |
59 | | - <button |
60 | | - {...closeProps} |
61 | | - aria-label='close' |
62 | | - className='fd-button--light fd-modal__close' |
63 | | - onClick={this.handleCloseClick} /> |
| 57 | + aria-label={title} |
| 58 | + aria-modal='true' |
| 59 | + className='fd-modal' |
| 60 | + role='dialog'> |
| 61 | + <div |
| 62 | + {...contentProps} |
| 63 | + className='fd-modal__content' |
| 64 | + role='document'> |
| 65 | + <div {...headerProps} className='fd-modal__header'> |
| 66 | + <h1 {...titleProps} className='fd-modal__title'> |
| 67 | + {title} |
| 68 | + </h1> |
| 69 | + <button |
| 70 | + {...closeProps} |
| 71 | + aria-label='close' |
| 72 | + className='fd-button--light fd-modal__close' |
| 73 | + onClick={this.handleCloseClick} /> |
| 74 | + </div> |
| 75 | + <div {...bodyProps} className='fd-modal__body'> |
| 76 | + {children} |
| 77 | + </div> |
| 78 | + {actions ? ( |
| 79 | + <footer |
| 80 | + {...footerProps} |
| 81 | + className='fd-modal__footer'> |
| 82 | + <div className='fd-modal__actions'> |
| 83 | + {actions} |
| 84 | + </div> |
| 85 | + </footer> |
| 86 | + ) : ( |
| 87 | + '' |
| 88 | + )} |
64 | 89 | </div> |
65 | | - <div {...bodyProps} className='fd-modal__body'> |
66 | | - {children} |
67 | | - </div> |
68 | | - {actions ? ( |
69 | | - <footer |
70 | | - {...footerProps} |
71 | | - className='fd-modal__footer'> |
72 | | - <div className='fd-modal__actions'> |
73 | | - {actions} |
74 | | - </div> |
75 | | - </footer> |
76 | | - ) : ( |
77 | | - '' |
78 | | - )} |
79 | 90 | </div> |
80 | 91 | </div> |
81 | 92 | </div> |
82 | | - </div>, |
| 93 | + </FocusTrap >, |
83 | 94 | this.bodyElm |
84 | 95 | ); |
85 | 96 | } |
|
0 commit comments