Skip to content

Commit 9368a89

Browse files
authored
Fix typeahead in RAC ListBox (#5146)
1 parent 3c3485f commit 9368a89

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/@react-aria/selection/src/ListKeyboardDelegate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {Key, RefObject} from 'react';
1717
interface ListKeyboardDelegateOptions<T> {
1818
collection: Collection<Node<T>>,
1919
ref: RefObject<HTMLElement>,
20+
collator?: Intl.Collator,
2021
layout?: 'stack' | 'grid',
2122
orientation?: Orientation,
2223
direction?: Direction,
@@ -27,7 +28,7 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
2728
private collection: Collection<Node<T>>;
2829
private disabledKeys: Set<Key>;
2930
private ref: RefObject<HTMLElement>;
30-
private collator: Intl.Collator;
31+
private collator: Intl.Collator | undefined;
3132
private layout: 'stack' | 'grid';
3233
private orientation?: Orientation;
3334
private direction?: Direction;
@@ -39,6 +40,7 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
3940
let opts = args[0] as ListKeyboardDelegateOptions<T>;
4041
this.collection = opts.collection;
4142
this.ref = opts.ref;
43+
this.collator = opts.collator;
4244
this.disabledKeys = opts.disabledKeys || new Set();
4345
this.orientation = opts.orientation;
4446
this.direction = opts.direction;

packages/react-aria-components/src/ListBox.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {AriaListBoxOptions, AriaListBoxProps, DraggableItemResult, DragPreviewRenderer, DroppableCollectionResult, DroppableItemResult, FocusScope, ListKeyboardDelegate, mergeProps, useFocusRing, useHover, useListBox, useListBoxSection, useLocale, useOption} from 'react-aria';
13+
import {AriaListBoxOptions, AriaListBoxProps, DraggableItemResult, DragPreviewRenderer, DroppableCollectionResult, DroppableItemResult, FocusScope, ListKeyboardDelegate, mergeProps, useCollator, useFocusRing, useHover, useListBox, useListBoxSection, useLocale, useOption} from 'react-aria';
1414
import {CollectionDocumentContext, CollectionPortal, CollectionProps, ItemProps, useCachedChildren, useCollection} from './Collection';
1515
import {ContextValue, forwardRefType, HiddenContext, Provider, SlotProps, StyleProps, StyleRenderProps, useContextProps, useRenderProps, useSlot, useSlottedContext} from './utils';
1616
import {DragAndDropContext, DragAndDropHooks, DropIndicator, DropIndicatorContext, DropIndicatorProps} from './useDragAndDrop';
@@ -130,16 +130,18 @@ function ListBoxInner<T>({state, props, listBoxRef}: ListBoxInnerProps<T>) {
130130
let isListDroppable = !!dragAndDropHooks?.useDroppableCollectionState;
131131
let {direction} = useLocale();
132132
let {disabledBehavior, disabledKeys} = selectionManager;
133+
let collator = useCollator({usage: 'search', sensitivity: 'base'});
133134
let keyboardDelegate = useMemo(() => (
134135
props.keyboardDelegate || new ListKeyboardDelegate({
135136
collection,
137+
collator,
136138
ref: listBoxRef,
137139
disabledKeys: disabledBehavior === 'selection' ? new Set<React.Key>() : disabledKeys,
138140
layout,
139141
orientation,
140142
direction
141143
})
142-
), [collection, listBoxRef, disabledBehavior, disabledKeys, orientation, direction, props.keyboardDelegate, layout]);
144+
), [collection, collator, listBoxRef, disabledBehavior, disabledKeys, orientation, direction, props.keyboardDelegate, layout]);
143145

144146
let {listBoxProps} = useListBox({
145147
...props,

0 commit comments

Comments
 (0)