Skip to content

Commit 94ff4ca

Browse files
committed
chore: cleanup
1 parent f223ab7 commit 94ff4ca

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

site/src/components/MultiSelectCombobox/MultiSelectCombobox.tsx

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -238,29 +238,30 @@ export const MultiSelectCombobox = forwardRef<
238238
[onChange, selected],
239239
);
240240

241-
const handleKeyDown = useCallback(
242-
(e: KeyboardEvent<HTMLDivElement>) => {
243-
const input = inputRef.current;
244-
if (input) {
245-
if (e.key === "Delete" || e.key === "Backspace") {
246-
if (input.value === "" && selected.length > 0) {
247-
const lastSelectOption = selected[selected.length - 1];
248-
// If last item is fixed, we should not remove it.
249-
if (!lastSelectOption.fixed) {
250-
handleUnselect(selected[selected.length - 1]);
251-
}
241+
const handleKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
242+
const input = inputRef.current;
243+
if (input) {
244+
if (e.key === "Delete" || e.key === "Backspace") {
245+
if (input.value === "" && selected.length > 0) {
246+
const lastSelectOption = selected[selected.length - 1];
247+
// If last item is fixed, we should not remove it.
248+
if (!lastSelectOption.fixed) {
249+
handleUnselect(selected[selected.length - 1]);
252250
}
253251
}
254-
// This is not a default behavior of the <input /> field
255-
if (e.key === "Escape") {
256-
input.blur();
257-
}
258252
}
259-
},
260-
[handleUnselect, selected],
261-
);
253+
// This is not a default behavior of the <input /> field
254+
if (e.key === "Escape") {
255+
input.blur();
256+
}
257+
}
258+
};
262259

263260
useEffect(() => {
261+
if (!open) {
262+
return;
263+
}
264+
264265
const handleClickOutside = (event: MouseEvent | TouchEvent) => {
265266
if (
266267
dropdownRef.current &&
@@ -273,10 +274,6 @@ export const MultiSelectCombobox = forwardRef<
273274
}
274275
};
275276

276-
if (!open) {
277-
return;
278-
}
279-
280277
if (open) {
281278
document.addEventListener("mousedown", handleClickOutside);
282279
document.addEventListener("touchend", handleClickOutside);
@@ -381,7 +378,7 @@ export const MultiSelectCombobox = forwardRef<
381378
onChange?.(newOptions);
382379
}}
383380
>
384-
{`Create "${inputValue}"`}
381+
Create "{inputValue}"
385382
</CommandItem>
386383
);
387384

@@ -554,6 +551,12 @@ export const MultiSelectCombobox = forwardRef<
554551
setSelected(fixedOptions);
555552
onChange?.(fixedOptions);
556553
}}
554+
onKeyDown={(e) => {
555+
if (e.key === "Enter") {
556+
setSelected(fixedOptions);
557+
onChange?.(fixedOptions);
558+
}
559+
}}
557560
className={cn(
558561
"bg-transparent mt-1 border-none rounded-sm cursor-pointer text-content-secondary hover:text-content-primary outline-none focus:ring-2 focus:ring-content-link",
559562
(hideClearAllButton ||

0 commit comments

Comments
 (0)