Skip to content

Commit f77152e

Browse files
authored
fix: add Checkbox default slot to GridList and Table (#7188)
* Fix Checkbox default slot * fix lint
1 parent e22e960 commit f77152e

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

packages/react-aria-components/src/GridList.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ export const GridListItem = /*#__PURE__*/ createLeafComponent('item', function G
375375
values={[
376376
[CheckboxContext, {
377377
slots: {
378+
[DEFAULT_SLOT]: {},
378379
selection: checkboxProps
379380
}
380381
}],

packages/react-aria-components/src/Table.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,7 @@ export const Row = /*#__PURE__*/ createBranchComponent(
11181118
values={[
11191119
[CheckboxContext, {
11201120
slots: {
1121+
[DEFAULT_SLOT]: {},
11211122
selection: checkboxProps
11221123
}
11231124
}],

packages/react-aria-components/test/GridList.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ import {act, fireEvent, mockClickDefault, pointerMap, render, within} from '@rea
1414
import {
1515
Button,
1616
Checkbox,
17+
Dialog,
18+
DialogTrigger,
1719
DropIndicator,
1820
GridList,
1921
GridListContext,
2022
GridListItem,
23+
Label,
2124
UNSTABLE_ListLayout as ListLayout,
25+
Modal,
2226
RouterProvider,
2327
Tag,
2428
TagGroup,
@@ -465,6 +469,29 @@ describe('GridList', () => {
465469
expect(document.activeElement).toBe(document.body);
466470
});
467471

472+
it('should not propagate the checkbox context from selection into other cells', async () => {
473+
let tree = render(
474+
<GridList aria-label="Test" selectionMode="multiple">
475+
<GridListItem id="dialog" textValue="dialog">
476+
<DialogTrigger>
477+
<Button>Open</Button>
478+
<Modal>
479+
<Dialog>
480+
<Checkbox><Label>Agree</Label></Checkbox>
481+
</Dialog>
482+
</Modal>
483+
</DialogTrigger>
484+
</GridListItem>
485+
<GridListItem id="dog" textValue="Dog">Dog</GridListItem>
486+
<GridListItem id="kangaroo">Kangaroo</GridListItem>
487+
</GridList>
488+
);
489+
490+
await user.click(tree.getByRole('button'));
491+
let checkbox = tree.getByRole('checkbox');
492+
expect(checkbox).toBeInTheDocument();
493+
});
494+
468495
describe('drag and drop', () => {
469496
it('should support drag button slot', () => {
470497
let {getAllByRole} = render(<DraggableGridList />);

packages/react-aria-components/test/Table.test.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import {act, fireEvent, installPointerEvent, mockClickDefault, pointerMap, render, triggerLongPress, within} from '@react-spectrum/test-utils-internal';
14-
import {Button, Cell, Checkbox, Collection, Column, ColumnResizer, DropIndicator, ResizableTableContainer, Row, Table, TableBody, TableHeader, UNSTABLE_TableLayout as TableLayout, useDragAndDrop, useTableOptions, UNSTABLE_Virtualizer as Virtualizer} from '../';
14+
import {Button, Cell, Checkbox, Collection, Column, ColumnResizer, Dialog, DialogTrigger, DropIndicator, Label, Modal, ResizableTableContainer, Row, Table, TableBody, TableHeader, UNSTABLE_TableLayout as TableLayout, useDragAndDrop, useTableOptions, UNSTABLE_Virtualizer as Virtualizer} from '../';
1515
import {composeStories} from '@storybook/react';
1616
import {DataTransfer, DragEvent} from '@react-aria/dnd/test/mocks';
1717
import React, {useMemo, useRef, useState} from 'react';
@@ -1798,4 +1798,37 @@ describe('Table', () => {
17981798
}
17991799
});
18001800
});
1801+
1802+
describe('contexts', () => {
1803+
it('should not propagate the checkbox context from selection into other cells', async () => {
1804+
let tree = render(
1805+
<Table aria-label="Files" selectionMode="multiple">
1806+
<MyTableHeader>
1807+
<MyColumn id="name" isRowHeader>Name</MyColumn>
1808+
<MyColumn>Type</MyColumn>
1809+
<MyColumn>Date Modified</MyColumn>
1810+
</MyTableHeader>
1811+
<TableBody>
1812+
<MyRow id="1" textValue="Games">
1813+
<Cell>Games</Cell>
1814+
<Cell>File folder</Cell>
1815+
<Cell>
1816+
<DialogTrigger>
1817+
<Button>Open</Button>
1818+
<Modal>
1819+
<Dialog>
1820+
<Checkbox><Label>Agree</Label></Checkbox>
1821+
</Dialog>
1822+
</Modal>
1823+
</DialogTrigger>
1824+
</Cell>
1825+
</MyRow>
1826+
</TableBody>
1827+
</Table>
1828+
);
1829+
await user.click(tree.getByRole('button'));
1830+
let checkbox = tree.getByRole('checkbox');
1831+
expect(checkbox).toBeInTheDocument();
1832+
});
1833+
});
18011834
});

0 commit comments

Comments
 (0)