1
+ /* eslint-disable jsx-a11y/no-noninteractive-tabindex */
1
2
/**
2
3
* Terms component which displays modal window with term details
3
4
*/
@@ -9,6 +10,7 @@ import React from 'react';
9
10
import PT from 'prop-types' ;
10
11
import { Modal , PrimaryButton , Button } from 'topcoder-react-ui-kit' ;
11
12
import LoadingIndicator from 'components/LoadingIndicator' ;
13
+ import FocusTrap from 'focus-trap-react' ;
12
14
import TermDetails from './TermDetails' ;
13
15
14
16
import style from './styles.scss' ;
@@ -54,6 +56,7 @@ export default class Terms extends React.Component {
54
56
this . resizeHandler = this . resizeHandler . bind ( this ) ;
55
57
this . nextTerm = this . nextTerm . bind ( this ) ;
56
58
this . max = 0 ;
59
+ this . terms = React . createRef ( ) ;
57
60
}
58
61
59
62
componentDidMount ( ) {
@@ -63,6 +66,7 @@ export default class Terms extends React.Component {
63
66
}
64
67
window . addEventListener ( 'message' , this . messageHandler , false ) ;
65
68
window . addEventListener ( 'resize' , this . resizeHandler , false ) ;
69
+ this . terms . current . focus ( ) ;
66
70
}
67
71
68
72
componentWillReceiveProps ( nextProps ) {
@@ -83,6 +87,10 @@ export default class Terms extends React.Component {
83
87
}
84
88
}
85
89
90
+ componentDidUpdate ( ) {
91
+ this . terms . current . focus ( ) ;
92
+ }
93
+
86
94
componentWillUnmount ( ) {
87
95
window . removeEventListener ( 'message' , this . messageHandler ) ;
88
96
window . removeEventListener ( 'resize' , this . resizeHandler ) ;
@@ -152,17 +160,18 @@ export default class Terms extends React.Component {
152
160
153
161
return (
154
162
< div key = { ( selectedTerm || { } ) . termsOfUseId } >
155
- < Modal
156
- onCancel = { onCancel }
157
- theme = { { container : style [ 'modal-container' ] } }
158
- >
159
- {
163
+ < FocusTrap >
164
+ < Modal
165
+ onCancel = { onCancel }
166
+ theme = { { container : style [ 'modal-container' ] } }
167
+ >
168
+ {
160
169
isLoadingTerms
161
170
&& < LoadingIndicator />
162
171
}
163
- {
172
+ {
164
173
! isLoadingTerms && (
165
- < div styleName = "modal-content" >
174
+ < div styleName = "modal-content" ref = { this . terms } tabIndex = "0" >
166
175
< div styleName = "title" >
167
176
{ terms . length > 1 ? defaultTitle : terms [ 0 ] . title }
168
177
</ div >
@@ -216,6 +225,8 @@ export default class Terms extends React.Component {
216
225
</ div >
217
226
< div
218
227
styleName = "tab-title"
228
+ tabIndex = "0"
229
+ role = "tab"
219
230
onClick = { ( ) => this . selectTerm ( t ) }
220
231
onKeyPress = { ( ) => this . selectTerm ( t ) }
221
232
>
@@ -318,7 +329,8 @@ export default class Terms extends React.Component {
318
329
</ div >
319
330
)
320
331
}
321
- </ Modal >
332
+ </ Modal >
333
+ </ FocusTrap >
322
334
</ div >
323
335
) ;
324
336
}
0 commit comments