Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const Checkbox = (props: Props, providedRef: RefObject<HTMLInputElement>) => {
<input
{...inputProps}
{...focusProps}
aria-label={label || inputProps?.['aria-label']}
aria-label={inputProps?.['aria-label'] || label}
ref={ref}
/>
</VisuallyHidden>
Expand Down
16 changes: 8 additions & 8 deletions src/components/Checkbox/Checkbox.unit.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,25 +162,25 @@ describe('<Checkbox />', () => {
expect(element.getAttribute('data-disabled')).toBe(disabled.toString());
});

it('should use label prop for aria-label when provided', async () => {
it('should use aria-label prop for aria-label when provided', async () => {
expect.assertions(1);

const label = 'test label';
const ariaLabel = 'Checkbox';

const wrapper = await mountAndWait(<Checkbox aria-label="Checkbox" label={label} />);
const wrapper = await mountAndWait(<Checkbox aria-label={ariaLabel} label={'test label'} />);
const element = wrapper.find('input').getDOMNode();

expect(element.getAttribute('aria-label')).toBe(label);
expect(element.getAttribute('aria-label')).toBe(ariaLabel);
});

it('should use aria-label prop when label prop not provided', async () => {
it('should use label prop when aria-label prop not provided', async () => {
expect.assertions(1);

const ariaLabel = 'test aria label';
const wrapper = await mountAndWait(<Checkbox aria-label={ariaLabel} />);
const label = 'test aria label';
const wrapper = await mountAndWait(<Checkbox label={label} />);
const element = wrapper.find('input').getDOMNode();

expect(element.getAttribute('aria-label')).toBe(ariaLabel);
expect(element.getAttribute('aria-label')).toBe(label);
});

it('should not add a description when description if not provided', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Checkbox/Checkbox.unit.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ exports[`<Checkbox /> snapshot should match snapshot with labelled checkbox 1`]
>
<input
aria-checked={false}
aria-label="Example text"
aria-label="Checkbox"
checked={false}
disabled={false}
onBlur={[Function]}
Expand Down Expand Up @@ -425,7 +425,7 @@ exports[`<Checkbox /> snapshot should match snapshot with labelled checkbox and
<input
aria-checked={false}
aria-describedby="checkbox-description-test-ID"
aria-label="Example text"
aria-label="Checkbox"
checked={false}
disabled={false}
onBlur={[Function]}
Expand Down
2 changes: 1 addition & 1 deletion src/components/RadioGroup/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Radio: FC<RadioProps> = (props: RadioProps) => {
const radioId = useId(id);

const radioProps = {
'aria-label': label,
'aria-label': props['aria-label'] || label,
...props,
...(description
? {
Expand Down
23 changes: 23 additions & 0 deletions src/components/RadioGroup/RadioGroup.unit.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ describe('<RadioGroup />', () => {
{
label: 'Option 1',
value: 'option1',
'aria-label': 'Test Group Option 1',
},
]}
/>
Expand Down Expand Up @@ -450,6 +451,28 @@ describe('<RadioGroup />', () => {
expect(radio.id).toBe(id);
});

it('should have child aria-label when aria-label is provided to child', () => {
expect.assertions(1);

const ariaLabel = 'Test Group Option 1';

render(
<RadioGroup
label="Test Radio Group"
options={[
{
label: 'Option 1',
value: 'option1',
'aria-label': ariaLabel,
},
]}
/>
);
const radio = screen.getByRole('radio');

expect(radio.getAttribute('aria-label')).toBe(ariaLabel);
});

it('should have child style when style is provided to child', () => {
expect.assertions(1);

Expand Down
2 changes: 1 addition & 1 deletion src/components/RadioGroup/RadioGroup.unit.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ exports[`<RadioGroup /> snapshot should match snapshot with child 1`] = `
class="md-radio-label"
>
<input
aria-label="Option 1"
aria-label="Test Group Option 1"
class="md-radio-button"
name="test-ID"
tabindex="0"
Expand Down
Loading