Skip to content

Commit 987e600

Browse files
solimantdannify
andauthored
Fix TableView SSR (#2754)
Co-authored-by: Danni <[email protected]>
1 parent 0f76dca commit 987e600

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

packages/@react-aria/grid/src/useHighlightSelectionDescription.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export function useHighlightSelectionDescription(props: UseHighlightSelectionDes
3232
let formatMessage = useMessageFormatter(intlMessages);
3333
let modality = useInteractionModality();
3434
// null is the default if the user hasn't interacted with the table at all yet or the rest of the page
35-
let shouldLongPress = (modality === 'pointer' || modality === 'virtual' || modality == null) && 'ontouchstart' in window;
35+
let shouldLongPress = (modality === 'pointer' || modality === 'virtual' || modality == null)
36+
&& typeof window !== 'undefined' && 'ontouchstart' in window;
3637

3738
let interactionDescription = useMemo(() => {
3839
let selectionMode = props.selectionManager.selectionMode;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2022 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {testSSR} from '@react-spectrum/test-utils';
14+
15+
describe('Table SSR', function () {
16+
it('should render without errors', async function () {
17+
await testSSR(__filename, `
18+
import {Provider} from '@react-spectrum/provider';
19+
import {theme} from '@react-spectrum/theme-default';
20+
import {Cell, Column, Row, TableBody, TableHeader, TableView} from '../';
21+
<Provider theme={theme}>
22+
<TableView aria-label="Table">
23+
<TableHeader>
24+
<Column>Foo</Column>
25+
<Column>Bar</Column>
26+
<Column>Baz</Column>
27+
</TableHeader>
28+
<TableBody>
29+
<Row>
30+
<Cell>Foo 1</Cell>
31+
<Cell>Bar 1</Cell>
32+
<Cell>Baz 1</Cell>
33+
</Row>
34+
<Row>
35+
<Cell>Foo 2</Cell>
36+
<Cell>Bar 2</Cell>
37+
<Cell>Baz 2</Cell>
38+
</Row>
39+
</TableBody>
40+
</TableView>
41+
</Provider>
42+
`);
43+
});
44+
});

0 commit comments

Comments
 (0)