Skip to content

Commit 94335a7

Browse files
committed
fix stale inert after causing scroll during keyboard DnD
1 parent dd1603a commit 94335a7

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

packages/@react-aria/overlays/src/ariaHideOutside.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
*/
1212

1313
import {getOwnerWindow} from '@react-aria/utils';
14-
1514
const supportsInert = typeof HTMLElement !== 'undefined' && 'inert' in HTMLElement.prototype;
1615

1716
interface AriaHideOutsideOptions {
@@ -72,6 +71,7 @@ export function ariaHideOutside(targets: Element[], options?: AriaHideOutsideOpt
7271
// made for elements with role="row" since VoiceOver on iOS has issues hiding elements with role="row".
7372
// For that case we want to hide the cells inside as well (https://bugs.webkit.org/show_bug.cgi?id=222623).
7473
if (
74+
hiddenNodes.has(node) ||
7575
visibleNodes.has(node) ||
7676
(node.parentElement && hiddenNodes.has(node.parentElement) && node.parentElement.getAttribute('role') !== 'row')
7777
) {
@@ -136,7 +136,7 @@ export function ariaHideOutside(targets: Element[], options?: AriaHideOutsideOpt
136136

137137
let observer = new MutationObserver(changes => {
138138
for (let change of changes) {
139-
if (change.type !== 'childList' || change.addedNodes.length === 0) {
139+
if (change.type !== 'childList') {
140140
continue;
141141
}
142142

packages/@react-aria/overlays/test/ariaHideOutside.test.js

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13+
import {act, render, waitFor} from '@react-spectrum/test-utils-internal';
1314
import {ariaHideOutside} from '../src';
14-
import React from 'react';
15-
import {render, waitFor} from '@react-spectrum/test-utils-internal';
15+
import React, {useState} from 'react';
1616

1717
describe('ariaHideOutside', function () {
1818
it('should hide everything except the provided element [button]', function () {
@@ -354,10 +354,13 @@ describe('ariaHideOutside', function () {
354354
});
355355

356356
it('should hide everything except the provided element [row]', function () {
357-
let {getAllByRole} = render(
357+
let {getAllByRole, getByTestId} = render(
358358
<div role="grid">
359359
<div role="row">
360-
<div role="gridcell">Cell 1</div>
360+
<div role="gridcell">
361+
<span data-testid="test-span">
362+
Cell 1
363+
</span></div>
361364
</div>
362365
<div role="row">
363366
<div role="gridcell">Cell 2</div>
@@ -367,13 +370,15 @@ describe('ariaHideOutside', function () {
367370

368371
let cells = getAllByRole('gridcell');
369372
let rows = getAllByRole('row');
373+
let span = getByTestId('test-span');
370374

371375
let revert = ariaHideOutside([rows[1]]);
372376

373377
// Applies aria-hidden to the row and cell despite recursive nature of aria-hidden
374378
// for https://bugs.webkit.org/show_bug.cgi?id=222623
375379
expect(rows[0]).toHaveAttribute('aria-hidden', 'true');
376380
expect(cells[0]).toHaveAttribute('aria-hidden', 'true');
381+
expect(span).not.toHaveAttribute('aria-hidden');
377382
expect(rows[1]).not.toHaveAttribute('aria-hidden', 'true');
378383
expect(cells[1]).not.toHaveAttribute('aria-hidden', 'true');
379384

@@ -383,5 +388,47 @@ describe('ariaHideOutside', function () {
383388
expect(cells[0]).not.toHaveAttribute('aria-hidden', 'true');
384389
expect(rows[1]).not.toHaveAttribute('aria-hidden', 'true');
385390
expect(cells[1]).not.toHaveAttribute('aria-hidden', 'true');
391+
expect(span).not.toHaveAttribute('aria-hidden');
392+
});
393+
394+
it('should unhide after item reorder', async function () {
395+
function Item(props) {
396+
return (
397+
<div role="presentation">
398+
<div data-testid={props.testid} role="row">
399+
<div role="gridcell" />
400+
</div>
401+
</div>
402+
);
403+
}
404+
405+
function Test() {
406+
let [count, setCount] = useState(0);
407+
let items = ['row1', 'row2', 'row3', 'row4', 'row5'];
408+
if (count === 1) {
409+
items = ['row2', 'row3', 'row4', 'row5', 'row1'];
410+
}
411+
412+
return (
413+
<>
414+
<button onClick={() => setCount((old) => old + 1)}>press</button>
415+
{items.map((item) => <Item testid={item} key={item} />)}
416+
</>
417+
418+
);
419+
}
420+
421+
let {getByRole, getByTestId} = render(
422+
<Test />
423+
);
424+
425+
let button = getByRole('button');
426+
let row = getByTestId('row1');
427+
let revert = ariaHideOutside([button]);
428+
429+
act(() => button.click());
430+
await Promise.resolve();
431+
revert();
432+
expect(row).not.toHaveAttribute('aria-hidden', 'true');
386433
});
387434
});

0 commit comments

Comments
 (0)