Merge pull request #38830 from BerriAI/litellm_paginated_select_deletion_query

fix(ui): keep a deleted-from search query instead of blanking the box

(cherry picked from commit b3235fa786)
This commit is contained in:
yuneng-jiang 2026-08-29 15:57:51 -07:00 committed by Yuneng Jiang
parent eb67432174
commit fdd424a45a
No known key found for this signature in database
2 changed files with 34 additions and 1 deletions

View file

@ -361,4 +361,32 @@ describe("PaginatedSearchSelect", () => {
await user.click(screen.getByRole("combobox"));
expect(await screen.findByTestId("paginated-search-select-loading-more")).toBeInTheDocument();
});
it("queries the trimmed label when a character is deleted from the end of the selection", async () => {
const user = userEvent.setup();
const onSearchChange = vi.fn();
renderSelect({ onSearchChange, value: "alias-alpha" });
const input = screen.getByRole("combobox") as HTMLInputElement;
input.focus();
input.setSelectionRange(input.value.length, input.value.length);
await user.keyboard("{Backspace}");
expect(input).toHaveValue("alias-alph");
await waitFor(() => expect(onSearchChange).toHaveBeenLastCalledWith("alias-alph"));
});
it("queries what is left when a character is deleted from inside the selection", async () => {
const user = userEvent.setup();
const onSearchChange = vi.fn();
renderSelect({ onSearchChange, value: "alias-alpha" });
const input = screen.getByRole("combobox") as HTMLInputElement;
input.focus();
input.setSelectionRange(6, 6);
await user.keyboard("{Backspace}");
expect(input).toHaveValue("aliasalpha");
await waitFor(() => expect(onSearchChange).toHaveBeenLastCalledWith("aliasalpha"));
});
});

View file

@ -50,6 +50,11 @@ const typedInsertion = (previous: string, next: string): string => {
return next.slice(start, next.length - end);
};
const editedQuery = (label: string, next: string): string => {
const inserted = typedInsertion(label, next);
return inserted === "" && next !== label ? next : inserted;
};
export function PaginatedSearchSelect({
options,
value,
@ -101,7 +106,7 @@ export function PaginatedSearchSelect({
const replacedWholeInput = wholeSelectionRef.current;
wholeSelectionRef.current = false;
handleInputValueChange(
typedQuery === null && !replacedWholeInput ? typedInsertion(selected?.label ?? "", next) : next,
typedQuery === null && !replacedWholeInput ? editedQuery(selected?.label ?? "", next) : next,
reason,
);
};