;
+ }) => {
+ return (
+ <>
+ Where will the 2024 Olympics take place?
+
+ >
+ );
+ };
+
+ return (
+
+
+
+ );
+};
+
export const FullWidth = {
render: Template,
diff --git a/packages/react/src/components/Forms/Select/mono.tsx b/packages/react/src/components/Forms/Select/mono.tsx
index 8b10d31..44ff4a9 100644
--- a/packages/react/src/components/Forms/Select/mono.tsx
+++ b/packages/react/src/components/Forms/Select/mono.tsx
@@ -23,6 +23,9 @@ export type SelectProps = PropsWithChildren &
onChange?: (event: {
target: { value: string | number | undefined | string[] };
}) => void;
+ onBlur?: (event: {
+ target: { value: string | number | undefined | string[] };
+ }) => void;
disabled?: boolean;
clearable?: boolean;
multi?: boolean;
diff --git a/packages/react/src/components/Forms/Select/multi.mdx b/packages/react/src/components/Forms/Select/multi.mdx
index 6b7584c..4b246b8 100644
--- a/packages/react/src/components/Forms/Select/multi.mdx
+++ b/packages/react/src/components/Forms/Select/multi.mdx
@@ -97,6 +97,14 @@ using the component in a controlled way.
+## Usage with react-hook-form
+
+You can use this input with [react-hook-form](https://react-hook-form.com/docs)
+
+
+
## Props
They are the same as the [Select](?path=/docs/components-forms-select-mono--docs#props) component.
diff --git a/packages/react/src/components/Forms/Select/multi.stories.tsx b/packages/react/src/components/Forms/Select/multi.stories.tsx
index d29b547..c1f3a5d 100644
--- a/packages/react/src/components/Forms/Select/multi.stories.tsx
+++ b/packages/react/src/components/Forms/Select/multi.stories.tsx
@@ -1,9 +1,17 @@
import React, { useState } from "react";
+import { useForm, Controller, ControllerRenderProps } from "react-hook-form";
+import * as Yup from "yup";
+import { yupResolver } from "@hookform/resolvers/yup";
import { Meta, StoryFn } from "@storybook/react";
import { faker } from "@faker-js/faker";
import { Select } from ":/components/Forms/Select";
import { CunninghamProvider } from ":/components/Provider";
import { Button } from ":/components/Button";
+import {
+ getFieldState,
+ getFieldErrorMessage,
+ onSubmit,
+} from ":/tests/reactHookFormUtils";
export default {
title: "Components/Forms/Select/Multi",
@@ -208,6 +216,103 @@ export const Error = {
},
};
+export const ReactHookForm = () => {
+ enum CitiesOptionEnum {
+ NONE = "",
+ DIJON = "dijon",
+ PARIS = "paris",
+ TOKYO = "tokyo",
+ VANNES = "vannes",
+ }
+
+ interface SelectExampleFormValues {
+ capitalCity: CitiesOptionEnum[];
+ }
+
+ const selectExampleSchema = Yup.object().shape({
+ capitalCity: Yup.array()
+ .required()
+ .test({
+ test: (cityList) =>
+ cityList.every((city) =>
+ [CitiesOptionEnum.PARIS, CitiesOptionEnum.TOKYO].includes(city),
+ ),
+ message: "Wrong answer!",
+ }),
+ });
+
+ const { handleSubmit, formState, control } = useForm(
+ {
+ defaultValues: {
+ capitalCity: [],
+ },
+ mode: "onChange",
+ reValidateMode: "onChange",
+ resolver: yupResolver(selectExampleSchema),
+ },
+ );
+
+ const renderSelect = ({
+ field,
+ }: {
+ field: ControllerRenderProps;
+ }) => {
+ return (
+ <>
+ Which are the capital of the country ?
+
+ >
+ );
+ };
+
+ return (
+
+
+
+ );
+};
+
export const FormExample = () => {
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();