Skip to content

Commit

Permalink
feat: extend select props in select component in react kit (#823)
Browse files Browse the repository at this point in the history
* feat: extend select props in select component in react kit
  • Loading branch information
albertfolch-redeemeum authored Oct 30, 2024
1 parent 71dd801 commit a39d82d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
17 changes: 7 additions & 10 deletions packages/react-kit/src/components/form/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,6 @@ export default function SelectComponent<M extends boolean>({
const displayError =
typeof displayErrorMessage === "string" && displayErrorMessage !== "";

const handleChange = (
option: Parameters<NonNullable<typeof onChange>>[0]
) => {
if (!meta.touched) {
helpers.setTouched(true);
}
helpers.setValue(option);
onChange?.(option);
};
const handleBlur = () => {
if (!meta.touched) {
helpers.setTouched(true);
Expand All @@ -150,7 +141,13 @@ export default function SelectComponent<M extends boolean>({
placeholder={placeholder}
options={options}
value={field.value}
onChange={handleChange}
onChange={(option, ...rest) => {
if (!meta.touched) {
helpers.setTouched(true);
}
helpers.setValue(option);
onChange?.(option, ...rest);
}}
onBlur={handleBlur}
isSearchable={isSearchable}
isClearable={isClearable}
Expand Down
22 changes: 17 additions & 5 deletions packages/react-kit/src/components/form/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { ReactNode } from "react";
import { CSSObjectWithLabel, MultiValue, SingleValue } from "react-select";
import Select, {
ActionMeta,
CSSObjectWithLabel,
MultiValue,
SingleValue
} from "react-select";
import { CSSProperties } from "styled-components";
import { ImageEditorModalProps } from "./Upload/ImageEditorModal/ImageEditorModal";
import type {
Expand All @@ -8,6 +13,7 @@ import type {
TextAreaTheme
} from "./Field.styles";
import type { GridProps } from "../ui/Grid";
import { StateManagerProps } from "react-select/dist/declarations/src/useStateManager";

export interface BaseProps {
name: string;
Expand Down Expand Up @@ -86,8 +92,7 @@ export interface BaseSelectProps {
onChange?: OnChange;
}

export interface SelectProps<M extends boolean | undefined = false>
extends BaseProps {
export type SelectProps<M extends boolean | undefined = false> = BaseProps & {
isMulti?: M;
disabled?: boolean;
isClearable?: boolean;
Expand All @@ -97,7 +102,8 @@ export interface SelectProps<M extends boolean | undefined = false>
onChange?: (
option: M extends true
? MultiValue<SelectDataProps<string>>
: SingleValue<SelectDataProps<string>>
: SingleValue<SelectDataProps<string>>,
actionMeta: ActionMeta<SelectDataProps<string>>
) => void;
label?: string;
theme?: Partial<{
Expand All @@ -120,7 +126,13 @@ export interface SelectProps<M extends boolean | undefined = false>
singleValue: Partial<CSSProperties> &
Partial<{ error: CSSObjectWithLabel }>;
}>;
}
} & Pick<
StateManagerProps<
SelectDataProps<string>,
M extends undefined ? false : boolean
>,
"formatGroupLabel" | "formatOptionLabel"
>;

export type UploadProps = BaseProps & {
accept?: string;
Expand Down

0 comments on commit a39d82d

Please sign in to comment.