Comments (8)
@appleSimple my bad 😞
This one should work: https://codesandbox.io/p/sandbox/damp-monad-sptgfr?file=%2Fsrc%2FDemo.tsx%3A12%2C4
from material-ui.
@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.
not found example link T^T
from material-ui.
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.
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.
@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.
from material-ui.
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.
@DiegoAndai have a look please when convenient
from material-ui.
Related Issues (20)
- [docs] Random Unsplash photo URL is no longer functional HOT 2
- sx prop not work HOT 1
- [v6] Module not found: DefaultPropsProvider/ InitColorSchemeScript HOT 8
- [joy-ui] When using styled('div') all its properties are lost
- bug: Preact example is throwing errors HOT 2
- [material-ui][Autocomplete] label cut off when the option list is displayed above.
- @mui/material: incorrect responsiveFontSizes return type when using CssVarsTheme as input HOT 2
- [RFC][Grid v2] Stabilize API HOT 4
- [docs][Grid v2] Restructure docs HOT 3
- Some bad ts performance cases
- Mui input base text area style is not applied correctly with input props on 5.15.11 from 5.15.10 HOT 6
- [Joy UI] Typography color is not defined by what is on the table
- Autocomplete with groups throws accessibility scanner issues
- Opening the Scroll Dialogs diables scrolling on main page
- Type conflict in Button component's `href` prop when using `component` prop
- Not able to upload a file on button click HOT 1
- Menu doesnt restore the aria-hidden when closed. HOT 1
- [bug] `extendTheme` doesn't work w/ `pigment` HOT 6
- [Unstable_NumberInput]: step incorrect with min HOT 1
- I have too many style tags in my head tag HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from material-ui.