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
4 changes: 0 additions & 4 deletions src/components/Dropdown/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,6 @@ const dropdownArgs: Object = {
disabled: false,
closeOnDropdownClick: true,
portal: false,
overlayProps: {
role: 'listbox',
'aria-label': 'Dropdown overlay',
},
};

Dropdown_Button.args = {
Expand Down
36 changes: 36 additions & 0 deletions src/components/Dropdown/Dropdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1067,4 +1067,40 @@ describe('Dropdown', () => {
expect(referenceElement.getAttribute('aria-expanded')).toBe('true');
expect(container.querySelector('.dropdown-wrapper')).toBeTruthy();
});

describe('overlay wrapper role', () => {
const openOverlay = async (props: object = {}): Promise<HTMLElement> => {
render(
<Dropdown {...dropdownProps} {...props}>
<Button data-testid="dropdown-reference" text="Dropdown menu test" />
</Dropdown>
);
const referenceElement = screen.getByTestId('dropdown-reference');
act(() => {
userEvent.click(referenceElement);
});
await waitFor(() => screen.getByText('User profile 1'));
return document.getElementById(
referenceElement.getAttribute('aria-controls')
);
};

test('Should not set a role on the overlay wrapper by default', async () => {
const overlayWrapper = await openOverlay();
expect(overlayWrapper).toBeTruthy();
expect(overlayWrapper.hasAttribute('role')).toBe(false);
});

test('Should apply the role prop to the overlay wrapper', async () => {
const overlayWrapper = await openOverlay({ role: 'listbox' });
expect(overlayWrapper.getAttribute('role')).toBe('listbox');
});

test('Should apply overlayProps.role to the overlay wrapper', async () => {
const overlayWrapper = await openOverlay({
overlayProps: { role: 'dialog' },
});
expect(overlayWrapper.getAttribute('role')).toBe('dialog');
});
});
});
2 changes: 1 addition & 1 deletion src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const Dropdown: FC<DropdownProps> = React.memo(
referenceOnClick,
referenceOnKeydown,
referenceWrapperClassNames,
role = 'listbox',
role,
Comment thread
vrajput-eightfold marked this conversation as resolved.
Resolved
showDropdown,
style,
tabIndex = 0,
Expand Down
5 changes: 2 additions & 3 deletions src/components/Dropdown/Dropdown.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@ export interface DropdownProps {
*/
referenceWrapperClassNames?: string;
/**
* The dropdown aria role.
* If null, the role will not be applied to the reference element.
* @default 'listbox'
* Aria role of the overlay wrapper. Unset by default; set it only when the
* overlay content has no role of its own.
*/
role?: string | null;
/**
Expand Down
3 changes: 0 additions & 3 deletions src/components/Menu/__snapshots__/Menu.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ exports[`Menu Menu is large 1`] = `
<div
class="dropdown-wrapper no-padding open"
id="dropdown-"
role="listbox"
style="position: absolute; top: 4px; left: 0px;"
tabindex="-1"
>
Expand Down Expand Up @@ -275,7 +274,6 @@ exports[`Menu Menu is medium 1`] = `
<div
class="dropdown-wrapper no-padding open"
id="dropdown-"
role="listbox"
style="position: absolute; top: 4px; left: 0px;"
tabindex="-1"
>
Expand Down Expand Up @@ -527,7 +525,6 @@ exports[`Menu Menu is small 1`] = `
<div
class="dropdown-wrapper no-padding open"
id="dropdown-"
role="listbox"
style="position: absolute; top: 4px; left: 0px;"
tabindex="-1"
>
Expand Down
Loading