Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions packages/@react-stately/grid/src/GridCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,9 @@ export class GridCollection<T> implements IGridCollection<T> {
getItem(key: Key) {
return this.keyMap.get(key);
}

at(idx: number) {
const keys = [...this.getKeys()];
return this.getItem(keys[idx]);
}
}
5 changes: 5 additions & 0 deletions packages/@react-stately/list/src/ListCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,9 @@ export class ListCollection<T> implements Collection<Node<T>> {
getItem(key: Key) {
return this.keyMap.get(key);
}

at(idx: number) {
const keys = [...this.getKeys()];
return this.getItem(keys[idx]);
}
}
5 changes: 5 additions & 0 deletions packages/@react-stately/table/src/TableCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,9 @@ export class TableCollection<T> extends GridCollection<T> {
getItem(key: Key) {
return this.keyMap.get(key);
}

at(idx: number) {
const keys = [...this.getKeys()];
return this.getItem(keys[idx]);
}
}
5 changes: 5 additions & 0 deletions packages/@react-stately/tree/src/TreeCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ export class TreeCollection<T> implements Collection<Node<T>> {
getItem(key: Key) {
return this.keyMap.get(key);
}

at(idx: number) {
const keys = [...this.getKeys()];
return this.getItem(keys[idx]);
}
}
3 changes: 3 additions & 0 deletions packages/@react-types/shared/src/collections.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ export interface Collection<T> extends Iterable<T> {
/** Get an item by its key. */
getItem(key: Key): T,

/** Get an item by the index of its key. */
at(idx: number): T,

/** Get the key that comes before the given key in the collection. */
getKeyBefore(key: Key): Key | null,

Expand Down