diff --git a/packages/@react-spectrum/s2/stories/ComboBox.stories.tsx b/packages/@react-spectrum/s2/stories/ComboBox.stories.tsx index 19af5c3f3d1..d2089a5e072 100644 --- a/packages/@react-spectrum/s2/stories/ComboBox.stories.tsx +++ b/packages/@react-spectrum/s2/stories/ComboBox.stories.tsx @@ -27,7 +27,7 @@ const meta: Meta> = { }, tags: ['autodocs'], argTypes: { - ...categorizeArgTypes('Events', ['onInputChange', 'onOpenChange', 'onSelectionChange']), + ...categorizeArgTypes('Events', ['onInputChange', 'onOpenChange', 'onSelectionChange', 'onLoadMore']), label: {control: {type: 'text'}}, description: {control: {type: 'text'}}, errorMessage: {control: {type: 'text'}}, diff --git a/packages/@react-spectrum/s2/stories/Picker.stories.tsx b/packages/@react-spectrum/s2/stories/Picker.stories.tsx index 7685f4f5c43..d7c826789ed 100644 --- a/packages/@react-spectrum/s2/stories/Picker.stories.tsx +++ b/packages/@react-spectrum/s2/stories/Picker.stories.tsx @@ -41,7 +41,7 @@ const meta: Meta> = { decorators: [StaticColorDecorator], tags: ['autodocs'], argTypes: { - ...categorizeArgTypes('Events', ['onOpenChange', 'onSelectionChange']), + ...categorizeArgTypes('Events', ['onOpenChange', 'onSelectionChange', 'onLoadMore']), label: {control: {type: 'text'}}, description: {control: {type: 'text'}}, errorMessage: {control: {type: 'text'}}, diff --git a/packages/@react-stately/list/src/ListCollection.ts b/packages/@react-stately/list/src/ListCollection.ts index ce82a4f664b..67dfcf89e0d 100644 --- a/packages/@react-stately/list/src/ListCollection.ts +++ b/packages/@react-stately/list/src/ListCollection.ts @@ -17,20 +17,17 @@ export class ListCollection implements Collection> { private iterable: Iterable>; private firstKey: Key | null = null; private lastKey: Key | null = null; + private _size: number; constructor(nodes: Iterable>) { this.iterable = nodes; let visit = (node: Node) => { - // Skip the loader node so it isn't added to the keymap and thus - // doesn't influence the size count. This should only matter for RAC and S2 - if (node.type !== 'loader') { - this.keyMap.set(node.key, node); - - if (node.childNodes && node.type === 'section') { - for (let child of node.childNodes) { - visit(child); - } + this.keyMap.set(node.key, node); + + if (node.childNodes && node.type === 'section') { + for (let child of node.childNodes) { + visit(child); } } }; @@ -41,6 +38,7 @@ export class ListCollection implements Collection> { let last: Node | null = null; let index = 0; + let size = 0; for (let [key, node] of this.keyMap) { if (last) { last.nextKey = key; @@ -54,13 +52,19 @@ export class ListCollection implements Collection> { node.index = index++; } + // Only count sections and items when determining size so that + // loaders and separators in RAC/S2 don't influence the emptyState determination + if (node.type === 'section' || node.type === 'item') { + size++; + } + last = node; // Set nextKey as undefined since this might be the last node // If it isn't the last node, last.nextKey will properly set at start of new loop last.nextKey = undefined; } - + this._size = size; this.lastKey = last?.key ?? null; } @@ -69,7 +73,7 @@ export class ListCollection implements Collection> { } get size(): number { - return this.keyMap.size; + return this._size; } getKeys(): IterableIterator {