-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[Dialog] Flatten DialogTitle DOM structure #19696
Comments
Always in favor of removing DOM nodes when possible. |
I'd be interested to see both use cases in the current implementation. Generally it's always possible to add additional DOM elements if necessary. Removing is not (or at least a lot harder). |
I believe this demo illustrates the constraints I have mentioned: https://material-ui.com/components/dialogs/#customized-dialogs. |
We recently had a tweet on this matter: https://twitter.com/optimistavf/status/1300343255968747521. If we don't move in the direction proposed in the issue's description, I think that we should apply the List's tradeoff:
|
The way here is to remove diff --git a/packages/material-ui/src/DialogTitle/DialogTitle.js b/packages/material-ui/src/DialogTitle/DialogTitle.js
index 910d45f710..cc774fa724 100644
--- a/packages/material-ui/src/DialogTitle/DialogTitle.js
+++ b/packages/material-ui/src/DialogTitle/DialogTitle.js
@@ -40,10 +40,19 @@ const DialogTitle = React.forwardRef(function DialogTitle(inProps, ref) {
name: 'MuiDialogTitle',
});
- const { children, className, disableTypography = false, ...other } = props;
- const styleProps = { ...props, disableTypography };
+ const { children: childrenProp, className, typographyProps, ...other } = props;
+ const styleProps = { ...props };
const classes = useUtilityClasses(styleProps);
+ let children = childrenProp;
+ if (typeof childrenProp.type === 'undefined') {
+ children = (
+ <Typography component="h2" variant="h6" {...typographyProps}>
+ {childrenProp}
+ </Typography>
+ );
+ }
+
return (
<DialogTitleRoot
className={clsx(classes.root, className)}
@@ -51,13 +60,7 @@ const DialogTitle = React.forwardRef(function DialogTitle(inProps, ref) {
ref={ref}
{...other}
>
- {disableTypography ? (
- children
- ) : (
- <Typography component="h2" variant="h6">
- {children}
- </Typography>
- )}
+ {children}
</DialogTitleRoot>
);
}); |
@vicasas maybe we should test for a children type string directly instead of no type? But otherwise, it looks like an option with potential. The biggest challenge of this tradeoff will probably be documentation. Will developers be able to understand what's going on? To some extent, we have already used the pattern in the past when a developer provides a Typography. We have recently worked on a similar problem in #25883, maybe we should apply the same pattern in all the other cases? |
I have tried to consider all our options. I could find the following:
<Dialog>
<DialogTitle>
<Typography variant="h6" component="h2">
Set backup account
</Typography>
</DialogTitle>
<DialogContent>
I would personally vote for 3. It would solve #26386 at its root. |
With option 3, if you want to do something custom, should you stop using |
Summary 💡
DialogTitle
should be flatterExamples 🌈
Motivation 🔦
It is possible but requires targetting nested elements.
disableTypography
is not helpful since then we wouldn't render a heading element.We could leverage aria but this would go against rule 1 of aria (don't use aria):
<DialogTitle disableTypography role="heading" aria-level="2" className={variantH2Styles} />
The text was updated successfully, but these errors were encountered: