This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Modal): Add PreventModalAriaHidden component
- Loading branch information
1 parent
76b486e
commit 0f1be28
Showing
4 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import {hideOthers} from 'aria-hidden'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const PREVENT_ARIA_HIDDEN_ATTRIBUTE = 'data-prevent-aria-hidden'; | ||
|
||
// hide everything except modalElement and elements with | ||
// the PREVENT_ARIA_HIDDEN_ATTRIBUTE | ||
function hideForModal(modalElement) { | ||
return hideOthers([ | ||
modalElement, | ||
...document.querySelectorAll(`[${PREVENT_ARIA_HIDDEN_ATTRIBUTE}]`), | ||
]); | ||
} | ||
|
||
// A helper component that applies the PREVENT_ARIA_HIDDEN_ATTRIBUTE | ||
// to its (only) child component | ||
function PreventModalAriaHidden({children}) { | ||
return React.cloneElement(React.Children.only(children), { | ||
[PREVENT_ARIA_HIDDEN_ATTRIBUTE]: true, | ||
}); | ||
} | ||
PreventModalAriaHidden.propTypes = { | ||
children: PropTypes.element.isRequired, | ||
}; | ||
|
||
export {hideForModal, PreventModalAriaHidden}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters