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

fix(react): type issue in Dialog with OverridableComponent #294

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Changes from 1 commit
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
Next Next commit
fix(react): type issue in Dialog with OverridableComponent
brionmario committed Oct 21, 2024
commit adc4fc4b8fe8416711bae20cd9310c72109bbe83
10 changes: 4 additions & 6 deletions packages/react/src/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -18,10 +18,8 @@

import MuiDialog from '@mui/material/Dialog';
import type {DialogProps as MuiDialogProps} from '@mui/material/Dialog';
import type {ModalTypeMap} from '@mui/material/Modal';
import {OverridableComponent} from '@mui/material/OverridableComponent';
import clsx from 'clsx';
import {forwardRef} from 'react';
import {forwardRef, ForwardRefExoticComponent} from 'react';
import type {ElementType, ReactElement, Ref} from 'react';

export type DialogProps<C extends ElementType = ElementType> = {
@@ -46,19 +44,19 @@ export type DialogProps<C extends ElementType = ElementType> = {
*
* @remarks
* - ✔️ Props of the [Modal](https://mui.com/material-ui/api/modal/) component are also available.
* - `component` prop is supported.
* - FIXME: ⚠️ `component` prop is temporarily not supported due to https://github.com/wso2/oxygen-ui/issues/283
* - ✅ The `ref` is forwarded to the root element.
*
* @template C - The type of the component.
* @param props - The props for the Dialog component.
* @param ref - The ref to be forwarded to the MuiDialog component.
* @returns The rendered Dialog component.
*/
const Dialog: OverridableComponent<ModalTypeMap<ModalTypeMap['defaultComponent'], DialogProps>> = forwardRef(
const Dialog: ForwardRefExoticComponent<DialogProps> = forwardRef(
<C extends ElementType = ElementType>(
{className, ...rest}: DialogProps<C>,
ref: Ref<HTMLDivElement>,
): ReactElement => <MuiDialog ref={ref} className={clsx('OxygenDialog-root')} {...rest} />,
) as OverridableComponent<ModalTypeMap<ModalTypeMap['defaultComponent'], DialogProps>>;
) as ForwardRefExoticComponent<DialogProps>;

export default Dialog;