File tree 5 files changed +15
-6
lines changed
5 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -79,9 +79,9 @@ import ReactModal from 'react-modal';
79
79
80
80
bodyOpenClassName= {
81
81
" ReactModal__Body--open"
82
- /* String className to be applied to the document.body
82
+ /* String className to be applied to the document.body
83
83
(must be a constant string).
84
- This attribute when set as `null` doesn't add any class
84
+ This attribute when set as `null` doesn't add any class
85
85
to document.body.
86
86
See the `Styles` section for more details. */ }
87
87
@@ -121,6 +121,11 @@ import ReactModal from 'react-modal';
121
121
to be applied if desired.
122
122
This attribute is `dialog` by default. */ }
123
123
124
+ preventScroll= {
125
+ false
126
+ /* Boolean indicating if the modal should use the preventScroll flag when
127
+ restoring focus to the element that had focus prior to its display. */ }
128
+
124
129
parentSelector= {
125
130
() => document .body
126
131
/* Function that will be called to get the parent element
@@ -136,7 +141,7 @@ import ReactModal from 'react-modal';
136
141
data= {
137
142
{ background: " green" }
138
143
/* Additional data attributes (optional). */ }
139
-
144
+
140
145
testId= {
141
146
" "
142
147
/* String testId that renders a data-testid attribute in the DOM,
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ export default () => {
51
51
props . closeTimeoutMS . should . be . eql ( 0 ) ;
52
52
props . shouldFocusAfterRender . should . be . ok ( ) ;
53
53
props . shouldCloseOnOverlayClick . should . be . ok ( ) ;
54
+ props . preventScroll . should . be . false ( ) ;
54
55
ReactDOM . unmountComponentAtNode ( node ) ;
55
56
ariaAppHider . resetForTesting ( ) ;
56
57
Modal . setAppElement ( document . body ) ; // restore default
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ class Modal extends Component {
60
60
shouldFocusAfterRender : PropTypes . bool ,
61
61
shouldCloseOnOverlayClick : PropTypes . bool ,
62
62
shouldReturnFocusAfterClose : PropTypes . bool ,
63
+ preventScroll : PropTypes . bool ,
63
64
parentSelector : PropTypes . func ,
64
65
aria : PropTypes . object ,
65
66
data : PropTypes . object ,
@@ -82,6 +83,7 @@ class Modal extends Component {
82
83
shouldCloseOnEsc : true ,
83
84
shouldCloseOnOverlayClick : true ,
84
85
shouldReturnFocusAfterClose : true ,
86
+ preventScroll : false ,
85
87
parentSelector : ( ) => document . body
86
88
} ;
87
89
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ export default class ModalPortal extends Component {
51
51
shouldFocusAfterRender : PropTypes . bool ,
52
52
shouldCloseOnOverlayClick : PropTypes . bool ,
53
53
shouldReturnFocusAfterClose : PropTypes . bool ,
54
+ preventScroll : PropTypes . bool ,
54
55
role : PropTypes . string ,
55
56
contentLabel : PropTypes . string ,
56
57
aria : PropTypes . object ,
@@ -185,7 +186,7 @@ export default class ModalPortal extends Component {
185
186
186
187
if ( this . props . shouldFocusAfterRender ) {
187
188
if ( this . props . shouldReturnFocusAfterClose ) {
188
- focusManager . returnFocus ( ) ;
189
+ focusManager . returnFocus ( this . props . preventScroll ) ;
189
190
focusManager . teardownScopedFocus ( ) ;
190
191
} else {
191
192
focusManager . popWithoutFocus ( ) ;
Original file line number Diff line number Diff line change @@ -34,12 +34,12 @@ export function markForFocusLater() {
34
34
}
35
35
36
36
/* eslint-disable no-console */
37
- export function returnFocus ( ) {
37
+ export function returnFocus ( preventScroll = false ) {
38
38
let toFocus = null ;
39
39
try {
40
40
if ( focusLaterElements . length !== 0 ) {
41
41
toFocus = focusLaterElements . pop ( ) ;
42
- toFocus . focus ( ) ;
42
+ toFocus . focus ( { preventScroll } ) ;
43
43
}
44
44
return ;
45
45
} catch ( e ) {
You can’t perform that action at this time.
0 commit comments