Skip to content

Commit 1c49b74

Browse files
authored
Merge pull request #150 from csandman/chakra-2-fixes
Chakra 2 Fixes
2 parents ef3db3c + 25afb66 commit 1c49b74

File tree

15 files changed

+600
-591
lines changed

15 files changed

+600
-591
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"plugins": ["@typescript-eslint"],
2828
"rules": {
29+
"no-console": "error",
2930
"curly": ["error", "all"],
3031
"no-underscore-dangle": "off",
3132
"import/prefer-default-export": "off",

README.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -738,18 +738,13 @@ See this issue for some discussion about using this package with `react-hook-for
738738

739739
By default, `react-hook-form` uses [uncontrolled components](https://reactjs.org/docs/uncontrolled-components.html) to reduced input renders however this only works for native HTML inputs. Because chakra-react-select is not a native HTML input, you'll need to use react-hook-form's [`Controller`](https://react-hook-form.com/api/usecontroller/controller) component or [`useController`](https://react-hook-form.com/api/usecontroller) hook in order to keep the value(s) tracked in `react-hook-form`'s state. Here are some examples using each:
740740

741-
- `Controller` multi select with built-in validation
742-
- Vanilla JS: https://codesandbox.io/s/chakra-react-select-react-hook-form-controller-v7llc?file=/example.js
743-
- TypeScript: https://codesandbox.io/s/chakra-react-select-react-hook-form-controller-typescript-v8ps5?file=/app.tsx
744-
- `useController` multi select with built-in validation
745-
- Vanilla JS: https://codesandbox.io/s/chakra-react-select-react-hook-form-usecontroller-n8wuf?file=/example.js
746-
- TypeScript: https://codesandbox.io/s/chakra-react-select-react-hook-form-usecontroller-typescript-qcm23?file=/app.tsx
747-
- `useController` single select
748-
- Vanilla JS: https://codesandbox.io/s/chakra-react-select-react-hook-form-usecontroller-single-select-vanilla-js-11x4zk?file=/example.js
749-
- TypeScript: https://codesandbox.io/s/chakra-react-select-react-hook-form-usecontroller-single-select-typescript-vylckh?file=/app.tsx
750-
- Multi select with `yup` validation (advanced example)
751-
- Vanilla JS: https://codesandbox.io/s/chakra-react-select-react-hook-form-with-yup-validation-tno8v?file=/src/app.js
752-
- TypeScript: https://codesandbox.io/s/chakra-react-select-react-hook-form-with-yup-validation-typescript-n7slhu?file=/app.tsx
741+
- `Controller` multi select with built-in validation [ [JavaScript](https://codesandbox.io/s/chakra-react-select-react-hook-form-controller-v7llc?file=/example.js) | [TypeScript](https://codesandbox.io/s/chakra-react-select-react-hook-form-controller-typescript-v8ps5?file=/app.tsx) ]
742+
- `useController` multi select with built-in validation [ [JavaScript](https://codesandbox.io/s/chakra-react-select-react-hook-form-usecontroller-n8wuf?file=/example.js) | [TypeScript](https://codesandbox.io/s/chakra-react-select-react-hook-form-usecontroller-typescript-qcm23?file=/app.tsx) ]
743+
- `useController` single select [ [JavaScript](https://codesandbox.io/s/chakra-react-select-react-hook-form-usecontroller-single-select-vanilla-js-11x4zk?file=/example.js) | [TypeScript](https://codesandbox.io/s/chakra-react-select-react-hook-form-usecontroller-single-select-typescript-vylckh?file=/app.tsx) ]
744+
- Multi select with [`yup`](https://github.com/jquense/yup) validation (advanced example) [ [JavaScript](https://codesandbox.io/s/chakra-react-select-react-hook-form-with-yup-validation-tno8v?file=/src/app.js) | [TypeScript](https://codesandbox.io/s/chakra-react-select-react-hook-form-with-yup-validation-typescript-n7slhu?file=/app.tsx) ]
745+
- Single select with [`yup`](https://github.com/jquense/yup) validation (advanced example) [ [JavaScript](https://codesandbox.io/s/chakra-react-select-single-react-hook-form-with-yup-validation-y5kjc1?file=/src/app.js) | [TypeScript](https://codesandbox.io/s/chakra-react-select-single-react-hook-form-with-yup-validation-typescript-phmv0u?file=/app.tsx) ]
746+
- Multi select with [`zod`](https://github.com/colinhacks/zod) validation (advanced example) [ [JavaScript](https://codesandbox.io/s/chakra-react-select-react-hook-form-with-zod-validation-cu0rku?file=/src/app.js) | [TypeScript](https://codesandbox.io/s/chakra-react-select-react-hook-form-with-zod-validation-typescript-5fyhfh?file=/app.tsx) ]
747+
- Single select with [`zod`](https://github.com/colinhacks/zod) validation (advanced example) [ [JavaScript](https://codesandbox.io/s/chakra-react-select-single-react-hook-form-with-zod-validation-jd588n?file=/src/app.js) | [TypeScript](https://codesandbox.io/s/chakra-react-select-single-react-hook-form-with-zod-validation-typescript-m1dqme?file=/app.tsx) ]
753748

754749
### [`formik`](https://formik.org/)
755750

src/chakra-components/containers.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from "react";
2-
import type { ReactElement } from "react";
32
import { Box } from "@chakra-ui/layout";
43
import type { SystemStyleObject } from "@chakra-ui/system";
54
import type {
@@ -16,7 +15,7 @@ export const SelectContainer = <
1615
Group extends GroupBase<Option>
1716
>(
1817
props: ContainerProps<Option, IsMulti, Group>
19-
): ReactElement => {
18+
) => {
2019
const {
2120
children,
2221
className,
@@ -43,6 +42,7 @@ export const SelectContainer = <
4342

4443
return (
4544
<Box
45+
{...innerProps}
4646
className={cx(
4747
{
4848
"--is-disabled": isDisabled,
@@ -52,7 +52,6 @@ export const SelectContainer = <
5252
className
5353
)}
5454
sx={sx}
55-
{...innerProps}
5655
>
5756
{children}
5857
</Box>
@@ -65,13 +64,14 @@ export const ValueContainer = <
6564
Group extends GroupBase<Option>
6665
>(
6766
props: ValueContainerProps<Option, IsMulti, Group>
68-
): ReactElement => {
67+
) => {
6968
const {
7069
children,
7170
className,
7271
cx,
7372
isMulti,
7473
hasValue,
74+
innerProps,
7575
selectProps: { size, chakraStyles },
7676
} = props;
7777

@@ -98,6 +98,7 @@ export const ValueContainer = <
9898

9999
return (
100100
<Box
101+
{...innerProps}
101102
className={cx(
102103
{
103104
"value-container": true,
@@ -119,11 +120,12 @@ export const IndicatorsContainer = <
119120
Group extends GroupBase<Option>
120121
>(
121122
props: IndicatorsContainerProps<Option, IsMulti, Group>
122-
): ReactElement => {
123+
) => {
123124
const {
124125
children,
125126
className,
126127
cx,
128+
innerProps,
127129
selectProps: { chakraStyles },
128130
} = props;
129131

@@ -140,6 +142,7 @@ export const IndicatorsContainer = <
140142

141143
return (
142144
<Box
145+
{...innerProps}
143146
className={cx(
144147
{
145148
indicators: true,

0 commit comments

Comments
 (0)