Skip to content

Commit

Permalink
Add collection-no-register-item example (ariakit#3093)
Browse files Browse the repository at this point in the history
Part of ariakit#939

-  Collection with `shouldRegisterItem` set to `false`
  • Loading branch information
renatorib committed Nov 24, 2023
1 parent d440475 commit 3d2b197
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions examples/collection-no-register-item/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import "./style.css";
import * as Ariakit from "@ariakit/react";

export default function Example() {
const collection = Ariakit.useCollectionStore();
const length = collection.useState((state) => state.renderedItems.length);
return (
<Ariakit.Collection store={collection} className="collection">
<div>Items count: {length}</div>
<Ariakit.CollectionItem>🍎 Apple</Ariakit.CollectionItem>
<Ariakit.CollectionItem>🍇 Grape</Ariakit.CollectionItem>
<Ariakit.CollectionItem shouldRegisterItem={false}>
🍊 Orange
</Ariakit.CollectionItem>
</Ariakit.Collection>
);
}
1 change: 1 addition & 0 deletions examples/collection-no-register-item/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url("../collection/style.css");
5 changes: 5 additions & 0 deletions examples/collection-no-register-item/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { q } from "@ariakit/test";

test("should not count unregistered items", async () => {
expect(await q.text.wait("Items count: 2")).toBeInTheDocument();
});

0 comments on commit 3d2b197

Please sign in to comment.