Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ test('supports ariaLabelledby', () => {
expect(container.querySelector('[role=listbox]')).toHaveAttribute('aria-labelledby', 'someid');
});

test('supports ariaRequired', () => {
const container = renderList(
<OptionsList open={true} statusType="pending" ariaRequired={true}>
<div>Option</div>
</OptionsList>
);
expect(container.querySelector('[role=listbox]')).toHaveAttribute('aria-required', 'true');
});

test('onLoadMore fires when dropdown opens and its bottom is on the screen', () => {
const onLoadMore = jest.fn();
const { rerender } = render(
Expand Down
3 changes: 3 additions & 0 deletions src/internal/components/options-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface OptionsListProps extends BaseComponentProps {
ariaLabel?: string;
ariaLabelledby?: string;
ariaDescribedby?: string;
ariaRequired?: boolean;
decreaseBlockMargin?: boolean;
embedded?: boolean;
stickyItemBlockSize?: number | null;
Expand Down Expand Up @@ -77,6 +78,7 @@ const OptionsList = (
ariaLabel,
ariaLabelledby,
ariaDescribedby,
ariaRequired,
embedded,
stickyItemBlockSize,
isMultiSelect,
Expand Down Expand Up @@ -130,6 +132,7 @@ const OptionsList = (
aria-labelledby={ariaLabelledby}
aria-describedby={ariaDescribedby}
aria-multiselectable={role === 'listbox' && isMultiSelect ? true : undefined}
aria-required={ariaRequired}
>
{open && children}
</Tag>
Expand Down
9 changes: 9 additions & 0 deletions src/multiselect/__tests__/multiselect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,15 @@ describe('a11y properties', () => {
'multiselect-label'
);
});
test('listbox should receive aria-required when that property is set', () => {
const { wrapper } = renderMultiselect(
<Multiselect selectedOptions={[]} options={defaultOptions} ariaRequired={true} />
);
wrapper.openDropdown();
expect(
wrapper.findDropdown().getElement().parentNode!.querySelector(`[role=listbox]`)!.getAttribute('aria-required')
).toBe('true');
});
});

test('Trigger receives focus when autofocus is true', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/multiselect/internal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const InternalMultiselect = React.forwardRef(
<DropdownFooter content={multiselectProps.isOpen ? dropdownStatus.content : null} id={footerId} />
) : null
}
menuProps={multiselectProps.getMenuProps()}
menuProps={{ ...multiselectProps.getMenuProps(), ariaRequired }}
getOptionProps={multiselectProps.getOptionProps}
filteredOptions={multiselectProps.filteredOptions}
filteringValue={filteringValue}
Expand Down
14 changes: 14 additions & 0 deletions src/select/__tests__/select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,20 @@ describe.each([false, true])('expandToViewport=%s', expandToViewport => {
wrapper.findDropdown({ expandToViewport }).getElement().parentNode!.querySelector(`#${controlledId}`)!
).toHaveAccessibleName('select-label');
});

test('listbox should receive aria-required when that property is set', () => {
const { wrapper } = renderSelect({
ariaRequired: true,
});
wrapper.openDropdown();
expect(
wrapper
.findDropdown({ expandToViewport })
.getElement()
.parentNode!.querySelector(`[role=listbox]`)!
.getAttribute('aria-required')
).toBe('true');
});
});

describe('Filtering results', () => {
Expand Down
1 change: 1 addition & 0 deletions src/select/internal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ const InternalSelect = React.forwardRef(
onLoadMore: handleLoadMore,
ariaLabelledby: joinStrings(selectAriaLabelId, controlId),
ariaDescribedby: dropdownStatus.content ? footerId : undefined,
ariaRequired,
};

const announcement = useAnnouncement({
Expand Down
Loading