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": "patch",
"comment": "fix: don't apply modalizer attributes when focus trap isn't configured",
"packageName": "@fluentui/react-popover",
"email": "lingfangao@hotmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: don't apply modalizer attributes when focus trap isn't configured",
"packageName": "@fluentui/react-tabster",
"email": "lingfangao@hotmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -541,4 +541,31 @@ describe('Popover', () => {
.should('have.length', 2);
});
});

describe('Without trapFocus', () => {
it('should restore focus on close', () => {
mount(
<Popover>
<PopoverTrigger>
<button id="trigger">trigger</button>
</PopoverTrigger>
<PopoverSurface>
<button id="button">button</button>
</PopoverSurface>
</Popover>,
);

cy.get('#trigger')
.click()
.get(popoverContentSelector)
.should('exist')
.get('#button')
.focus()
.type('{esc}')
.get(popoverContentSelector)
.should('not.exist')
.get('#trigger')
.should('have.focus');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`PopoverSurface renders a default state 1`] = `
<div
aria-label="test"
class="fui-PopoverSurface"
data-tabster="{\\"restorer\\":{\\"type\\":0}}"
data-testid="component"
role="group"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const usePopoverSurface_unstable = (
ref: useMergedRefs(ref, contentRef),
role: trapFocus ? 'dialog' : 'group',
'aria-modal': trapFocus ? true : undefined,
...(trapFocus ? modalAttributes : {}),
...modalAttributes,
...props,
}),
{ elementType: 'div' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ export const useModalAttributes = (
const id = useId('modal-', options.id);
const modalAttributes = useTabsterAttributes({
restorer: { type: TabsterTypes.RestorerTypes.Source },
modalizer: {
id,
isOthersAccessible: !trapFocus,
isAlwaysAccessible: alwaysFocusable,
isTrapped: legacyTrapFocus && trapFocus,
},
...(trapFocus && {
modalizer: {
id,
isOthersAccessible: !trapFocus,
isAlwaysAccessible: alwaysFocusable,
isTrapped: legacyTrapFocus && trapFocus,
},
}),
});

const triggerAttributes = useTabsterAttributes({
Expand Down