Skip to content

Commit 089beac

Browse files
authored
feat(Popup): add transition callbacks (#1388)
1 parent 8eb741f commit 089beac

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/components/Popup/Popup.tsx

+44-2
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,59 @@ export type PopupPlacement = PopperPlacement;
2121
export type PopupAnchorRef = PopperAnchorRef;
2222

2323
export interface PopupProps extends DOMProps, LayerExtendableProps, PopperProps, QAProps {
24-
open?: boolean;
2524
children?: React.ReactNode;
25+
/** Manages `Popup` visibility */
26+
open?: boolean;
27+
/** `Popup` will not be removed from the DOM upon hiding */
2628
keepMounted?: boolean;
29+
/** Render an arrow pointing to the anchor */
2730
hasArrow?: boolean;
31+
/** Do not use `LayerManager` on stacking popups */
2832
disableLayer?: boolean;
2933
/** @deprecated Add onClick handler to children */
3034
onClick?: React.MouseEventHandler<HTMLDivElement>;
35+
/** `mouseenter` event handler */
3136
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
37+
/** `mouseleave` event handler */
3238
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
39+
/** `focus` event handler */
3340
onFocus?: React.FocusEventHandler<HTMLDivElement>;
41+
/** `blur` event handler */
3442
onBlur?: React.FocusEventHandler<HTMLDivElement>;
43+
/** On start open popup animation void callback */
44+
onTransitionEnter?: VoidFunction;
45+
/** On finish open popup animation void callback */
46+
onTransitionEntered?: VoidFunction;
47+
/** On start close popup animation void callback */
48+
onTransitionExit?: VoidFunction;
49+
/** On finish close popup animation void callback */
50+
onTransitionExited?: VoidFunction;
51+
/** Do not use `Portal` for children */
3552
disablePortal?: boolean;
53+
/** DOM element children to be mounted to */
3654
container?: HTMLElement;
55+
/** HTML `class` attribute for content node */
3756
contentClassName?: string;
57+
/** If true, the focus will return to the anchor element */
3858
restoreFocus?: boolean;
59+
/** Element the focus will be restored to, depends on `restoreFocus` */
3960
restoreFocusRef?: React.RefObject<HTMLElement>;
61+
/** `aria-label` attribute, use this attribute only if you didn't have visible caption */
4062
'aria-label'?: React.AriaAttributes['aria-label'];
63+
/** `aria-labelledby` attribute, prefer this attribute if you have visible caption */
4164
'aria-labelledby'?: React.AriaAttributes['aria-labelledby'];
65+
/** `aria-role` attribute */
4266
role?: React.AriaRole;
67+
/** HTML `id` attribute */
4368
id?: string;
69+
/** Enable focus trapping behavior */
4470
focusTrap?: boolean;
71+
/** While open, the focus will be set to the first interactive element in the content */
4572
autoFocus?: boolean;
4673
}
4774

4875
const b = block('popup');
4976
const ARROW_SIZE = 8;
50-
5177
export function Popup({
5278
keepMounted = false,
5379
hasArrow = false,
@@ -71,6 +97,10 @@ export function Popup({
7197
onMouseLeave,
7298
onFocus,
7399
onBlur,
100+
onTransitionEnter,
101+
onTransitionEntered,
102+
onTransitionExit,
103+
onTransitionExited,
74104
disablePortal,
75105
container,
76106
strategy,
@@ -132,6 +162,18 @@ export function Popup({
132162
mountOnEnter={!keepMounted}
133163
unmountOnExit={!keepMounted}
134164
appear={true}
165+
onEnter={() => {
166+
onTransitionEnter?.();
167+
}}
168+
onEntered={() => {
169+
onTransitionEntered?.();
170+
}}
171+
onExit={() => {
172+
onTransitionExit?.();
173+
}}
174+
onExited={() => {
175+
onTransitionExited?.();
176+
}}
135177
>
136178
<div
137179
ref={handleRef}

src/components/Popup/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ LANDING_BLOCK-->
110110
| onMouseEnter | `mouseenter` event handler | `Function` | |
111111
| onMouseLeave | `mouseleave` event handler | `Function` | |
112112
| onOutsideClick | Outside click event handler | `Function` | |
113+
| onTransitionEnter | On start open popup animation | `Function` | |
114+
| onTransitionEntered | On finish open popup animation | `Function` | |
115+
| onTransitionExit | On start close popup animation | `Function` | |
116+
| onTransitionExited | On finish close popup animation | `Function` | |
113117
| open | Manages `Popup` visibility | `boolean` | `false` |
114118
| placement | `Popper.js` placement | `PopupPlacement` `Array<PopupPlacement>` | |
115119
| qa | Test attribute (`data-qa`) | `string` | |

0 commit comments

Comments
 (0)