Skip to content

Commit bfb96f9

Browse files
committed
Do not base autocomplete width on input size
Since react-aria 3.41.0, this would result in the listbox disappearing when the user pressed "Down". It's not entirely clear to me what specifically is causing this, but at this point it's not worth it to invest more time into debugging it, when the default width looks fine too.
1 parent fb1b4de commit bfb96f9

File tree

4 files changed

+6
-39
lines changed

4 files changed

+6
-39
lines changed

src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPageRedesign.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ describe("Settings page redesign", () => {
792792
const input = screen.getByLabelText("City and state*");
793793
await act(async () => {
794794
await user.clear(input);
795-
await user.keyboard("[Tab]Tu[ArrowDown][Enter][Tab]");
795+
await user.keyboard("Tu[ArrowDown][Enter][Tab]");
796796
});
797797
expect(input).toHaveValue("Tulsa, OK, USA");
798798
});
@@ -814,7 +814,8 @@ describe("Settings page redesign", () => {
814814

815815
const input = screen.getByLabelText("Past location");
816816
await act(async () => {
817-
await user.keyboard("[Tab]Tu[ArrowDown][Enter][Tab]");
817+
await user.click(input);
818+
await user.keyboard("Tu[ArrowDown][Enter][Tab]");
818819
});
819820
expect(input).toHaveValue("Tulsa, OK, USA");
820821
});

src/app/components/client/ComboBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ function ComboBox(
9191
popoverRef={popoverRef}
9292
state={state}
9393
triggerRef={inputRef}
94+
placement="bottom start"
9495
>
9596
<div className={comboBoxStyles.popoverList}>
9697
<ListBox
9798
{...listBoxProps}
9899
listBoxRef={listBoxRef}
99100
listPlaceholder={listPlaceholder}
100-
parentRef={inputRef}
101101
state={state}
102102
/>
103103
</div>

src/app/components/client/ListBox.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import { ReactElement, ReactNode, RefObject, useRef } from "react";
88
import { AriaListBoxOptions, useListBox, useOption } from "react-aria";
99
import { ListState } from "react-stately";
10-
import { useElementWidth } from "../../hooks/useElementWidth";
1110
import styles from "./ListBox.module.scss";
1211

1312
export interface OptionProps extends AriaListBoxOptions<unknown> {
@@ -45,27 +44,21 @@ function Option({ item, state }: OptionProps) {
4544
export interface ListBoxProps extends AriaListBoxOptions<unknown> {
4645
state: ListState<object>;
4746
listBoxRef: RefObject<HTMLUListElement | null>;
48-
parentRef?: RefObject<HTMLInputElement | null>;
4947
listPlaceholder?: ReactElement;
5048
}
5149

5250
// TODO: Add unit test when changing this code:
5351
/* c8 ignore start */
5452
function ListBox(props: ListBoxProps) {
55-
const { listBoxRef, parentRef, state, listPlaceholder } = props;
53+
const { listBoxRef, state, listPlaceholder } = props;
5654
const { listBoxProps } = useListBox(props, state, listBoxRef);
5755

58-
const parentWidth = useElementWidth(parentRef);
59-
6056
return (
6157
<ul
6258
{...listBoxProps}
6359
ref={listBoxRef}
6460
className={styles.listBox}
65-
style={{
66-
...listBoxProps.style,
67-
...(parentWidth && { width: `${parentWidth}px` }),
68-
}}
61+
style={listBoxProps.style}
6962
>
7063
{[...state.collection].map((item) => (
7164
<Option key={item.key} item={item} state={state} />

src/app/hooks/useElementWidth.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)