-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(modal): Use React portals for accessibility fixes #419
Changes from 5 commits
7ebf3f0
6ec8881
bafb042
6e4f137
b31e7ff
033515c
0b5ce67
57b8d65
ff3144b
10c16e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,9 @@ export interface ModalProps extends ModalContentProps { | |
open: boolean; | ||
} | ||
|
||
const Modal = ({open, ...modalContentProps}: ModalProps): JSX.Element | null => | ||
open ? <ModalContent {...modalContentProps} /> : null; | ||
const Modal = ({open, ...modalContentProps}: ModalProps): JSX.Element | null => { | ||
return open ? <ModalContent {...modalContentProps} /> : null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can we revert this change? |
||
}; | ||
|
||
Modal.Padding = PopupPadding; | ||
Modal.Width = ModalWidth; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import * as React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import styled from '@emotion/styled'; | ||
import {keyframes} from '@emotion/core'; | ||
import tabTrappingKey from 'focus-trap-js'; | ||
|
@@ -172,7 +173,28 @@ const ModalContent = ({ | |
} | ||
}; | ||
|
||
return ( | ||
React.useEffect(() => { | ||
const siblings = [...((document.body.children as any) as HTMLElement[])].filter( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot to make this line and https://github.com/Workday/canvas-kit/pull/419/files#diff-3fe25d4d6af6314872e682fe13b7f7ccR212 use a configurable container instead of just |
||
el => el !== modalRef.current!.parentElement | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should actually check if current is not undefined?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting... Will |
||
); | ||
const prevAriaHidden = siblings.map(el => el.getAttribute('aria-hidden')); | ||
siblings.forEach(el => { | ||
el.setAttribute('aria-hidden', 'true'); | ||
}); | ||
|
||
return () => { | ||
siblings.forEach((el, index) => { | ||
const prev = prevAriaHidden[index]; | ||
if (prev) { | ||
el.setAttribute('aria-hidden', prev); | ||
} else { | ||
el.removeAttribute('aria-hidden'); | ||
} | ||
}); | ||
}; | ||
}, []); | ||
|
||
const content = ( | ||
<Container onClick={handleOutsideClick} {...elemProps}> | ||
<Popup | ||
popupRef={modalRef} | ||
|
@@ -186,6 +208,8 @@ const ModalContent = ({ | |
</Popup> | ||
</Container> | ||
); | ||
|
||
return ReactDOM.createPortal(content, document.body); | ||
NicholasBoll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
export default ModalContent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not actually sure why this is here.