Skip to content

Commit f57da2b

Browse files
authored
Merge pull request #4397 from Sagar-6203620715/fix-access-3
fix(a11y)-3: prevent rendering empty dialog title headings
2 parents fd54e9b + 0ec1615 commit f57da2b

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

frontend/src/components/common/Dialog.tsx

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ export interface OurDialogTitleProps extends DialogTitleProps {
4646
export function DialogTitle(props: OurDialogTitleProps) {
4747
const { children, focusTitle, buttons, disableTypography = false, ...other } = props;
4848

49+
// Don't render heading if there's no content to avoid empty heading violations
50+
if (!children && (!buttons || buttons.length === 0)) {
51+
return null;
52+
}
53+
4954
const focusedRef = React.useCallback((node: HTMLElement) => {
5055
if (node !== null) {
5156
if (focusTitle) {
@@ -58,23 +63,25 @@ export function DialogTitle(props: OurDialogTitleProps) {
5863
return (
5964
<MuiDialogTitle style={{ display: 'flex' }} {...other}>
6065
<Grid container justifyContent="space-between" alignItems="center">
61-
<Grid item>
62-
{disableTypography ? (
63-
children
64-
) : (
65-
<Typography
66-
ref={focusedRef}
67-
variant="h1"
68-
style={{
69-
fontSize: '1.25rem',
70-
fontWeight: 500,
71-
lineHeight: 1.6,
72-
}}
73-
>
74-
{children}
75-
</Typography>
76-
)}
77-
</Grid>
66+
{children && (
67+
<Grid item>
68+
{disableTypography ? (
69+
children
70+
) : (
71+
<Typography
72+
ref={focusedRef}
73+
variant="h1"
74+
style={{
75+
fontSize: '1.25rem',
76+
fontWeight: 500,
77+
lineHeight: 1.6,
78+
}}
79+
>
80+
{children}
81+
</Typography>
82+
)}
83+
</Grid>
84+
)}
7885
{buttons && buttons.length > 0 && (
7986
<Grid item>
8087
<Box>

0 commit comments

Comments
 (0)