Skip to content

Commit 216cd6d

Browse files
authored
fix: properly render empty state when filtering S2 ComboBox with sections (#8735)
1 parent 4a37eb8 commit 216cd6d

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

packages/@react-spectrum/s2/stories/ComboBox.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const meta: Meta<typeof ComboBox<any>> = {
2727
},
2828
tags: ['autodocs'],
2929
argTypes: {
30-
...categorizeArgTypes('Events', ['onInputChange', 'onOpenChange', 'onSelectionChange']),
30+
...categorizeArgTypes('Events', ['onInputChange', 'onOpenChange', 'onSelectionChange', 'onLoadMore']),
3131
label: {control: {type: 'text'}},
3232
description: {control: {type: 'text'}},
3333
errorMessage: {control: {type: 'text'}},

packages/@react-spectrum/s2/stories/Picker.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const meta: Meta<typeof Picker<any>> = {
4141
decorators: [StaticColorDecorator],
4242
tags: ['autodocs'],
4343
argTypes: {
44-
...categorizeArgTypes('Events', ['onOpenChange', 'onSelectionChange']),
44+
...categorizeArgTypes('Events', ['onOpenChange', 'onSelectionChange', 'onLoadMore']),
4545
label: {control: {type: 'text'}},
4646
description: {control: {type: 'text'}},
4747
errorMessage: {control: {type: 'text'}},

packages/@react-stately/list/src/ListCollection.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,17 @@ export class ListCollection<T> implements Collection<Node<T>> {
1717
private iterable: Iterable<Node<T>>;
1818
private firstKey: Key | null = null;
1919
private lastKey: Key | null = null;
20+
private _size: number;
2021

2122
constructor(nodes: Iterable<Node<T>>) {
2223
this.iterable = nodes;
2324

2425
let visit = (node: Node<T>) => {
25-
// Skip the loader node so it isn't added to the keymap and thus
26-
// doesn't influence the size count. This should only matter for RAC and S2
27-
if (node.type !== 'loader') {
28-
this.keyMap.set(node.key, node);
29-
30-
if (node.childNodes && node.type === 'section') {
31-
for (let child of node.childNodes) {
32-
visit(child);
33-
}
26+
this.keyMap.set(node.key, node);
27+
28+
if (node.childNodes && node.type === 'section') {
29+
for (let child of node.childNodes) {
30+
visit(child);
3431
}
3532
}
3633
};
@@ -41,6 +38,7 @@ export class ListCollection<T> implements Collection<Node<T>> {
4138

4239
let last: Node<T> | null = null;
4340
let index = 0;
41+
let size = 0;
4442
for (let [key, node] of this.keyMap) {
4543
if (last) {
4644
last.nextKey = key;
@@ -54,13 +52,19 @@ export class ListCollection<T> implements Collection<Node<T>> {
5452
node.index = index++;
5553
}
5654

55+
// Only count sections and items when determining size so that
56+
// loaders and separators in RAC/S2 don't influence the emptyState determination
57+
if (node.type === 'section' || node.type === 'item') {
58+
size++;
59+
}
60+
5761
last = node;
5862

5963
// Set nextKey as undefined since this might be the last node
6064
// If it isn't the last node, last.nextKey will properly set at start of new loop
6165
last.nextKey = undefined;
6266
}
63-
67+
this._size = size;
6468
this.lastKey = last?.key ?? null;
6569
}
6670

@@ -69,7 +73,7 @@ export class ListCollection<T> implements Collection<Node<T>> {
6973
}
7074

7175
get size(): number {
72-
return this.keyMap.size;
76+
return this._size;
7377
}
7478

7579
getKeys(): IterableIterator<Key> {

0 commit comments

Comments
 (0)