Conversation
Remove keepMounted on portal child parts Remove unused imports Remove keepMounted prop in tests
Netlify deploy preview |
| const openRef = useLatestRef(open); | ||
|
|
||
| useEnhancedEffect(() => { | ||
| React.useEffect(() => { |
There was a problem hiding this comment.
Change to regular useEffect as the timing lets Motion know the exit animation styles have been applied inside a single requestAnimationFrame when checking for element.getAnimations() when keepMounted=true
| onFinished: handleUnmount, | ||
| }); | ||
|
|
||
| React.useImperativeHandle(params.unmountRef, () => ({ unmount: handleUnmount }), [handleUnmount]); |
There was a problem hiding this comment.
An API with a bunch of imperative methods could be useful in general, not just for this, so it could be named something more generic to future-proof it. This concept may be similar to using hooks, or component stores as in Ariakit. One difference is you can't "read" values in render, it's just for accessing internal methods/state inside event handlers & effects (since it's a ref).
There was a problem hiding this comment.
👍
A couple of Material UI components use this pattern and call the prop action (like https://github.com/mui/material-ui/blob/master/packages/mui-material/src/ButtonBase/ButtonBase.d.ts#L13)
Signed-off-by: atomiks <cc.glows@gmail.com>
Signed-off-by: atomiks <cc.glows@gmail.com>
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
| /** | ||
| * A ref to imperative actions. | ||
| */ | ||
| action?: React.RefObject<{ unmount: () => void }>; |
There was a problem hiding this comment.
The type of the ref should be exported so it's easy for consumers to pass a correct type to React.useRef
There was a problem hiding this comment.
Hmm, how should it be exported? Like Dialog.ActionsRef?
There was a problem hiding this comment.
Yeah, should be fine like that.
| * | ||
| * Documentation: [Base UI Menu](https://base-ui.com/react/components/menu) | ||
| */ | ||
| const MenuRoot: React.FC<MenuRoot.Props> = function MenuRoot(props) { |
There was a problem hiding this comment.
The explicit type definition was added in #705. Make sure the types are still generated correctly.
There was a problem hiding this comment.
Right, I just noticed that DialogRoot didn't have this definition, but MenuRoot did. When I checked if the Root accepted arbitrary props it didn't (TS errors). However, based on the issues, I realize this may be exclusive to consumers of the built dist files, and not our dev environment. Do you remember if there was a difference there? (If so, Dialog must currently have this issue 🤔)
There was a problem hiding this comment.
Yeah, DialogRoot has the same issue - it has propTypes in its built type definitions:
declare const DialogRoot: {
(props: DialogRoot.Props): React.JSX.Element;
propTypes: any;
};
There was a problem hiding this comment.
Fixed Roots that were missing it here
Co-authored-by: Michał Dudak <michal.dudak@gmail.com> Signed-off-by: atomiks <cc.glows@gmail.com>
|
🤔 I wonder if this is a viable method for cleanly closing menus in this situation: #1349 (comment) |
Signed-off-by: atomiks <cc.glows@gmail.com>
Closes #1160
JavaScript animations page. I focused on
Motionfairly exclusively. TheactionsRefprop holds imperative methods, currently justunmount.action.current.unmount()is for when animatingopacitydoesn't work in other libraries for the most part, asopacity: 0.9999is really the simplest solution.Motion experiments