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
1 change: 1 addition & 0 deletions packages/@react-aria/checkbox/src/useCheckboxGroupItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: C
inputProps: {
...res.inputProps,
'aria-describedby': [
props['aria-describedby'],
state.validationState === 'invalid' ? checkboxGroupErrorMessageIds.get(state) : null,
checkboxGroupDescriptionIds.get(state)
].filter(Boolean).join(' ') || undefined
Expand Down
1 change: 1 addition & 0 deletions packages/@react-aria/radio/src/useRadio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: Ref
value,
onChange,
'aria-describedby': [
props['aria-describedby'],
state.validationState === 'invalid' ? radioGroupErrorMessageIds.get(state) : null,
radioGroupDescriptionIds.get(state)
].filter(Boolean).join(' ') || undefined
Expand Down
8 changes: 8 additions & 0 deletions packages/react-aria-components/test/CheckboxGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,12 @@ describe('CheckboxGroup', () => {
let label = document.getElementById(group.getAttribute('aria-labelledby'));
expect(label).toHaveAttribute('data-required', 'true');
});

it('should support aria-describedby on a checkbox', () => {
let {getAllByRole} = renderGroup({}, {'aria-describedby': 'test'});
let checkboxes = getAllByRole('checkbox');
for (let checkbox of checkboxes) {
expect(checkbox).toHaveAttribute('aria-describedby', 'test');
}
});
});
20 changes: 14 additions & 6 deletions packages/react-aria-components/test/RadioGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ describe('RadioGroup', () => {
let labelA = radios[0].closest('label');
let labelB = radios[1].closest('label');
let labelC = radios[2].closest('label');

const expectNotFocused = (...labels) => {
labels.forEach((label) => {
expect(label).not.toHaveAttribute('data-focus-visible');
Expand All @@ -292,7 +292,7 @@ describe('RadioGroup', () => {
};

expectNotFocused(labelA, labelB, labelC);

userEvent.tab();
expect(document.activeElement).toBe(radios[0]);
expect(labelA).toHaveAttribute('data-focus-visible', 'true');
Expand All @@ -316,7 +316,7 @@ describe('RadioGroup', () => {
<Modal data-test="modal">
<Dialog role="alertdialog" data-test="dialog">
{({close}) => (
<>
<>
<TestRadioGroup radioProps={{className: ({isFocusVisible}) => isFocusVisible ? 'focus' : ''}} />
<Button onPress={close}>Close</Button>
</>
Expand All @@ -330,7 +330,7 @@ describe('RadioGroup', () => {
userEvent.click(trigger);

let dialog = getByRole('alertdialog');

let radios = within(dialog).getAllByRole('radio');
let labelA = radios[0].closest('label');
let labelB = radios[1].closest('label');
Expand All @@ -344,10 +344,10 @@ describe('RadioGroup', () => {
};

expectNotFocused(labelA, labelB, labelC);

userEvent.tab();
expect(document.activeElement).toBe(radios[0]);
expect(labelA).toHaveAttribute('data-focus-visible', 'true');
expect(labelA).toHaveAttribute('data-focus-visible', 'true');
expect(labelA).toHaveClass('focus');
expectNotFocused(labelB, labelC);

Expand All @@ -362,4 +362,12 @@ describe('RadioGroup', () => {
expect(labelC).toHaveClass('focus');
expectNotFocused(labelA, labelB);
});

it('should support aria-describedby on a radio', () => {
let {getAllByRole} = renderGroup({}, {'aria-describedby': 'test'});
let radios = getAllByRole('radio');
for (let radio of radios) {
expect(radio).toHaveAttribute('aria-describedby', 'test');
}
});
});