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

[Tooltip] Deprecate *Component and *Props for v6 #44350

Merged
merged 37 commits into from
Nov 18, 2024

Conversation

siriwatknp
Copy link
Member

A continuation from #42120

@siriwatknp siriwatknp added package: material-ui Specific to @mui/material v6.x labels Nov 8, 2024
@mui-bot
Copy link

mui-bot commented Nov 8, 2024

Netlify deploy preview

SpeedDialAction: parsed: +0.75% , gzip: +0.66%
Tooltip: parsed: +0.87% , gzip: +0.73%
@material-ui/core: parsed: +0.08% , gzip: +0.06%
@material-ui/lab: parsed: +0.14% , gzip: +0.09%

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 2fcd5a2

@zannager zannager requested a review from DiegoAndai November 8, 2024 11:14
Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

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

Hey! I gave it another review

Sorry I didn't catch these in the previous review 😓 my bad

packages/mui-material/src/Tooltip/Tooltip.js Outdated Show resolved Hide resolved
packages/mui-material/src/Tooltip/Tooltip.js Outdated Show resolved Hide resolved
Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

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

🚀 ⭐

@oliviertassinari oliviertassinari changed the title [material-ui][Tooltip] deprecate *Component and *Props for v6 [Tooltip] deprecate *Component and *Props for v6 Nov 15, 2024
@oliviertassinari oliviertassinari added the component: tooltip This is the name of the generic UI component, not the React module! label Nov 15, 2024
@oliviertassinari oliviertassinari changed the title [Tooltip] deprecate *Component and *Props for v6 [Tooltip] Deprecate *Component and *Props for v6 Nov 15, 2024
@siriwatknp siriwatknp enabled auto-merge (squash) November 18, 2024 09:38
@siriwatknp siriwatknp merged commit 7781a01 into mui:master Nov 18, 2024
22 checks passed
@arishoham
Copy link
Contributor

arishoham commented Nov 21, 2024

This pr broke the types on our tooltip wrapper:

import { Box, BoxProps, Tooltip as MuiTooltip, TooltipProps as MuiTooltipsProps } from '@mui/material';

export type TooltipProps = MuiTooltipsProps & { p?: BoxProps['p'] };

export const Tooltip = (props: TooltipProps) => {
  const { children, p = 4, title, sx: sxProps, slotProps = {} } = props;
  const { popper, ...slotPropsRest } = slotProps;

  return (
    <MuiTooltip
      {...props}
      title={<Box p={p}>{title}</Box>}
      sx={sxProps}
      slotProps={{
        ...slotPropsRest,
        popper: {
          ...popper,
          sx: popper?.sx,
          			^-- error
        },
      }}
    >
      {children}
    </MuiTooltip>
  );
};
Property 'sx' does not exist on type 'SlotProps<ElementType<PopperProps, keyof IntrinsicElements>, TooltipPopperSlotPropsOverrides, TooltipOwnerState>'.

@siriwatknp would you be able to help me fix this? switching slotProps for componentsProps works for now (but is deprecated)

@DiegoAndai
Copy link
Member

DiegoAndai commented Nov 26, 2024

Hey @arishoham, thanks for reaching out!

This is happening because slotProps can be functions, and now the updated Tooltip supports this.

You can support slotProps as functions following this example:

import {
  Box,
  BoxProps,
  Tooltip as MuiTooltip,
  TooltipProps as MuiTooltipsProps,
  TooltipOwnerState as MuiTooltipOwnerState,
} from '@mui/material';

export type TooltipProps = MuiTooltipsProps & { p?: BoxProps['p'] };

export const Tooltip = (props: TooltipProps) => {
  const { children, p = 4, title, sx: sxProps, slotProps = {} } = props;
  const { popper, ...slotPropsRest } = slotProps;

  return (
    <MuiTooltip
      {...props}
      title={<Box p={p}>{title}</Box>}
      sx={sxProps}
      slotProps={{
        ...slotPropsRest,
        popper: (ownerState: MuiTooltipOwnerState) => {
          const resolvedPopperProps = typeof popper === 'function' ? popper(ownerState) : popper;
          return {
            ...resolvedPopperProps,
            sx: resolvedPopperProps?.sx,
          };
        },
      }}
    >
      {children}
    </MuiTooltip>
  );
};

Let me know if this works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tooltip This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material v6.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants