Skip to content

Commit

Permalink
fix(a11y): Fieldset and legend for list/map date input (#3631)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianjon3s authored Sep 6, 2024
1 parent 36a3a1b commit 1e9757b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import { paddedDate } from "@planx/components/DateInput/model";
import type { DateField } from "@planx/components/shared/Schema/model";
import React from "react";
import InputLabel from "ui/public/InputLabel";
import InputLegend from "ui/editor/InputLegend";
import DateInput from "ui/shared/DateInput";

import { getFieldProps, Props } from ".";
Expand All @@ -13,21 +14,24 @@ export const DateFieldInput: React.FC<Props<DateField>> = (props) => {
const { id, errorMessage, name, value } = getFieldProps(props);

return (
<InputLabel label={data.title} htmlFor={id}>
<Box component="fieldset">
<InputLegend>
<Typography variant="body1" pb={1}>
<strong>{data.title}</strong>
</Typography>
</InputLegend>
{data.description && (
<FieldInputDescription description={data.description} />
)}
<Box sx={{ display: "flex", alignItems: "baseline" }}>
<DateInput
value={value?.toString()}
bordered
onChange={(newDate: string, eventType: string) => {
formik.setFieldValue(name, paddedDate(newDate, eventType));
}}
error={errorMessage}
id={id}
/>
</Box>
</InputLabel>
<DateInput
value={value?.toString()}
bordered
onChange={(newDate: string, eventType: string) => {
formik.setFieldValue(name, paddedDate(newDate, eventType));
}}
error={errorMessage}
id={id}
/>
</Box>
);
};
4 changes: 2 additions & 2 deletions editor.planx.uk/src/ui/shared/DateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const INPUT_YEAR_WIDTH = "84px";

const Root = styled(Box)(({ theme }) => ({
display: "flex",
alignItems: "bottom",
alignItems: "flex-end",
// Adds a uniform horizontal spacing between all child elements.
// The `* + *` selector makes sure the first element doesn't get this margin.
"& > * + *": {
Expand All @@ -31,7 +31,7 @@ const Root = styled(Box)(({ theme }) => ({
const Label = styled(Typography)(({ theme }) => ({
minWidth: INPUT_DATE_WIDTH,
alignSelf: "end",
marginBottom: theme.spacing(0.5),
marginBottom: theme.spacing(1),
display: "inline-block",
})) as typeof Typography;

Expand Down

0 comments on commit 1e9757b

Please sign in to comment.