Skip to content

Commit

Permalink
fix: use aria-disabled when disabled prop is applied (#1987)
Browse files Browse the repository at this point in the history
- updated the snapshots
- update treatments of disabled across components
- update aria-disabled in snapshots
  • Loading branch information
booc0mtaco authored Jun 11, 2024
1 parent 03edc20 commit 1fe3b0f
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 49 deletions.
4 changes: 2 additions & 2 deletions src/components/Checkbox/Checkbox-v2.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@
.checkbox__input:not(:checked):not(:indeterminate) {
color: var(--eds-theme-color-border-utility-default-medium-emphasis);

&:hover {
&:not(:disabled):hover {
color: var(--eds-theme-color-border-utility-default-medium-emphasis-hover);
background-color: var(--eds-theme-color-background-utility-default-no-emphasis-hover);
}

&:active {
&:not(:disabled):active {
color: var(--eds-theme-color-border-utility-default-medium-emphasis-active);
background-color: var(--eds-theme-color-background-utility-default-no-emphasis-active);
}
Expand Down
11 changes: 0 additions & 11 deletions src/components/Checkbox/Checkbox-v2.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const meta: Meta<typeof Checkbox> = {
title: 'Components/V2/Checkbox',
component: Checkbox,
args: {
disabled: false,
label: 'Checkbox',
},
parameters: {
Expand Down Expand Up @@ -59,11 +58,6 @@ export const Disabled: Story = {
<Checkbox {...args} disabled indeterminate label="Disabled" />
</div>
),
parameters: {
axe: {
disabledRules: ['color-contrast'],
},
},
};

/**
Expand All @@ -84,9 +78,4 @@ export const LongLabels: Story = {
args: {
label: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit',
},
parameters: {
axe: {
disabledRules: ['color-contrast'],
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ exports[`<Checkbox /> Disabled story renders snapshot 1`] = `
class="checkbox__labels"
>
<label
aria-disabled="true"
class="label label--lg label--disabled"
for=":r5:"
>
Expand All @@ -94,6 +95,7 @@ exports[`<Checkbox /> Disabled story renders snapshot 1`] = `
class="checkbox__labels"
>
<label
aria-disabled="true"
class="label label--lg label--disabled"
for=":r6:"
>
Expand All @@ -114,6 +116,7 @@ exports[`<Checkbox /> Disabled story renders snapshot 1`] = `
class="checkbox__labels"
>
<label
aria-disabled="true"
class="label label--lg label--disabled"
for=":r7:"
>
Expand All @@ -139,6 +142,7 @@ exports[`<Checkbox /> Disabled story renders snapshot 2`] = `
class="checkbox__labels"
>
<label
aria-disabled="true"
class="label label--lg label--disabled"
for=":ra:"
>
Expand Down
15 changes: 10 additions & 5 deletions src/components/FieldLabel/FieldLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ export type FieldLabelProps = {
*/
htmlFor: string;
// Design API
/**
* Indicates disabled state of the input.
*/
disabled?: boolean;
/**
* Size of the label.
*
* **Default is `"lg"`**.
*/
size?: Extract<Size, 'md' | 'lg'>;
/**
* Indicates disabled state of the input.
*/
disabled?: boolean;
};

/**
Expand All @@ -45,7 +45,12 @@ export const FieldLabel = React.forwardRef<HTMLLabelElement, FieldLabelProps>(
className,
);
return (
<label className={componentClassName} htmlFor={htmlFor} ref={ref}>
<label
aria-disabled={disabled ?? undefined}
className={componentClassName}
htmlFor={htmlFor}
ref={ref}
>
{children}
</label>
);
Expand Down
7 changes: 6 additions & 1 deletion src/components/FieldNote/FieldNote-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ export const FieldNote = ({
}

return (
<div className={componentClassName} id={id} {...other}>
<div
aria-disabled={disabled ?? undefined}
className={componentClassName}
id={id}
{...other}
>
{(status === 'critical' || status === 'warning' || iconToUse) && (
<Icon
className={styles['field-note__icon']}
Expand Down
6 changes: 0 additions & 6 deletions src/components/InputField/InputField-v2.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@ export const Disabled: Story = {
fieldNote: 'This InputField is disabled',
defaultValue: 'Text in disabled field',
},
parameters: {
axe: {
// Disabled input does not need to meet color contrast
disabledRules: ['color-contrast'],
},
},
};

/**
Expand Down
6 changes: 5 additions & 1 deletion src/components/InputField/InputField-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ export const InputField: InputFieldType = forwardRef(
{shouldRenderOverline && (
<div className={overlineClassName}>
{label && (
<FieldLabel className={labelClassName} htmlFor={idVar}>
<FieldLabel
className={labelClassName}
disabled={disabled}
htmlFor={idVar}
>
{label}
</FieldLabel>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ exports[`<InputField /> Disabled story renders snapshot 1`] = `
class="input-field__overline"
>
<label
class="label label--lg input-field__label input-field__label--disabled"
aria-disabled="true"
class="label label--lg label--disabled input-field__label input-field__label--disabled"
for=":rc:"
>
Disabled input field
Expand All @@ -69,6 +70,7 @@ exports[`<InputField /> Disabled story renders snapshot 1`] = `
/>
</div>
<div
aria-disabled="true"
class="field-note field-note--disabled"
id=":rd:"
>
Expand Down
16 changes: 0 additions & 16 deletions src/components/Radio/Radio-v2.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const Default: Story = {
args: {
name: 'option-1',
label: 'Option 1',
disabled: false,
checked: false,
readOnly: true,
},
Expand All @@ -41,11 +40,6 @@ export const Disabled: Story = {
name: 'option-disabled',
disabled: true,
},
parameters: {
axe: {
disabledRules: ['color-contrast'],
},
},
};

export const DisabledAndChecked: Story = {
Expand Down Expand Up @@ -86,11 +80,6 @@ export const WithoutVisibleLabel: Story = {
label: undefined,
'aria-label': 'unchecked radio button',
},
parameters: {
axe: {
disabledRules: ['color-contrast'],
},
},
};

export const LongLabels = {
Expand All @@ -110,9 +99,4 @@ export const LongLabels = {
</div>
);
},
parameters: {
axe: {
disabledRules: ['color-contrast'],
},
},
};
2 changes: 2 additions & 0 deletions src/components/Radio/__snapshots__/Radio-v2.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ exports[`<Radio /> (v2) Disabled story renders snapshot 1`] = `
class="radio__labels"
>
<label
aria-disabled="true"
class="label label--lg label--disabled"
for=":r2:"
>
Expand Down Expand Up @@ -146,6 +147,7 @@ exports[`<Radio /> (v2) DisabledAndChecked story renders snapshot 1`] = `
class="radio__labels"
>
<label
aria-disabled="true"
class="label label--lg label--disabled"
for=":r3:"
>
Expand Down
6 changes: 0 additions & 6 deletions src/components/Select/Select-v2.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,6 @@ export const Disabled: StoryObj = {
disabled: true,
},
parameters: {
axe: {
disabledRules: ['color-contrast'],
},
docs: {
...Default.parameters?.docs,
},
Expand Down Expand Up @@ -860,9 +857,6 @@ export const DisabledRequired: StoryObj = {
className: 'w-96',
},
parameters: {
axe: {
disabledRules: ['color-contrast'],
},
docs: {
...Default.parameters?.docs,
},
Expand Down
1 change: 1 addition & 0 deletions src/components/Select/Select-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ const SelectLabel = ({
<Listbox.Label
as={FieldLabel}
className={componentClassName}
disabled={disabled}
htmlFor={htmlFor}
>
{label}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ praesentium, commodi eligendi asperiores quis dolorum porro.
class="textarea-field__footer"
>
<div
aria-disabled="true"
class="field-note field-note--disabled textarea-field__field-note"
id=":r7:"
>
Expand Down

0 comments on commit 1fe3b0f

Please sign in to comment.