Skip to content

Commit

Permalink
fix: close select on blur
Browse files Browse the repository at this point in the history
  • Loading branch information
abelflopes committed Jul 9, 2024
1 parent 1791dff commit af63726
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/components/select/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { getChildrenData, valueAsArray } from "./utils";
import { type SelectProps, type ChangeHandler, type SelectOptionProps } from "./types";
import { SelectContext, type SelectContextProps } from "./context";

// TODO: debounced focus / blur handling in trigger + dropdown wrapper

/**
* Select is a type of input that allows users to choose one or more options from a list of choices.
* The options are hidden by default and revealed when a user interacts with an element. It shows the currently selected option in its default collapsed state.
Expand All @@ -24,6 +26,7 @@ const Select = ({
children,
className,
onFocus,
onBlur,
search: searchOptions,
onChange: selectOnChange,
name: selectName,
Expand Down Expand Up @@ -176,6 +179,14 @@ const Select = ({
onFocus={(e) => {
setOpen(true);
onFocus?.(e);
}}
onBlur={(e) => {
if (!selectMultiple) {
setTimeout(() => {
setOpen(false);
}, 100);
}
onBlur?.(e);
}}>
{selectedValuesList.length > 0 &&
childrenData
Expand Down

0 comments on commit af63726

Please sign in to comment.