@@ -10,7 +10,7 @@ import ModalHeader from './ModalHeader';
1010import ModalTitle from './ModalTitle' ;
1111import { MODAL_SIZES } from '../../utils/constants' ;
1212import BaseView from '../../utils/rnw-compat/BaseView' ;
13- import useModal from './useModal' ;
13+ import useModal from '../../hooks /useModal' ;
1414
1515const propTypes = {
1616 children : PropTypes . node . isRequired ,
@@ -33,7 +33,11 @@ const Modal = React.forwardRef((props, ref) => {
3333 ...elementProps
3434 } = props ;
3535
36- const modal = useModal ( visible , onToggle ) ;
36+ const modal = useModal ( visible , onToggle , {
37+ keepBodyScroll : false ,
38+ bodyClass : 'modal-open' ,
39+ centered : true ,
40+ } ) ;
3741 const waitingForMouseUp = useRef ( false ) ;
3842 const ignoreBackdropClick = useRef ( false ) ;
3943
@@ -54,69 +58,67 @@ const Modal = React.forwardRef((props, ref) => {
5458 ) ;
5559
5660 const modalElement = (
57- < BaseView
58- key = "modal"
59- ref = { ( element ) => {
60- modal . ref . current = findNodeHandle ( element ) ;
61- } }
62- accessible
63- accessibilityRole = "dialog"
64- aria-labelledby = { modal . identifier }
65- aria-modal = "true"
66- // For now we need onClick here, because onMouseDown would also toggle the modal when the user clicks on a scrollbar.
67- onClick = { ( event ) => {
68- if ( backdrop === 'static' ) {
69- return ;
70- }
71-
72- if (
73- ignoreBackdropClick . current ||
74- event . target !== event . currentTarget
75- ) {
76- ignoreBackdropClick . current = false ;
77- return ;
78- }
79-
80- modal . setVisible ( false ) ;
81- } }
82- onMouseUp = { ( event ) => {
83- if ( waitingForMouseUp . current && event . target === modal . ref . current ) {
84- ignoreBackdropClick . current = true ;
85- }
86-
87- waitingForMouseUp . current = false ;
88- } }
89- onKeyUp = { ( event ) => {
90- if ( event . key !== 'Escape' ) {
91- return ;
92- }
93-
94- event . preventDefault ( ) ;
95-
96- if ( backdrop === 'static' ) {
97- return ;
98- }
99-
100- modal . setVisible ( false ) ;
101- } }
102- essentials = { { className : 'modal show' } }
103- >
61+ < ModalContext . Provider value = { modal } key = "modal" >
10462 < BaseView
105- accessibilityRole = "document"
106- onMouseDown = { ( ) => {
107- waitingForMouseUp . current = true ;
63+ ref = { ( element ) => {
64+ modal . ref . current = findNodeHandle ( element ) ;
65+ } }
66+ accessible
67+ accessibilityRole = "dialog"
68+ aria-labelledby = { modal . identifier }
69+ aria-modal = "true"
70+ // For now we need onClick here, because onMouseDown would also toggle the modal when the user clicks on a scrollbar.
71+ onClick = { ( event ) => {
72+ if ( backdrop === 'static' ) {
73+ return ;
74+ }
75+
76+ if (
77+ ignoreBackdropClick . current ||
78+ event . target !== event . currentTarget
79+ ) {
80+ ignoreBackdropClick . current = false ;
81+ return ;
82+ }
83+
84+ modal . setVisible ( false ) ;
85+ } }
86+ onMouseUp = { ( event ) => {
87+ if ( waitingForMouseUp . current && event . target === modal . ref . current ) {
88+ ignoreBackdropClick . current = true ;
89+ }
90+
91+ waitingForMouseUp . current = false ;
92+ } }
93+ onKeyUp = { ( event ) => {
94+ if ( event . key !== 'Escape' ) {
95+ return ;
96+ }
97+
98+ event . preventDefault ( ) ;
99+
100+ if ( backdrop === 'static' ) {
101+ return ;
102+ }
103+
104+ modal . setVisible ( false ) ;
108105 } }
109- essentials = { { className : dialogClasses } }
106+ essentials = { { className : 'modal show' } }
110107 >
111- < ModalContext . Provider value = { modal } >
108+ < BaseView
109+ onMouseDown = { ( ) => {
110+ waitingForMouseUp . current = true ;
111+ } }
112+ essentials = { { className : dialogClasses } }
113+ >
112114 < BaseView
113115 { ...elementProps }
114116 ref = { ref }
115117 essentials = { { className : 'modal-content' } }
116118 />
117- </ ModalContext . Provider >
119+ </ BaseView >
118120 </ BaseView >
119- </ BaseView >
121+ </ ModalContext . Provider >
120122 ) ;
121123
122124 if ( ! backdrop ) {
0 commit comments