Skip to content

Commit

Permalink
fix(combobox): close list on outside click
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 committed Jul 31, 2024
1 parent 3f0e195 commit 7b26d59
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/core/src/combobox/combobox-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ export function ComboboxContent<T extends ValidComponent = "div">(
"onFocusOutside",
]);

const close = () => {
const dismiss = () => {
context.resetInputValue(
context.listState().selectionManager().selectedKeys(),
);
context.close();
setTimeout(() => {
context.close();
});
};

const onFocusOutside = (e: FocusOutsideEvent) => {
Expand Down Expand Up @@ -165,7 +168,7 @@ export function ComboboxContent<T extends ValidComponent = "div">(
local.style,
)}
onFocusOutside={onFocusOutside}
onDismiss={close}
onDismiss={dismiss}
{...context.dataset()}
{...others}
/>
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/combobox/combobox-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface ComboboxInputCommonProps<
ref: T | ((el: T) => void);
onInput: JSX.EventHandlerUnion<T, InputEvent>;
onKeyDown: JSX.EventHandlerUnion<T, KeyboardEvent>;
onClick: JSX.EventHandlerUnion<T, MouseEvent>;
onFocus: JSX.EventHandlerUnion<T, FocusEvent>;
onBlur: JSX.EventHandlerUnion<T, FocusEvent>;
onTouchEnd: JSX.EventHandlerUnion<T, TouchEvent>;
Expand Down Expand Up @@ -93,6 +94,7 @@ export function ComboboxInput<T extends ValidComponent = "input">(
[
"ref",
"disabled",
"onClick",
"onInput",
"onKeyDown",
"onFocus",
Expand All @@ -113,6 +115,14 @@ export function ComboboxInput<T extends ValidComponent = "input">(

const { fieldProps } = createFormControlField(formControlFieldProps);

const onClick: JSX.EventHandlerUnion<HTMLInputElement, MouseEvent> = (e) => {
callHandler(e, local.onClick);

if (context.triggerMode() === "focus" && !context.isOpen()) {
context.open(false, "focus");
}
};

const onInput: JSX.EventHandlerUnion<HTMLInputElement, InputEvent> = (e) => {
callHandler(e, local.onInput);

Expand Down Expand Up @@ -315,6 +325,7 @@ export function ComboboxInput<T extends ValidComponent = "input">(
aria-required={formControlContext.isRequired() || undefined}
aria-disabled={formControlContext.isDisabled() || undefined}
aria-readonly={formControlContext.isReadOnly() || undefined}
onClick={onClick}
onInput={onInput}
onKeyDown={onKeyDown}
onFocus={onFocus}
Expand Down

0 comments on commit 7b26d59

Please sign in to comment.