Skip to content

Commit 3b1722a

Browse files
committed
feat: onopen and onclose props for select
1 parent ed44dff commit 3b1722a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/components/primitives/Select/Select.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ const Select = ({ wrapperRef, ...props }: ISelectProps, ref: any) => {
5959
_item,
6060
_selectedItem,
6161
size,
62+
onOpen,
63+
onClose,
6264
...resolvedProps
6365
} = usePropsResolution('Input', props, {
6466
isDisabled,
@@ -143,7 +145,10 @@ const Select = ({ wrapperRef, ...props }: ISelectProps, ref: any) => {
143145
/>
144146
);
145147

146-
const handleClose = () => setIsOpen(false);
148+
const handleClose = () => {
149+
setIsOpen(false);
150+
onClose && onClose();
151+
};
147152

148153
return (
149154
<Box
@@ -170,6 +175,12 @@ const Select = ({ wrapperRef, ...props }: ISelectProps, ref: any) => {
170175
}}
171176
value={selectedItem === null ? tempFix : value}
172177
aria-label={placeholder}
178+
onFocus={() => {
179+
onOpen && onOpen();
180+
}}
181+
onBlur={() => {
182+
onClose && onClose();
183+
}}
173184
>
174185
<option disabled value={tempFix}>
175186
{placeholder}
@@ -185,6 +196,7 @@ const Select = ({ wrapperRef, ...props }: ISelectProps, ref: any) => {
185196
onPress={() => {
186197
Keyboard.dismiss();
187198
setIsOpen(true);
199+
onOpen && onOpen();
188200
}}
189201
disabled={isDisabled}
190202
accessibilityLabel={accessibilityLabel}

src/components/primitives/Select/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ export interface ISelectProps extends IBoxProps<ISelectProps> {
5959
* @default outline
6060
*/
6161
variant?: 'outline' | 'filled' | 'underlined' | 'unstyled' | 'rounded';
62+
/**
63+
* Callback to be invoked when Select Dropdown or BottomSheet is opened.
64+
*/
65+
onOpen?: (nativeEvent: any) => void;
66+
/**
67+
* Callback to be invoked when Select Dropdown or BottomSheet is closed.
68+
*/
69+
onClose?: (nativeEvent: any) => void;
6270
/**
6371
* props to be passed to underlying ActionSheet.Content. Select uses ActionSheet underneath.
6472
*/

0 commit comments

Comments
 (0)