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: resolve incorrect usage of label 'for' form element #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/design-system/text-box/text-box.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { Sx } from '../../design-tokens';
export interface TextBoxProps extends Form.FormControlProps {
required?: boolean;
disabled?: boolean;
id?: string;
id: string;
label: string;
name?: string;
defaultValue?: string;
Expand Down Expand Up @@ -67,7 +67,9 @@ export const TextBox = ({
data-testid={rest['data-testid']}
/>
</Form.Control>
<Form.Label className={cn(cx.label)}>{label}</Form.Label>
<Form.Label htmlFor={id} className={cn(cx.label)}>
{label}
</Form.Label>
</Form.Field>
</Flex>
{errorMessage && (
Expand Down
14 changes: 10 additions & 4 deletions src/design-system/text-box/text-box.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@ export default {
const MainComponents = (): JSX.Element => (
<Variants.Row>
<Variants.Cell>
<TextBox label="Label" value="" />
<TextBox label="Label" value="" id="empty" />
</Variants.Cell>
<Variants.Cell>
<TextBox label="Label" value="" id="hover" />
</Variants.Cell>
<Variants.Cell>
<TextBox label="Label" value="Input Text" />
<TextBox label="Label" value="Input Text" id="with-value" />
</Variants.Cell>
<Variants.Cell>
<TextBox label="Label" value="Input Text" errorMessage="Error" />
<TextBox
label="Label"
value="Input Text"
errorMessage="Error"
id="with-error"
/>
</Variants.Cell>
<Variants.Cell>
<TextBox label="Label" value="Input Text" disabled />
<TextBox label="Label" value="Input Text" disabled id="disabled" />
</Variants.Cell>
<Variants.Cell>
<TextBox label="Label" value="" id="focus" />
Expand All @@ -53,6 +58,7 @@ export const Overview = (): JSX.Element => {
<Section title="Copy for use">
<Flex flexDirection="column" alignItems="center" w="$fill" my="$32">
<TextBox
id="default"
value={value}
label="Text"
onChange={(event): void => {
Expand Down