Skip to content

Commit 739e93f

Browse files
committed
addressing more review comments
1 parent 2c89783 commit 739e93f

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

packages/@react-aria/autocomplete/src/useAutocomplete.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ export interface AriaAutocompleteOptions extends Omit<AriaAutocompleteProps, 'ch
5050
collectionRef: RefObject<HTMLElement | null>
5151
}
5252

53-
export interface AutocompleteAria {
53+
export interface AutocompleteAria<T> {
5454
/** Props for the autocomplete textfield/searchfield element. These should be passed to the textfield/searchfield aria hooks respectively. */
5555
textFieldProps: AriaTextFieldProps,
5656
/** Props for the collection, to be passed to collection's respective aria hook (e.g. useMenu). */
5757
collectionProps: CollectionOptions,
5858
/** Ref to attach to the wrapped collection. */
5959
collectionRef: RefObject<HTMLElement | null>,
6060
/** A filter function that returns if the provided collection node should be filtered out of the collection. */
61-
filter?: (nodeTextValue: string, node: Node<unknown>) => boolean
61+
filter?: (nodeTextValue: string, node: Node<T>) => boolean
6262
}
6363

6464
/**
@@ -67,7 +67,7 @@ export interface AutocompleteAria {
6767
* @param props - Props for the autocomplete.
6868
* @param state - State for the autocomplete, as returned by `useAutocompleteState`.
6969
*/
70-
export function useAutocomplete(props: AriaAutocompleteOptions, state: AutocompleteState): AutocompleteAria {
70+
export function useAutocomplete<T>(props: AriaAutocompleteOptions, state: AutocompleteState): AutocompleteAria<T> {
7171
let {
7272
inputRef,
7373
collectionRef,

packages/@react-aria/collections/src/Document.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,15 @@ export class ElementNode<T> extends BaseNode<T> {
259259
nodeType = 8; // COMMENT_NODE (we'd use ELEMENT_NODE but React DevTools will fail to get its dimensions)
260260
// TODO: running with assumption that setProps will be called before any other calls to node are made so theoretically
261261
// node will be defined
262-
node: CollectionNode<T> | null;
262+
private _node: CollectionNode<T> | null;
263263
isMutated = true;
264264
private _index: number = 0;
265265
hasSetProps = false;
266266
isHidden = false;
267267

268268
constructor(type: string, ownerDocument: Document<T, any>) {
269269
super(ownerDocument);
270-
this.node = null;
270+
this._node = null;
271271
}
272272

273273
get index(): number {
@@ -287,6 +287,17 @@ export class ElementNode<T> extends BaseNode<T> {
287287
return 0;
288288
}
289289

290+
get node(): CollectionNode<T> | null {
291+
if (this._node == null && process.env.NODE_ENV !== 'production') {
292+
console.error('Attempted to access node before it was defined. Check if setProps wasn\'t called before attempting to access the node.');
293+
}
294+
return this._node;
295+
}
296+
297+
set node(node: CollectionNode<T>) {
298+
this._node = node;
299+
}
300+
290301
/**
291302
* Lazily gets a mutable instance of a Node. If the node has already
292303
* been cloned during this update cycle, it just returns the existing one.

0 commit comments

Comments
 (0)