Skip to content

Commit 0d68f68

Browse files
committed
updating tests and making enter trigger listbox link
1 parent c13544b commit 0d68f68

File tree

6 files changed

+428
-341
lines changed

6 files changed

+428
-341
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ export function useAutocomplete(props: AriaAutocompleteOptions, state: Autocompl
197197
item?.dispatchEvent(
198198
new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)
199199
);
200+
// TODO: this currently has problems making Enter trigger Listbox links. usePress catches the press up that happens but
201+
// detects that the press target is different from the event target aka listbox item vs the input where the Enter event occurs...
200202
}
201203
};
202204

@@ -232,7 +234,7 @@ export function useAutocomplete(props: AriaAutocompleteOptions, state: Autocompl
232234
spellCheck: 'false'
233235
},
234236
collectionProps: mergeProps(collectionProps, {
235-
// TODO: shouldFocusOnHover?
237+
// TODO: shouldFocusOnHover? shouldFocusWrap? Should it be up to the wrapped collection?
236238
shouldUseVirtualFocus: true,
237239
disallowTypeAhead: true
238240
}),

packages/@react-aria/interactions/src/usePress.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ export function usePress(props: PressHookProps): PressResult {
787787
]);
788788

789789
// Remove user-select: none in case component unmounts immediately after pressStart
790-
790+
791791
useEffect(() => {
792792
return () => {
793793
if (!allowTextSelectionOnPress) {

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

+7
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
295295
) {
296296
onSelect(e);
297297
}
298+
299+
// TODO: non ideal since this makes the link action happen on press start rather than on press up like it usually
300+
// does for listboxes but we never get the onPress event because the simiulated event target from useAutocomplete is different
301+
// from the actual place it is triggered from (the input).
302+
if (shouldUseVirtualFocus && e.pointerType === 'keyboard' && hasAction) {
303+
performAction(e);
304+
}
298305
};
299306

300307
itemPressProps.onPress = (e) => {

packages/react-aria-components/stories/Autocomplete.stories.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ export const AutocompleteWithListbox = {
348348
<MyListBoxItem>Foo</MyListBoxItem>
349349
<MyListBoxItem>Bar</MyListBoxItem>
350350
<MyListBoxItem>Baz</MyListBoxItem>
351+
<MyListBoxItem href="http://google.com">Google</MyListBoxItem>
351352
</ListBoxSection>
352353
<Separator style={{borderTop: '1px solid gray', margin: '2px 5px'}} />
353354
<ListBoxSection className={styles.group} aria-label="Section 2">

0 commit comments

Comments
 (0)