|
11 | 11 | */
|
12 | 12 |
|
13 | 13 | import {act, fireEvent, installPointerEvent, mockClickDefault, pointerMap, render, triggerLongPress, within} from '@react-spectrum/test-utils-internal';
|
14 |
| -import {Button, Cell, Checkbox, Collection, Column, ColumnResizer, Dialog, DialogTrigger, DropIndicator, Label, Modal, ResizableTableContainer, Row, Table, TableBody, TableHeader, TableLayout, useDragAndDrop, useTableOptions, Virtualizer} from '../'; |
| 14 | +import {Button, Cell, Checkbox, Collection, Column, ColumnResizer, Dialog, DialogTrigger, DropIndicator, Label, Modal, ResizableTableContainer, Row, Table, TableBody, TableHeader, TableLayout, Tag, TagGroup, TagList, useDragAndDrop, useTableOptions, Virtualizer} from '../'; |
15 | 15 | import {composeStories} from '@storybook/react';
|
16 | 16 | import {DataTransfer, DragEvent} from '@react-aria/dnd/test/mocks';
|
17 | 17 | import React, {useMemo, useRef, useState} from 'react';
|
@@ -64,7 +64,7 @@ function MyRow({id, columns, children, ...otherProps}) {
|
64 | 64 | let {selectionBehavior, allowsDragging} = useTableOptions();
|
65 | 65 |
|
66 | 66 | return (
|
67 |
| - <Row id={id} {...otherProps}> |
| 67 | + <Row id={id} {...otherProps} columns={columns}> |
68 | 68 | {allowsDragging && (
|
69 | 69 | <Cell>
|
70 | 70 | <Button slot="drag">≡</Button>
|
@@ -125,6 +125,31 @@ let TestTable = ({tableProps, tableHeaderProps, columnProps, tableBodyProps, row
|
125 | 125 | </Table>
|
126 | 126 | );
|
127 | 127 |
|
| 128 | +let EditableTable = ({tableProps, tableHeaderProps, columnProps, tableBodyProps, rowProps, cellProps}) => ( |
| 129 | + <Table aria-label="Files" {...tableProps}> |
| 130 | + <MyTableHeader {...tableHeaderProps}> |
| 131 | + <MyColumn id="name" isRowHeader {...columnProps}>Name</MyColumn> |
| 132 | + <MyColumn {...columnProps}>Type</MyColumn> |
| 133 | + <MyColumn {...columnProps}>Actions</MyColumn> |
| 134 | + </MyTableHeader> |
| 135 | + <TableBody {...tableBodyProps}> |
| 136 | + <MyRow id="1" textValue="Edit" {...rowProps}> |
| 137 | + <Cell {...cellProps}>Games</Cell> |
| 138 | + <Cell {...cellProps}>File folder</Cell> |
| 139 | + <Cell {...cellProps}> |
| 140 | + <TagGroup aria-label="Tag group"> |
| 141 | + <TagList> |
| 142 | + <Tag id="1">Tag 1</Tag> |
| 143 | + <Tag id="2">Tag 2</Tag> |
| 144 | + <Tag id="3">Tag 3</Tag> |
| 145 | + </TagList> |
| 146 | + </TagGroup> |
| 147 | + </Cell> |
| 148 | + </MyRow> |
| 149 | + </TableBody> |
| 150 | + </Table> |
| 151 | +); |
| 152 | + |
128 | 153 | let DraggableTable = (props) => {
|
129 | 154 | let {dragAndDropHooks} = useDragAndDrop({
|
130 | 155 | getItems: (keys) => [...keys].map((key) => ({'text/plain': key})),
|
@@ -890,6 +915,21 @@ describe('Table', () => {
|
890 | 915 | expect(rows.map(r => r.textContent)).toEqual(['FooBar', 'Foo 7Bar 7', 'Foo 8Bar 8', 'Foo 9Bar 9', 'Foo 10Bar 10', 'Foo 11Bar 11', 'Foo 12Bar 12', 'Foo 13Bar 13', 'Foo 49Bar 49']);
|
891 | 916 | });
|
892 | 917 |
|
| 918 | + it('should support nested collections with colliding keys', async () => { |
| 919 | + let {container} = render(<EditableTable />); |
| 920 | + |
| 921 | + let itemMap = new Map(); |
| 922 | + let items = container.querySelectorAll('[data-key]'); |
| 923 | + |
| 924 | + for (let item of items) { |
| 925 | + if (item instanceof HTMLElement) { |
| 926 | + let key = item.dataset.collection + ':' + item.dataset.key; |
| 927 | + expect(itemMap.has(key)).toBe(false); |
| 928 | + itemMap.set(key, item); |
| 929 | + } |
| 930 | + } |
| 931 | + }); |
| 932 | + |
893 | 933 | describe('colSpan', () => {
|
894 | 934 | it('should render table with colSpans', () => {
|
895 | 935 | let {getAllByRole} = render(<TableCellColSpan />);
|
|
0 commit comments