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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "fix: Use role=complementary for Popovers without focus traps",
"packageName": "@fluentui/react-popover",
"email": "[email protected]",
"dependentChangeType": "patch"
}
21 changes: 11 additions & 10 deletions packages/react-popover/e2e/Popover.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const popoverTriggerSelector = '[aria-haspopup]';
const popoverContentSelector = '[role="dialog"]';
const popoverContentSelector = '[role="complementary"]';
const popoverInteractiveContentSelector = '[role="dialog"]';
const popoverStoriesTitle = 'Components/Popover';

const popoverDefaultStory = 'Default';
Expand Down Expand Up @@ -95,21 +96,21 @@ describe('Popover', () => {
});

it('should dismiss all nested popovers on outside click', () => {
cy.get('body').click('bottomRight').get(popoverContentSelector).should('not.exist');
cy.get('body').click('bottomRight').get(popoverInteractiveContentSelector).should('not.exist');
});

it('should not dismiss when clicking on nested content', () => {
cy.contains('Second nested button').click().get(popoverContentSelector).should('have.length', 3);
cy.contains('Second nested button').click().get(popoverInteractiveContentSelector).should('have.length', 3);
});

it('should dismiss child popovers when clicking on parents', () => {
cy.contains('First nested button')
.click()
.get(popoverContentSelector)
.get(popoverInteractiveContentSelector)
.should('have.length', 2)
.contains('Root button')
.click()
.get(popoverContentSelector)
.get(popoverInteractiveContentSelector)
.should('have.length', 1);
});

Expand All @@ -119,22 +120,22 @@ describe('Popover', () => {
cy.get(secondNestedTriggerSelector)
.eq(1)
.click()
.get(popoverContentSelector)
.get(popoverInteractiveContentSelector)
.should('have.length', 3)
.get(secondNestedTriggerSelector)
.eq(0)
.click()
.get(popoverContentSelector)
.get(popoverInteractiveContentSelector)
.should('have.length', 3);
});

it('should dismiss each popover in the stack with Escape keydown', () => {
cy.focused().realPress('Escape');
cy.get(popoverContentSelector).should('have.length', 2);
cy.get(popoverInteractiveContentSelector).should('have.length', 2);
cy.focused().realPress('Escape');
cy.get(popoverContentSelector).should('have.length', 1);
cy.get(popoverInteractiveContentSelector).should('have.length', 1);
cy.focused().realPress('Escape');
cy.get(popoverContentSelector).should('not.exist');
cy.get(popoverInteractiveContentSelector).should('not.exist');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,22 @@ describe('PopoverSurface', () => {
// Assert
expect(getByTestId(testid).getAttribute('aria-modal')).toEqual('true');
});

it('should set role dialog if focus trap is active', () => {
// Arrange
mockPopoverContext({ open: true, trapFocus: true });
const { queryByRole } = render(<PopoverSurface data-testid={testid}>Content</PopoverSurface>);

// Assert
expect(queryByRole('dialog')).not.toBeNull();
});

it('should set role complementary if focus trap is not active', () => {
// Arrange
mockPopoverContext({ open: true, trapFocus: false });
const { getByTestId } = render(<PopoverSurface data-testid={testid}>Content</PopoverSurface>);

// Assert
expect(getByTestId(testid)).not.toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`PopoverSurface renders a default state 1`] = `
class="fui-PopoverSurface"
data-tabster="{\\"deloser\\":{},\\"modalizer\\":{\\"id\\":\\"modal-1\\",\\"isOthersAccessible\\":true}}"
data-testid="component"
role="dialog"
role="complementary"
>
<div
class=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const usePopoverSurface = (props: PopoverSurfaceProps, ref: React.Ref<HTM
},
root: getNativeElementProps('div', {
ref: useMergedRefs(ref, contentRef),
role: 'dialog',
role: trapFocus ? 'dialog' : 'complementary',
'aria-modal': trapFocus ? true : undefined,
...modalAttributes,
...props,
Expand Down