-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
[Box] ref missing in TypeScript definition #17010
Comments
This comment has been minimized.
This comment has been minimized.
+1 for this. |
Please provide a full reproduction test case. This would help a lot 👷 . |
Here is a reproduction: https://codesandbox.io/s/strange-khorana-l4m2z In
|
This is a major issue that prevents use of animation libraries such as Greensock/GSAP. ALL MATERIAL-UI GENERATED NODES need the ability to add a ref. For others needing an interim workaround, this seems to work in TypeScript:
NOTE: Using |
This is a pretty funny issue. Ran into it recently. The material UI docs say that we can add refs to all MUI components but this central component of this ecosystem is missing the type definition for a ref? 🤣 So there's a few ways around this that I see so it's a non-blocking issue:
I hope this can be changed soon. The types for MUI are a bit too complex for me to make a pull request in my available time but I would if I could. |
Actually ref on Box is working. Just typing should be added. |
My little hack comes like this: const refElement = useRef<HTMLDivElement>();
.
.
.
<Box {...{ ref: refElement }}>
{children}
</Box> or still get typescript complained, try this: <Box {...{ ref: refElement } as any}>
{children}
</Box> |
This comment has been minimized.
This comment has been minimized.
I have faced the problem in #22876. From what I understand, we can solve the issue with: diff --git a/packages/material-ui/src/Box/Box.d.ts b/packages/material-ui/src/Box/Box.d.ts
index 2eb664df6c..7b29a250ea 100644
--- a/packages/material-ui/src/Box/Box.d.ts
+++ b/packages/material-ui/src/Box/Box.d.ts
@@ -37,6 +37,7 @@ export interface BoxProps extends ElementProps, SystemProps {
// styled API
component?: React.ElementType;
clone?: boolean;
+ ref?: React.Ref<unknown>;
// workaround for https://github.com/mui-org/material-ui/pull/15611
css?: SystemProps;
} Is there anything I'm missing? |
PR done here: #22925 |
still an issue for me. I just did: declare module '@material-ui/core/Box' {
interface BoxProps {
ref?: React.MutableRefObject<HTMLElement>;
}
} with typescript module augmentation it's simple |
@dioxmio We only solved it in v5. |
this works, too: |
Latest material-ui 4.3.2
The text was updated successfully, but these errors were encountered: