Skip to content
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

feat(Popup): new prop closeOnScroll close popup when scroll outside of it #21453

Merged
merged 3 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/fluentui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Use shadow8 for better contrast of `Tooltip` @jurokapsiar ([#21316](https://github.com/microsoft/fluentui/pull/21316))
- `FocusTrapZone`: add handleRef method instead of function to prevent calling it on each re-render @annabratseiko ([#21337](https://github.com/microsoft/fluentui/pull/21337))

### Features
- Add new Popup prop `closeOnScroll` to close popup when scroll happens outside of the popover element @yuanboxue-amber ([#21453](https://github.com/microsoft/fluentui/pull/21453))

<!--------------------------------[ v0.60.1 ]------------------------------- -->
## [v0.60.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-northstar_v0.60.1) (2022-01-17)
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-northstar_v0.60.0..@fluentui/react-northstar_v0.60.1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ export interface PopupProps

/** Controls whether or not auto focus should be applied, using boolean or AutoFocusZoneProps type value. */
autoFocus?: boolean | AutoFocusZoneProps;

/** Close the popup when scroll happens outside of Popup */
closeOnScroll?: boolean;
}

export const popupClassName = 'ui-popup';
Expand Down Expand Up @@ -170,6 +173,7 @@ export const Popup: React.FC<PopupProps> &
unstable_disableTether,
unstable_pinned,
autoSize,
closeOnScroll,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's have a test in cypress for this, it should be pretty straightforward to trigger a scroll event on the window

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done :)

} = props;

const [open, setOpen] = useAutoControlled({
Expand Down Expand Up @@ -477,7 +481,7 @@ export const Popup: React.FC<PopupProps> &
capture
/>

{isOpenedByRightClick && (
{(isOpenedByRightClick || closeOnScroll) && (
<>
<EventListener listener={dismissOnScroll} target={context.target} type="wheel" capture />
<EventListener listener={dismissOnScroll} target={context.target} type="touchmove" capture />
Expand Down Expand Up @@ -685,6 +689,7 @@ Popup.propTypes = {
contentRef: customPropTypes.ref,
trapFocus: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
autoFocus: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
closeOnScroll: PropTypes.bool,
};
Popup.defaultProps = {
accessibility: popupBehavior,
Expand Down