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

[material-ui][Dialog] Fix crashing of DraggableDialog demo #44747

Merged
merged 6 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion docs/data/material/components/dialogs/DraggableDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import Paper from '@mui/material/Paper';
import Draggable from 'react-draggable';

function PaperComponent(props) {
const nodeRef = React.useRef(null);
return (
<Draggable
nodeRef={nodeRef}
handle="#draggable-dialog-title"
cancel={'[class*="MuiDialogContent-root"]'}
>
<Paper {...props} />
<Paper {...props} ref={nodeRef} />
</Draggable>
);
}
Expand Down
4 changes: 3 additions & 1 deletion docs/data/material/components/dialogs/DraggableDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import Paper, { PaperProps } from '@mui/material/Paper';
import Draggable from 'react-draggable';

function PaperComponent(props: PaperProps) {
const nodeRef = React.useRef<HTMLDivElement>(null);
return (
<Draggable
nodeRef={nodeRef as React.RefObject<HTMLDivElement>}
Copy link
Contributor Author

@sai6855 sai6855 Dec 12, 2024

Choose a reason for hiding this comment

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

nodeRef doesn't accept a null type. If null is removed from the nodeRef declaration, TypeScript throws an error in the Paper component. So i used type assertion as a workaround.

Copy link
Member

Choose a reason for hiding this comment

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

FYI there's an open issue and PR in the react-draggable repo about this TS error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, FYI react-draggable last published version is on last year. I'm not sure if we have to wait for them to merge the PR.

https://www.npmjs.com/package/react-draggable

Copy link
Member

Choose a reason for hiding this comment

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

Yeah! My intention wasn't for us to wait, just to be aware of it.

handle="#draggable-dialog-title"
cancel={'[class*="MuiDialogContent-root"]'}
>
<Paper {...props} />
<Paper {...props} ref={nodeRef} />
</Draggable>
);
}
Expand Down
Loading