-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: (WIP) Autocomplete context refactor #8695
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
base: baseCollection_filter
Are you sure you want to change the base?
Changes from 7 commits
c111744
24dd7cb
d8969a7
ae3cc84
3a81f31
db91b3a
7177106
dfb80f3
ec8066f
76107ff
cde0977
82cb364
18d3dbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
|
||
import {AriaListBoxOptions, AriaListBoxProps, DraggableItemResult, DragPreviewRenderer, DroppableCollectionResult, DroppableItemResult, FocusScope, ListKeyboardDelegate, mergeProps, useCollator, useFocusRing, useHover, useListBox, useListBoxSection, useLocale, useOption} from 'react-aria'; | ||
import {Collection, CollectionBuilder, createBranchComponent, createLeafComponent, FilterLessNode, ItemNode, SectionNode} from '@react-aria/collections'; | ||
import {CollectionContext} from './Autocomplete'; | ||
import {CollectionProps, CollectionRendererContext, ItemRenderProps, SectionContext, SectionProps} from './Collection'; | ||
import {ContextValue, DEFAULT_SLOT, Provider, RenderProps, SlotProps, StyleProps, StyleRenderProps, useContextProps, useRenderProps, useSlot} from './utils'; | ||
import {DragAndDropContext, DropIndicatorContext, DropIndicatorProps, useDndPersistedKeys, useRenderDropIndicator} from './DragAndDrop'; | ||
|
@@ -23,7 +24,6 @@ import {HeaderContext} from './Header'; | |
import React, {createContext, ForwardedRef, forwardRef, JSX, ReactNode, useContext, useEffect, useMemo, useRef} from 'react'; | ||
import {SeparatorContext} from './Separator'; | ||
import {TextContext} from './Text'; | ||
import {UNSTABLE_InternalAutocompleteContext} from './Autocomplete'; | ||
|
||
export interface ListBoxRenderProps { | ||
/** | ||
|
@@ -120,7 +120,7 @@ interface ListBoxInnerProps<T> { | |
} | ||
|
||
function ListBoxInner<T extends object>({state: inputState, props, listBoxRef}: ListBoxInnerProps<T>) { | ||
let {filter, collectionProps, collectionRef} = useContext(UNSTABLE_InternalAutocompleteContext) || {}; | ||
let {filter, collectionRef, ...collectionProps} = useContext(CollectionContext) || {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are we still using not actually attached to this line, but it's nearby There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good question, I think I'm going to lean towards keeping these UNSTABLE for now since it is used in GridList who's Autocomplete virtual behavior isn't completely ironed out yet (I don't think there will be any changes there but just for safety). |
||
props = useMemo(() => collectionProps ? ({...props, ...collectionProps}) : props, [props, collectionProps]); | ||
let {dragAndDropHooks, layout = 'stack', orientation = 'vertical'} = props; | ||
// Memoed so that useAutocomplete callback ref is properly only called once on mount and not everytime a rerender happens | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import {AriaMenuProps, FocusScope, mergeProps, useHover, useMenu, useMenuItem, useMenuSection, useMenuTrigger, useSubmenuTrigger} from 'react-aria'; | ||
import {BaseCollection, Collection, CollectionBuilder, CollectionNode, createBranchComponent, createLeafComponent, ItemNode, SectionNode} from '@react-aria/collections'; | ||
import {MenuTriggerProps as BaseMenuTriggerProps, Collection as ICollection, Node, RootMenuTriggerState, TreeState, useMenuTriggerState, useSubmenuTriggerState, useTreeState} from 'react-stately'; | ||
import {CollectionContext} from './Autocomplete'; | ||
import {CollectionProps, CollectionRendererContext, ItemRenderProps, SectionContext, SectionProps, usePersistedKeys} from './Collection'; | ||
import {ContextValue, DEFAULT_SLOT, Provider, RenderProps, SlotProps, StyleRenderProps, useContextProps, useRenderProps, useSlot, useSlottedContext} from './utils'; | ||
import {filterDOMProps, mergeRefs, useObjectRef, useResizeObserver} from '@react-aria/utils'; | ||
|
@@ -39,7 +40,6 @@ import React, { | |
} from 'react'; | ||
import {SeparatorContext} from './Separator'; | ||
import {TextContext} from './Text'; | ||
import {UNSTABLE_InternalAutocompleteContext} from './Autocomplete'; | ||
|
||
export const MenuContext = createContext<ContextValue<MenuProps<any>, HTMLDivElement>>(null); | ||
export const MenuStateContext = createContext<TreeState<any> | null>(null); | ||
|
@@ -202,7 +202,7 @@ interface MenuInnerProps<T> { | |
} | ||
|
||
function MenuInner<T extends object>({props, collection, menuRef: ref}: MenuInnerProps<T>) { | ||
let {filter, collectionProps: autocompleteMenuProps, collectionRef} = useContext(UNSTABLE_InternalAutocompleteContext) || {}; | ||
let {filter, collectionRef, ...autocompleteMenuProps} = useContext(CollectionContext) || {}; | ||
// Memoed so that useAutocomplete callback ref is properly only called once on mount and not everytime a rerender happens | ||
ref = useObjectRef(useMemo(() => mergeRefs(ref, collectionRef !== undefined ? collectionRef as RefObject<HTMLDivElement> : null), [collectionRef, ref])); | ||
let filteredCollection = useMemo(() => filter ? collection.filter(filter) : collection, [collection, filter]); | ||
|
@@ -251,7 +251,7 @@ function MenuInner<T extends object>({props, collection, menuRef: ref}: MenuInne | |
[SectionContext, {name: 'MenuSection', render: MenuSectionInner}], | ||
[SubmenuTriggerContext, {parentMenuRef: ref, shouldUseVirtualFocus: autocompleteMenuProps?.shouldUseVirtualFocus}], | ||
[MenuItemContext, null], | ||
[UNSTABLE_InternalAutocompleteContext, null], | ||
[CollectionContext, null], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should ListBox and GridList also clear this now that we support nested grids? ex TagGroup inside Cell? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should also clear the new input context There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think ListBox needs to since it doesn't support nested collections or interactive elements in its options, but GridList/TableView is a good call. I'll also clear the input context as well |
||
[SelectionManagerContext, state.selectionManager], | ||
/* Ensure root MenuTriggerState is defined, in case Menu is rendered outside a MenuTrigger. */ | ||
/* We assume the context can never change between defined and undefined. */ | ||
|
Uh oh!
There was an error while loading. Please reload this page.