Skip to content

Commit

Permalink
Fix: Change FormHelperText usage with @mui/material to render divs
Browse files Browse the repository at this point in the history
Fixes rjsf-team#4031 by switching the render component for `FormHelperText` to be `div`
- In `@rjsf/mui`, updated `FieldErrorTemplate` and `FieldHelpTemplate` to use the `div` component for `FormHelperText`
  • Loading branch information
heath-freenome committed Jan 8, 2024
1 parent 8c685b7 commit fa2580f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
6 changes: 4 additions & 2 deletions packages/mui/src/FieldErrorTemplate/FieldErrorTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ export default function FieldErrorTemplate<
const id = errorId<T>(idSchema);

return (
<List dense={true} disablePadding={true}>
<List id={id} dense={true} disablePadding={true}>
{errors.map((error, i: number) => {
return (
<ListItem key={i} disableGutters={true}>
<FormHelperText id={id}>{error}</FormHelperText>
<FormHelperText component='div' id={`${id}-${i}`}>
{error}
</FormHelperText>
</ListItem>
);
})}
Expand Down
6 changes: 5 additions & 1 deletion packages/mui/src/FieldHelpTemplate/FieldHelpTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ export default function FieldHelpTemplate<
return null;
}
const id = helpId<T>(idSchema);
return <FormHelperText id={id}>{help}</FormHelperText>;
return (
<FormHelperText component='div' id={id}>
{help}
</FormHelperText>
);
}
7 changes: 4 additions & 3 deletions packages/mui/test/__snapshots__/Array.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4205,17 +4205,18 @@ label[data-shrink=false]+.MuiInputBase-formControl .emotion-16:focus::-ms-input-
</div>
<ul
className="MuiList-root MuiList-dense emotion-19"
id="root_name__error"
>
<li
className="MuiListItem-root MuiListItem-dense MuiListItem-padding emotion-20"
disabled={false}
>
<p
<div
className="MuiFormHelperText-root Mui-error MuiFormHelperText-sizeMedium MuiFormHelperText-contained emotion-21"
id="root_name__error"
id="root_name__error-0"
>
Bad input
</p>
</div>
</li>
</ul>
</div>
Expand Down
11 changes: 6 additions & 5 deletions packages/mui/test/__snapshots__/Form.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4738,25 +4738,26 @@ label[data-shrink=false]+.MuiInputBase-formControl .emotion-12:focus::-ms-input-
</div>
<ul
className="MuiList-root MuiList-dense emotion-15"
id="root__error"
>
<li
className="MuiListItem-root MuiListItem-dense MuiListItem-padding emotion-16"
disabled={false}
>
<p
<div
className="MuiFormHelperText-root Mui-error MuiFormHelperText-sizeMedium MuiFormHelperText-contained emotion-17"
id="root__error"
id="root__error-0"
>
an error
</p>
</div>
</li>
</ul>
<p
<div
className="MuiFormHelperText-root Mui-error MuiFormHelperText-sizeMedium MuiFormHelperText-contained emotion-17"
id="root__help"
>
help me!
</p>
</div>
</div>
</div>
<div
Expand Down

0 comments on commit fa2580f

Please sign in to comment.