Skip to content

Commit

Permalink
fix(autocomplete): revise shouldCloseOnInteractOutside logic
Browse files Browse the repository at this point in the history
  • Loading branch information
wingkwong committed May 13, 2024
1 parent 99d4e1e commit d40e792
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/components/autocomplete/src/use-autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,20 +470,27 @@ export function useAutocomplete<T extends object>(originalProps: UseAutocomplete
shouldCloseOnInteractOutside: (element: any) => {
let trigger = inputWrapperRef?.current;

const isOverlay = element?.children?.[0]?.getAttribute("role") === "dialog";

if (!trigger || !trigger.contains(element)) {
// adding blur logic in shouldCloseOnInteractOutside
// to cater the case like autocomplete inside modal
if (shouldFocus) {
setShouldFocus(false);
}
// if it is not clicking overlay, close the listbox
// e.g. clicking another autocomplete
if (!isOverlay) {
state.close();
}
} else {
// keep it focus
if (!shouldFocus) {
setShouldFocus(true);
}
}

return !trigger || !trigger.contains(element);
return isOverlay;
},
} as unknown as PopoverProps;
};
Expand Down

0 comments on commit d40e792

Please sign in to comment.