Skip to content
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

Fix the fieldset structure #51510

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 33 additions & 44 deletions web/packages/teleport/src/components/LabelsInput/LabelsInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,46 +146,42 @@ export function LabelsInput({
const width = `${inputWidth}px`;
const inputSize = 'medium';
return (
<Fieldset gap={labels.length > 0 ? 2 : 1}>
<Stack gap={1}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering how it broke the semantic structure of fieldset and legend, I managed to find that indeed:

The first element inside the fieldset must be a legend element, which provides a label or description for the group.

https://www.w3.org/TR/WCAG20-TECHS/H71.html

FWIW, I did a quick check and this could also be fixed by getting rid of this Stack and changing the gap on Fieldset to always be 2, with just a minimal difference in spacing compared to the original implementation while keeping spacing defined on parents and not individual children.

{legend && (
<Legend>
{tooltipContent ? (
<>
<span
css={{
marginRight: '4px',
verticalAlign: 'middle',
}}
>
{legend}
</span>
<IconTooltip children={tooltipContent} />
</>
) : (
legend
)}
</Legend>
)}
{labels.length > 0 && (
<Flex>
<Box width={width} mr="3">
<Text typography="body3">
{labelKey.fieldName} (required field)
</Text>
</Box>
<Fieldset>
{legend && (
<Legend>
{tooltipContent ? (
<>
<span
css={{
marginRight: '4px',
verticalAlign: 'middle',
}}
>
{legend}
</span>
<IconTooltip children={tooltipContent} />
</>
) : (
legend
)}
</Legend>
)}
{labels.length > 0 && (
<Flex mt={legend ? 1 : 0} mb={1}>
<Box width={width} mr="3">
<Text typography="body3">
{labelVal.fieldName} (required field)
{labelKey.fieldName} (required field)
</Text>
</Flex>
)}
</Stack>
<Stack gap={2}>
</Box>
<Text typography="body3">{labelVal.fieldName} (required field)</Text>
</Flex>
)}
<Box>
{labels.map((label, index) => {
const validationItem: LabelValidationResult | undefined =
validationResult.results?.[index];
return (
<Box key={index}>
<Box mb={2} key={index}>
<Flex alignItems="start">
<FieldInput
size={inputSize}
Expand Down Expand Up @@ -245,7 +241,7 @@ export function LabelsInput({
</Box>
);
})}
</Stack>
</Box>
<ButtonSecondary
onClick={e => {
e.preventDefault();
Expand Down Expand Up @@ -274,21 +270,14 @@ export const nonEmptyLabels: LabelsRule = labels => () => {
};
};

const Stack = styled(Flex).attrs({
flexDirection: 'column',
alignItems: 'start',
})``;

const Fieldset = styled(Stack).attrs({
as: 'fieldset',
})`
const Fieldset = styled.fieldset`
border: none;
margin: 0;
padding: 0;
`;

const Legend = styled.legend`
margin: 0;
margin: 0 0 ${props => props.theme.space[1]}px 0;
padding: 0;
${props => props.theme.typography.body3}
`;
Loading