Skip to content

Commit

Permalink
fix(combobox): when the user types command and deletes the first part…
Browse files Browse the repository at this point in the history
… of an argument the box should stay open
  • Loading branch information
MarcMcIntosh committed Feb 13, 2024
1 parent 29ac20d commit ddfb84d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/components/ComboBox/ComboBox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,17 @@ describe("ComboBox", () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(event.target.value).toEqual("hello\n");
});

test("select command, type / and then delete", async () => {
const { user, ...app } = render(<App />);
const textarea = app.getByRole("combobox");
await user.type(textarea, "@fi{Enter}");
expect(app.getByRole("combobox").textContent).toEqual("@file ");
await user.type(textarea, "/");
expect(app.queryByText("/foo")).not.toBeNull();
expect(app.queryByText("/bar")).not.toBeNull();
await user.type(textarea, "{Backspace}");
expect(app.queryByText("/foo")).not.toBeNull();
expect(app.queryByText("/bar")).not.toBeNull();
});
});
5 changes: 3 additions & 2 deletions src/components/ComboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,12 @@ export const ComboBox: React.FC<ComboBoxProps> = ({
const maybeCommand = detectCommand(ref.current);

if (maybeCommand !== null) {
const [command, args] = maybeCommand.command.split(" ");
const maybeCommandWithArguments = maybeCommand.command.split(" ");
const [command, args] = maybeCommandWithArguments;

if (!selectedCommand && args) {
setSelectedCommand(command + " ");
} else if (selectedCommand && !args) {
} else if (selectedCommand && maybeCommandWithArguments.length < 2) {
setSelectedCommand("");
}

Expand Down

0 comments on commit ddfb84d

Please sign in to comment.