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
2 changes: 1 addition & 1 deletion packages/react-aria/src/overlays/ariaHideOutside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let observerStack: Array<ObserverWrapper> = [];
export function ariaHideOutside(targets: Element[], options?: AriaHideOutsideOptions | Element) {
let windowObj = getOwnerWindow(targets?.[0]);
let opts = options instanceof windowObj.Element ? {root: options} : options;
let root = opts?.root ?? document.body;
let root = opts?.root ?? windowObj.document.body;
let shouldUseInert = opts?.shouldUseInert && supportsInert;
let visibleNodes = new Set<Element>(targets);
let hiddenNodes = new Set<Element>();
Expand Down
19 changes: 19 additions & 0 deletions packages/react-aria/test/overlays/ariaHideOutside.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@ describe('ariaHideOutside', function () {
expect(() => getByRole('button')).not.toThrow();
});

it('should use the target document as the default root', function () {
let iframe = document.createElement('iframe');
document.body.appendChild(iframe);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to clarify, the bug was that the top level root document's body was getting hidden, which hides everything below it

however, this should probably be hiding siblings of the iframe still

can you add an element alongside the iframe and assert it's hidden?

let iframeDocument = iframe.contentWindow.document;
iframeDocument.body.innerHTML = '<div id="outside"></div><div id="target"></div>';
let target = iframeDocument.getElementById('target');
let outside = iframeDocument.getElementById('outside');

let revert = ariaHideOutside([target]);

expect(outside).toHaveAttribute('aria-hidden', 'true');
expect(target).not.toHaveAttribute('aria-hidden');
expect(document.body).not.toHaveAttribute('aria-hidden');

revert();
expect(outside).not.toHaveAttribute('aria-hidden');
iframe.remove();
});

it('should hide everything except multiple elements', function () {
let {getByRole, getAllByRole, queryByRole, queryAllByRole} = render(
<>
Expand Down