Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listview display none #6357

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/@react-spectrum/list/stories/ListView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,23 @@ function Demo(props) {
</ListView>
);
}

const manyItems = [];
for (let i = 0; i < 100; i++) {manyItems.push({key: i, name: `item ${i}`});}

export const DisplayNone: ListViewStory = {
render: (args) => (
<div style={{display: 'none'}}>
<ListView aria-label="Dynamic items" items={manyItems} width="300px" height="200px" {...args}>
{(item: any) => (
<Item key={item.key} textValue={item.name}>
<Text>
{item.name}
</Text>
</Item>
)}
</ListView>
</div>
),
name: 'display: none with many items'
};
2 changes: 1 addition & 1 deletion packages/@react-stately/layout/src/ListLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class ListLayout<T> extends Layout<Node<T>> implements KeyboardDelegate,

let layoutNode = this.buildChild(node, 0, y);
y = layoutNode.layoutInfo.rect.maxY;
nodes.push(layoutNode);
this.validRect.height && nodes.push(layoutNode);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the height at this point? 0? undefined?
I think it'd be better to be a little more explicit and check if it's > 0, and if it's undefined, it'd be good to add a !isNaN


if (node.type === 'item' && y > this.validRect.maxY) {
y += (this.collection.size - (nodes.length + skipped)) * rowHeight;
Expand Down