Skip to content

Commit

Permalink
feat: add CheckTreePicker component
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenOutman committed Sep 5, 2022
1 parent a87fb65 commit 228fcb0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/CheckTreePicker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { FieldProps } from "formik";
import {
CheckTreePicker as RsCheckTreePicker,
CheckTreePickerProps as RsCheckTreePickerProps,
} from "rsuite";

import formikCompatible from "./formikCompatible";

export interface CheckTreePickerProps
extends FieldProps<string[]>,
RsCheckTreePickerProps<string> {}

export const CheckTreePicker = formikCompatible(RsCheckTreePicker);
50 changes: 50 additions & 0 deletions src/__tests__/CheckTreePicker.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from "react";

import { render, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { Formik, Form, Field, FormikProps } from "formik";
import _ from "lodash";

import { CheckTreePicker } from "../CheckTreePicker";

test("适配 formik", async () => {
const formikRef = React.createRef<FormikProps<any>>();
const { getByText, getByRole } = render(
<Formik
innerRef={formikRef}
initialValues={{
fruits: ["Apple"],
}}
onSubmit={_.noop}
>
<Form>
<Field
name="fruits"
component={CheckTreePicker}
data={[
{
label: "Apple",
value: "Apple",
},
{
label: "Banana",
value: "Banana",
},
]}
/>
</Form>
</Formik>
);

expect(getByRole("combobox")).toHaveTextContent("Apple");

userEvent.click(getByRole("combobox"));
userEvent.click(getByText("Banana"));

await waitFor(() => {
expect(formikRef.current?.values).toHaveProperty("fruits", [
"Apple",
"Banana",
]);
});
});
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from "./Cascader";
export * from "./Checkbox";
export * from "./CheckboxGroup";
export * from "./CheckPicker";
export * from "./CheckTreePicker";
export * from "./Input";
export * from "./InputNumber";
export * from "./RadioGroup";
Expand Down

0 comments on commit 228fcb0

Please sign in to comment.