Skip to content

Commit 1eb421e

Browse files
committed
make sure listbox doesnt add extranous padding above the empty state when empty or loading
since we are now rendering the virtualizer body if there is a loading sentinel, we dont want to add padding to the body rect calc since that will push the renderEmpty node down. Not a problem in TableLayout it seems
1 parent 63db21e commit 1eb421e

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,6 @@ const ComboboxInner = forwardRef(function ComboboxInner(props: ComboBoxProps<any
590590
</>
591591
);
592592
}
593-
594-
let isEmptyOrLoading = state?.collection?.size === 0 || (state?.collection.size === 1 && state.collection.getItem(state.collection.getFirstKey()!)!.type === 'loader');
595593
let scale = useScale();
596594

597595
return (
@@ -689,10 +687,7 @@ const ComboboxInner = forwardRef(function ComboboxInner(props: ComboBoxProps<any
689687
layout={ListLayout}
690688
layoutOptions={{
691689
estimatedRowHeight: 32,
692-
// TODO: can we get rid of this and instead handle padding else where other than the layout options? Kinda gross that we need to do this check.
693-
// Perhaps can consider only applying padding if the collection actually has content since the renderEmptyState content is outside the virtualizer
694-
// Otherwise could consider moving renderEmptyState into the collection...
695-
padding: isEmptyOrLoading ? 0 : 8,
690+
padding: 8,
696691
estimatedHeadingHeight: 50,
697692
loaderHeight: LOADER_ROW_HEIGHTS[size][scale]
698693
}}>

packages/@react-stately/layout/src/ListLayout.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,13 @@ export class ListLayout<T, O extends ListLayoutOptions = ListLayoutOptions> exte
255255
let collection = this.virtualizer!.collection;
256256
let skipped = 0;
257257
let nodes: LayoutNode[] = [];
258+
let isEmptyOrLoading = collection?.size === 0 || (collection.size === 1 && collection.getItem(collection.getFirstKey()!)!.type === 'loader');
259+
if (isEmptyOrLoading) {
260+
y = 0;
261+
}
262+
258263
for (let node of collection) {
259264
let rowHeight = (this.rowHeight ?? this.estimatedRowHeight ?? DEFAULT_HEIGHT) + this.gap;
260-
261265
// Skip rows before the valid rectangle unless they are already cached.
262266
if (node.type === 'item' && y + rowHeight < this.requestedRect.y && !this.isValid(node, y)) {
263267
y += rowHeight;
@@ -289,7 +293,7 @@ export class ListLayout<T, O extends ListLayoutOptions = ListLayoutOptions> exte
289293
}
290294

291295
y -= this.gap;
292-
y += this.padding;
296+
y += isEmptyOrLoading ? 0 : this.padding;
293297
this.contentSize = new Size(this.virtualizer!.visibleRect.width, y);
294298
return nodes;
295299
}

0 commit comments

Comments
 (0)