✨(react) add ref to Select
We encountered a use-case where we needed to blur the select programatically but the component wasn't offering any way to do that.
This commit is contained in:
@@ -1,16 +1,23 @@
|
||||
import React from "react";
|
||||
import React, { forwardRef } from "react";
|
||||
import { SelectMulti } from ":/components/Forms/Select/multi";
|
||||
import { SelectMono, SelectProps } from ":/components/Forms/Select/mono";
|
||||
|
||||
export * from ":/components/Forms/Select/mono";
|
||||
export * from ":/components/Forms/Select/multi";
|
||||
|
||||
export const Select = (props: SelectProps) => {
|
||||
export interface SelectHandle {
|
||||
blur: () => void;
|
||||
}
|
||||
export const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {
|
||||
if (props.defaultValue && props.value) {
|
||||
throw new Error(
|
||||
"You cannot use both defaultValue and value props on Select component",
|
||||
);
|
||||
}
|
||||
|
||||
return props.multi ? <SelectMulti {...props} /> : <SelectMono {...props} />;
|
||||
};
|
||||
return props.multi ? (
|
||||
<SelectMulti {...props} ref={ref} />
|
||||
) : (
|
||||
<SelectMono {...props} ref={ref} />
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user