Coder Social home page Coder Social logo

Comments (8)

alexey-kozlenkov avatar alexey-kozlenkov commented on July 22, 2024 1

@appleSimple my bad 😞
This one should work: https://codesandbox.io/p/sandbox/damp-monad-sptgfr?file=%2Fsrc%2FDemo.tsx%3A12%2C4

from material-ui.

alexey-kozlenkov avatar alexey-kozlenkov commented on July 22, 2024 1

@appleSimple any could be passed as a slotProps's value to CreateSlotsAndSlotProps, can't be passed to Alert's close button slotProps cause it's already specified as SlotProps<React.ElementType<IconButtonProps>, {}, AlertOwnerState>

from material-ui.

appleSimple avatar appleSimple commented on July 22, 2024

not found example link T^T

from material-ui.

appleSimple avatar appleSimple commented on July 22, 2024

slotProps's type could be any because of K extends Record<keyof Slots, any>, but not applied any type.

This may be related part of cause.

Alert.d.ts

export type AlertSlotsAndSlotProps = CreateSlotsAndSlotProps<
  AlertSlots,
  {
    closeButton: SlotProps<React.ElementType<IconButtonProps>, {}, AlertOwnerState>;
    closeIcon: SlotProps<React.ElementType<SvgIconProps>, {}, AlertOwnerState>;
  }
>;

types.ts

export type CreateSlotsAndSlotProps<Slots, K extends Record<keyof Slots, any>> = {
  /**
   * The components used for each slot inside.
   * @default {}
   */
  slots?: Slots;
  /**
   * The props used for each slot inside.
   * @default {}
   */
  slotProps?: {
    [P in keyof K]?: K[P];
  };
};

from material-ui.

ZeeshanTamboli avatar ZeeshanTamboli commented on July 22, 2024

You can type cast slotProps.closeButton to resolve the issue. Here's how:

<Alert
  icon={<CheckIcon fontSize="inherit" />}
  severity="success"
  onClose={() => void 0}
  slots={{
    closeIcon: CloseIcon,
    closeButton: MyIconButton,
  }}
  slotProps={{
    closeButton: {
      iconSize: 'medium',
    } as MyIconButtonProps,
  }}
>
  Here is a gentle confirmation that your action was successful.
</Alert>

This approach works, but it's not clear if it should be documented as a solution or is considered a workaround in which case this is a bug.

from material-ui.

alexey-kozlenkov avatar alexey-kozlenkov commented on July 22, 2024

@ZeeshanTamboli I don't it's possible since slotProps values there are not just types of desired props but a SlotProps<...> wrapper around original MUI's IconButtonProps, as I specified at the beginning of that issue.

image

from material-ui.

DiegoAndai avatar DiegoAndai commented on July 22, 2024

Hey @alexey-kozlenkov, thanks for the report 😊

This use case is covered in other components by adding ...SlotPropsOverrides types, for example the BadgeRootSlotPropsOverrides type in the Badge component. These types can then be augmented to accomplish the expected behavior, for example: https://codesandbox.io/p/sandbox/slot-props-overrides-example-7nm889?file=%2Fsrc%2FApp.tsx%3A10%2C2.

This hasn't been implemented in all components, the Alert being one of them. I'm accepting this as an enhancement for the missing functionality and adding the ready-to-take label if anyone wishes to work on it. It should be enough to add new types AlertCloseButtonSlotPropsOverrides and AlertCloseIconSlotPropsOverrides following the pattern used in Badge.

from material-ui.

alexey-kozlenkov avatar alexey-kozlenkov commented on July 22, 2024

@DiegoAndai have a look please when convenient

from material-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.