-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: colspan build #7780
Merged
Merged
fix: colspan build #7780
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
packages/@react-spectrum/table/test/TableNestedRows.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright 2020 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
jest.mock('@react-aria/live-announcer'); | ||
jest.mock('@react-aria/utils/src/scrollIntoView'); | ||
import {act, render as renderComponent} from '@react-spectrum/test-utils-internal'; | ||
import {Cell, Column, Row, TableBody, TableHeader, TableView} from '../'; | ||
import {enableTableNestedRows} from '@react-stately/flags'; | ||
import {Provider} from '@react-spectrum/provider'; | ||
import React from 'react'; | ||
import {tableTests} from './Table.test'; | ||
import {theme} from '@react-spectrum/theme-default'; | ||
|
||
describe('TableView with expandable rows flag on', function () { | ||
beforeAll(() => { | ||
enableTableNestedRows(); | ||
}); | ||
|
||
tableTests(); | ||
|
||
describe('with nested rows', function () { | ||
let offsetWidth, offsetHeight; | ||
|
||
beforeAll(function () { | ||
offsetWidth = jest.spyOn(window.HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(() => 1000); | ||
offsetHeight = jest.spyOn(window.HTMLElement.prototype, 'clientHeight', 'get').mockImplementation(() => 1000); | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterAll(function () { | ||
offsetWidth.mockReset(); | ||
offsetHeight.mockReset(); | ||
}); | ||
|
||
afterEach(() => { | ||
act(() => {jest.runAllTimers();}); | ||
}); | ||
it('can render', function () { | ||
let columns = [ | ||
{name: 'Foo', key: 'foo'}, | ||
{name: 'Bar', key: 'bar'}, | ||
{name: 'Baz', key: 'baz'} | ||
]; | ||
|
||
let nestedItems = [ | ||
{foo: 'Lvl 1 Foo 1', bar: 'Lvl 1 Bar 1', baz: 'Lvl 1 Baz 1', childRows: [ | ||
{foo: 'Lvl 2 Foo 1', bar: 'Lvl 2 Bar 1', baz: 'Lvl 2 Baz 1', childRows: [ | ||
{foo: 'Lvl 3 Foo 1', bar: 'Lvl 3 Bar 1', baz: 'Lvl 3 Baz 1'} | ||
]}, | ||
{foo: 'Lvl 2 Foo 2', bar: 'Lvl 2 Bar 2', baz: 'Lvl 2 Baz 2'} | ||
]} | ||
]; | ||
|
||
renderComponent( | ||
<Provider theme={theme}> | ||
<TableView aria-label="example table with nested rows" UNSTABLE_allowsExpandableRows> | ||
<TableHeader columns={columns}> | ||
{column => <Column>{column.name}</Column>} | ||
</TableHeader> | ||
<TableBody items={nestedItems}> | ||
{(item) => | ||
(<Row key={item.foo} UNSTABLE_childItems={item.childRows}> | ||
{(key) => { | ||
return <Cell>{item[key]}</Cell>; | ||
}} | ||
</Row>) | ||
} | ||
</TableBody> | ||
</TableView> | ||
</Provider> | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,20 +79,6 @@ export class GridCollection<T> implements IGridCollection<T> { | |
|
||
if (last) { | ||
last.nextKey = null; | ||
|
||
if (rowHasCellWithColSpan && node.type === 'item') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved this check back to Table's domain, it's old collections, so not too worried about colSpan on anything other than Tables in v3 |
||
let lastColIndex = last?.colIndex ?? 0 + 1; // internally colIndex is 0 based | ||
let lastColSpan = last?.colSpan ?? 1; | ||
let numberOfCellsInRow = lastColIndex + lastColSpan; | ||
if (numberOfCellsInRow !== this.columnCount) { | ||
throw new Error(`Cell count must match column count. Found ${numberOfCellsInRow} cells and ${this.columnCount} columns.`); | ||
} | ||
} else if (node.type === 'item') { | ||
let numberOfCellsInRow = [...node.childNodes].length; | ||
if (numberOfCellsInRow !== this.columnCount) { | ||
throw new Error(`Cell count must match column count. Found ${numberOfCellsInRow} cells and ${this.columnCount} columns.`); | ||
} | ||
} | ||
} | ||
|
||
// Remove deleted nodes and their children from the key map | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just moved these to another file so that the tests run faster