From 07b4e56e51b2213a79f3f03e036f102a9cc9a9a7 Mon Sep 17 00:00:00 2001 From: Dave Berthiaume <38862952+davebertz@users.noreply.github.com> Date: Mon, 11 Apr 2022 14:00:38 -0400 Subject: [PATCH] feat(DropDownGroup): add containerOverride prop (#786) * added containerOverride prop to DropDownGroup * containerOverride default prop to null Co-authored-by: Dave Berthiaume --- src/components/Input/DropDown/DropDownGroup.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/Input/DropDown/DropDownGroup.js b/src/components/Input/DropDown/DropDownGroup.js index 8b09b3f6..31525714 100644 --- a/src/components/Input/DropDown/DropDownGroup.js +++ b/src/components/Input/DropDown/DropDownGroup.js @@ -31,7 +31,8 @@ class DropDownGroup extends React.Component { static LAYOUT_VARIANTS = LAYOUT_VARIANTS; componentDidMount() { - document.addEventListener("click", this.handleOutsideClick); + const container = this.props.containerOverride || document; + container.addEventListener("click", this.handleOutsideClick); } static getDerivedStateFromProps(props, state) { @@ -58,7 +59,8 @@ class DropDownGroup extends React.Component { } componentWillUnmount() { - document.removeEventListener("click", this.handleOutsideClick); + const container = this.props.containerOverride || document; + container.removeEventListener("click", this.handleOutsideClick); } onClick = () => { @@ -396,7 +398,8 @@ DropDownGroup.propTypes = { onDropDownToggle: PropTypes.func, hybrid: PropTypes.bool, dropdownMenuOpen: PropTypes.func, - dropdownMenuClose: PropTypes.func + dropdownMenuClose: PropTypes.func, + containerOverride: PropTypes.node }; DropDownGroup.defaultProps = { @@ -419,7 +422,8 @@ DropDownGroup.defaultProps = { onDropDownToggle: null, hybrid: false, dropdownMenuOpen: null, - dropdownMenuClose: null + dropdownMenuClose: null, + containerOverride: null }; export default DropDownGroup;