Skip to content

Commit ff623ed

Browse files
committed
fix row count
1 parent ce6baf9 commit ff623ed

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

packages/@react-aria/table/src/useTable.ts

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

13-
import {announce} from '@react-aria/live-announcer';
14-
import {GridAria, GridProps, useGrid} from '@react-aria/grid';
15-
import {gridIds} from './utils';
13+
import { announce } from '@react-aria/live-announcer';
14+
import { GridAria, GridProps, useGrid } from '@react-aria/grid';
15+
import { gridIds } from './utils';
1616
// @ts-ignore
1717
import intlMessages from '../intl/*.json';
18-
import {Layout} from '@react-stately/virtualizer';
19-
import {mergeProps, useDescription, useId, useUpdateEffect} from '@react-aria/utils';
20-
import {Node} from '@react-types/shared';
21-
import {RefObject, useMemo} from 'react';
22-
import {TableKeyboardDelegate} from './TableKeyboardDelegate';
23-
import {TableState} from '@react-stately/table';
24-
import {useCollator, useLocale} from '@react-aria/i18n';
25-
import {useLocalizedStringFormatter} from '@react-aria/i18n';
18+
import { Layout } from '@react-stately/virtualizer';
19+
import { mergeProps, useDescription, useId, useUpdateEffect } from '@react-aria/utils';
20+
import { Node } from '@react-types/shared';
21+
import { RefObject, useMemo } from 'react';
22+
import { TableKeyboardDelegate } from './TableKeyboardDelegate';
23+
import { TableState } from '@react-stately/table';
24+
import { useCollator, useLocale } from '@react-aria/i18n';
25+
import { useLocalizedStringFormatter } from '@react-aria/i18n';
2626

2727
export interface AriaTableProps<T> extends GridProps {
2828
/** The layout object for the table. Computes what content is visible and how to position and style them. */
@@ -46,8 +46,8 @@ export function useTable<T>(props: AriaTableProps<T>, state: TableState<T>, ref:
4646

4747
// By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
4848
// When virtualized, the layout object will be passed in as a prop and override this.
49-
let collator = useCollator({usage: 'search', sensitivity: 'base'});
50-
let {direction} = useLocale();
49+
let collator = useCollator({ usage: 'search', sensitivity: 'base' });
50+
let { direction } = useLocale();
5151
let disabledBehavior = state.selectionManager.disabledBehavior;
5252
let delegate = useMemo(() => keyboardDelegate || new TableKeyboardDelegate({
5353
collection: state.collection,
@@ -60,7 +60,7 @@ export function useTable<T>(props: AriaTableProps<T>, state: TableState<T>, ref:
6060
let id = useId(props.id);
6161
gridIds.set(state, id);
6262

63-
let {gridProps} = useGrid({
63+
let { gridProps } = useGrid({
6464
...props,
6565
id,
6666
keyboardDelegate: delegate
@@ -69,15 +69,15 @@ export function useTable<T>(props: AriaTableProps<T>, state: TableState<T>, ref:
6969
// Override to include header rows
7070
if (isVirtualized) {
7171
// TODO Rob: fix headerRows
72-
gridProps['aria-rowcount'] = state.collection.size; // + state.collection.headerRows.length;
72+
gridProps['aria-rowcount'] = state.collection.size + (state.collection.getItem(state.collection.head.lastChildKey)?.index ?? 0) + 1;
7373
}
7474

75-
let {column, direction: sortDirection} = state.sortDescriptor || {};
75+
let { column, direction: sortDirection } = state.sortDescriptor || {};
7676
let stringFormatter = useLocalizedStringFormatter(intlMessages);
7777
let sortDescription = useMemo(() => {
7878
let columnName = state.collection.columns.find(c => c.key === column)?.textValue;
79-
return sortDirection && column ? stringFormatter.format(`${sortDirection}Sort`, {columnName}) : undefined;
80-
// eslint-disable-next-line react-hooks/exhaustive-deps
79+
return sortDirection && column ? stringFormatter.format(`${sortDirection}Sort`, { columnName }) : undefined;
80+
// eslint-disable-next-line react-hooks/exhaustive-deps
8181
}, [sortDirection, column, state.collection.columns]);
8282

8383
let descriptionProps = useDescription(sortDescription);

packages/@react-spectrum/table/test/Table.test.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
2-
* Copyright 2020 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-
*/
2+
* Copyright 2020 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+
*/
1212

1313
jest.mock('@react-aria/live-announcer');
1414
import { act, fireEvent, installPointerEvent, render as renderComponent, triggerPress, typeText, within } from '@react-spectrum/test-utils';
@@ -246,8 +246,8 @@ describe('TableView', function() {
246246

247247
let rows = within(rowgroups[1]).getAllByRole('row');
248248
expect(rows).toHaveLength(2);
249-
expect(rows[0]).toHaveAttribute('aria-rowindex', '1');
250-
expect(rows[1]).toHaveAttribute('aria-rowindex', '2');
249+
expect(rows[0]).toHaveAttribute('aria-rowindex', '2');
250+
expect(rows[1]).toHaveAttribute('aria-rowindex', '3');
251251

252252
let rowheader = within(rows[0]).getByRole('rowheader');
253253
expect(rowheader).toHaveTextContent('Foo 1');
@@ -300,7 +300,7 @@ describe('TableView', function() {
300300
expect(grid).toHaveAttribute('aria-label', 'Table');
301301
expect(grid).toHaveAttribute('data-testid', 'test');
302302
expect(grid).toHaveAttribute('aria-multiselectable', 'true');
303-
expect(grid).toHaveAttribute('aria-rowcount', '3');
303+
expect(grid).toHaveAttribute('aria-rowcount', '2');
304304
expect(grid).toHaveAttribute('aria-colcount', '4');
305305

306306
let rowgroups = within(grid).getAllByRole('rowgroup');
@@ -3541,9 +3541,9 @@ describe('TableView', function() {
35413541

35423542
rows = within(table).getAllByRole('row');
35433543
expect(rows).toHaveLength(4);
3544-
expect(rows[1]).toHaveAttribute('aria-rowindex', '1');
3545-
expect(rows[2]).toHaveAttribute('aria-rowindex', '2');
3546-
expect(rows[3]).toHaveAttribute('aria-rowindex', '3');
3544+
expect(rows[1]).toHaveAttribute('aria-rowindex', '2');
3545+
expect(rows[2]).toHaveAttribute('aria-rowindex', '3');
3546+
expect(rows[3]).toHaveAttribute('aria-rowindex', '4');
35473547

35483548

35493549
let rowHeaders = within(rows[1]).getAllByRole('rowheader');
@@ -3641,7 +3641,7 @@ describe('TableView', function() {
36413641
let rowHeaders = within(rows[1]).getAllByRole('rowheader');
36423642
expect(rowHeaders[0]).toHaveTextContent('Julia');
36433643

3644-
expect(rows[1]).toHaveAttribute('aria-rowindex', '1');
3644+
expect(rows[1]).toHaveAttribute('aria-rowindex', '2');
36453645
});
36463646

36473647
it('can bulk remove items', async function() {

0 commit comments

Comments
 (0)