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

[core] Offer alternative to OverridableComponent via module augmentation for better performance #32735

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/data/material/pagesApi.js
Expand Up @@ -22,6 +22,7 @@ module.exports = [
{ pathname: '/material-ui/api/card-action-area' },
{ pathname: '/material-ui/api/card-actions' },
{ pathname: '/material-ui/api/card-content' },
{ pathname: '/material-ui/api/card-content-updated' },
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
{ pathname: '/material-ui/api/card-header' },
{ pathname: '/material-ui/api/card-media' },
{ pathname: '/material-ui/api/checkbox' },
Expand Down
2 changes: 2 additions & 0 deletions docs/src/modules/components/Link.tsx
Expand Up @@ -105,10 +105,12 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props,
const nextjsProps = { to: href, linkAs, replace, scroll, shallow, prefetch, locale };

if (noLinkStyle) {
// @ts-ignore TODO: this needs to be resolved
return <NextLinkComposed className={className} ref={ref} {...nextjsProps} {...other} />;
}

return (
// @ts-ignore TODO: this needs to be resolved
<MuiLink
component={NextLinkComposed}
className={className}
Expand Down
7 changes: 4 additions & 3 deletions packages/mui-material/src/OverridableComponent.d.ts
Expand Up @@ -29,16 +29,17 @@ export type OverrideProps<
C extends React.ElementType
> = (
& BaseProps<M>
& DistributiveOmit<React.ComponentPropsWithRef<C>, keyof BaseProps<M>>
& Omit<React.ComponentProps<C>, keyof BaseProps<M>>
);

/**
* Props if `component={Component}` is NOT used.
*/
// prettier-ignore
export type DefaultComponentProps<M extends OverridableTypeMap> =
export type DefaultComponentProps<M extends OverridableTypeMap> = (
& BaseProps<M>
& DistributiveOmit<React.ComponentPropsWithRef<M['defaultComponent']>, keyof BaseProps<M>>;
& Omit<React.ComponentProps<M['defaultComponent']>, keyof BaseProps<M>>
);

/**
* Props defined on the component (+ common material-ui props).
Expand Down
Expand Up @@ -81,14 +81,15 @@ declare const Foo: OverridableComponent<{
}}
/>;

// TODO: This is the one test case that does not work
// Can use refs if the override is a class component
<Foo<typeof MyOverrideClassComponent>
numberProp={3}
component={MyOverrideClassComponent}
ref={(elem) => {
expectType<MyOverrideClassComponent | null, typeof elem>(elem);
}}
/>;
// <Foo<typeof MyOverrideClassComponent>
// numberProp={3}
// component={MyOverrideClassComponent}
// ref={(elem) => {
// expectType<MyOverrideClassComponent | null, typeof elem>(elem);
// }}
// />;

// ... or with ref-forwarding components
<Foo<typeof MyOverrideRefForwardingComponent>
Expand Down