File tree Expand file tree Collapse file tree
react-common/components/controls Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -61,9 +61,34 @@ export const Modal = (props: ModalProps) => {
6161 className
6262 ) ;
6363
64+ const modalRef = React . useRef < HTMLDivElement > ( null ) ;
65+
66+ React . useEffect ( ( ) => {
67+ const root = parentElement || document . body ;
68+ const parent = modalRef . current ?. parentElement ;
69+
70+ const hiddenSiblings : Element [ ] = [ ] ;
71+
72+ for ( const child of root . children ) {
73+ if ( child !== parent ) {
74+ if ( ! child . hasAttribute ( "aria-hidden" ) || child . getAttribute ( "aria-hidden" ) === "false" ) {
75+ ( child as HTMLElement ) . setAttribute ( "aria-hidden" , "true" ) ;
76+ hiddenSiblings . push ( child ) ;
77+ }
78+ }
79+ }
80+
81+ return ( ) => {
82+ for ( const child of hiddenSiblings ) {
83+ ( child as HTMLElement ) . removeAttribute ( "aria-hidden" ) ;
84+ }
85+ } ;
86+ } , [ parentElement ] )
87+
6488 return ReactDOM . createPortal ( < FocusTrap className = { classes } onEscape = { closeClickHandler } >
6589 < div id = { id }
6690 className = "common-modal"
91+ ref = { modalRef }
6792 role = { role || "dialog" }
6893 aria-hidden = { ariaHidden }
6994 aria-label = { ariaLabel }
@@ -131,5 +156,5 @@ export const Modal = (props: ModalProps) => {
131156 </ div >
132157 }
133158 </ div >
134- </ FocusTrap > , parentElement || document . getElementById ( "root" ) || document . body )
159+ </ FocusTrap > , parentElement || document . body )
135160}
You can’t perform that action at this time.
0 commit comments