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
24 changes: 24 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,30 @@ describe('ariaHideOutside', function () {
expect(() => getByRole('button')).not.toThrow();
});

it('should use the target document as the default root', function () {
let iframe = document.createElement('iframe');
let iframeSibling = document.createElement('div');
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?

document.body.appendChild(iframeSibling);
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(iframe).not.toHaveAttribute('aria-hidden');
expect(iframeSibling).not.toHaveAttribute('aria-hidden');

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.

as discussed with @LFDanLu I'm not sure this is correct for an iframe even if it may be correct for a new window.

I'm not sure of a way to tell the difference, have any thoughts?

// if it's a trusted iframe maybe this is ok? would probably need a try/catch
const isInIframe = window.self !== window.top;
// or
const inIframe = window.frameElement !== null;

maybe a combination

expect(document.body).not.toHaveAttribute('aria-hidden');

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

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