Skip to content

Commit dad1394

Browse files
authored
Merge pull request #153 from csandman/chakra-v2-fixes
Chakra v2 fixes
2 parents bb1a199 + 873cc10 commit dad1394

File tree

8 files changed

+51
-46
lines changed

8 files changed

+51
-46
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# chakra-react-select v3
22

3-
> This version of `chakra-react-select` is for compatibility with React v17 and Chakra UI v1. It will be maintained until the majority of users have migrated to the newest version of Chakra. If you're using [Chakra UI v2](https://chakra-ui.com/guides/migration) check [the docs for chakra-react-select v4 here](https://github.com/csandman/chakra-react-select).
3+
> This version of `chakra-react-select` is for compatibility with React v17 and Chakra UI v1. It will be maintained until the majority of users have migrated to the newest version of Chakra. If you're using [Chakra UI v2](https://chakra-ui.com/getting-started/migration) check [the docs for chakra-react-select v4 here](https://github.com/csandman/chakra-react-select).
44
55
[![Build Status](https://github.com/csandman/chakra-react-select/actions/workflows/build.yml/badge.svg?branch=main "Build Status")](https://github.com/csandman/chakra-react-select/actions/workflows/build.yml?query=branch%3Amain)
66
[![Lint Status](https://github.com/csandman/chakra-react-select/actions/workflows/lint.yml/badge.svg?branch=main "Lint Status")](https://github.com/csandman/chakra-react-select/actions/workflows/lint.yml?query=branch%3Amain)
@@ -12,7 +12,7 @@
1212
[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-c596c7.svg "Code Style: Prettier")](https://github.com/prettier/prettier)
1313
[![MIT License](https://badgen.net/github/license/csandman/chakra-react-select "MIT License")](LICENSE.md)
1414

15-
This component is a wrapper for the popular react component [react-select](https://react-select.com/home) made using the UI library [Chakra UI](https://chakra-ui.com/).
15+
This component is a wrapper for the popular react component [react-select](https://react-select.com/home) made using the UI library [Chakra UI](https://v1.chakra-ui.com/).
1616

1717
![Chakra React Select Banner](./github/chakra-react-select.png)
1818

@@ -97,7 +97,7 @@ In order to use this component, you can implement it and use it like you would n
9797

9898
#### `size` — Options: `sm`, `md`, `lg` — Default: `md`
9999

100-
You can pass the `size` prop with either `sm`, `md`, or `lg` (default is `md`). These will reflect the sizes available on the [Chakra `<Input />` component](https://chakra-ui.com/docs/form/input#changing-the-size-of-the-input) (with the exception of `xs` because it's too small to work).
100+
You can pass the `size` prop with either `sm`, `md`, or `lg` (default is `md`). These will reflect the sizes available on the [Chakra `<Input />` component](https://v1.chakra-ui.com/docs/form/input#changing-the-size-of-the-input) (with the exception of `xs` because it's too small to work).
101101

102102
```js
103103
return (
@@ -111,7 +111,7 @@ return (
111111

112112
#### `colorScheme`
113113

114-
You can pass the `colorScheme` prop to the select component to change all of the selected options tags' colors. You can view the whole list of available color schemes in [the Chakra docs](https://chakra-ui.com/docs/data-display/tag#props), or if you have a custom color palette, any of the custom color names in that will be available instead.
114+
You can pass the `colorScheme` prop to the select component to change all of the selected options tags' colors. You can view the whole list of available color schemes in [the Chakra docs](https://v1.chakra-ui.com/docs/data-display/tag#props), or if you have a custom color palette, any of the custom color names in that will be available instead.
115115

116116
Alternatively you can add the `colorScheme` key to any of your options objects and it will only style that option when selected.
117117

@@ -137,7 +137,7 @@ return (
137137

138138
#### `tagVariant` — Options: `subtle`, `solid`, `outline` — Default: `subtle`
139139

140-
You can pass the `tagVariant` prop with either `subtle`, `solid`, or `outline` (default is `subtle`). These will reflect the `variant` prop available on the [Chakra `<Tag />` component](https://chakra-ui.com/docs/data-display/tag#props).
140+
You can pass the `tagVariant` prop with either `subtle`, `solid`, or `outline` (default is `subtle`). These will reflect the `variant` prop available on the [Chakra `<Tag />` component](https://v1.chakra-ui.com/docs/data-display/tag#props).
141141

142142
Alternatively you can add the `variant` key to any of your options objects and it will only style that option when selected. This will override the `tagVariant` prop on the select if both are set
143143

@@ -187,7 +187,7 @@ return (
187187

188188
#### `focusBorderColor` — Default: `blue.500` | `errorBorderColor` — Default: `red.500`
189189

190-
The props `focusBorderColor` and `errorBorderColor` can be passed with Chakra color strings which will emulate the respective props being passed to [Chakra's `<Input />` component](https://chakra-ui.com/docs/form/input#changing-the-focus-and-error-border-colors).
190+
The props `focusBorderColor` and `errorBorderColor` can be passed with Chakra color strings which will emulate the respective props being passed to [Chakra's `<Input />` component](https://v1.chakra-ui.com/docs/form/input#changing-the-focus-and-error-border-colors).
191191

192192
```js
193193
return (
@@ -216,7 +216,7 @@ return <Select hasStickyGroupHeaders />;
216216

217217
#### `selectedOptionStyle` — Options: `color`, `check` — Default: `color`
218218

219-
In `v1.3.0` you can now pass the prop `selectedOptionStyle` with either `"color"` or `"check"` (defaults to `"color"`). The default option `"color"` will style a selected option similar to how react-select does it, by highlighting the selected option in the color blue. Alternatively if you pass `"check"` for the value, the selected option will be styled like the [Chakra UI Menu component](https://chakra-ui.com/docs/overlay/menu#menu-option-groups) and include a check icon next to the selected option(s). If `isMulti` and `selectedOptionStyle="check"` are passed, space will only be added for the check marks if `hideSelectedOptions={false}` is also passed.
219+
In `v1.3.0` you can now pass the prop `selectedOptionStyle` with either `"color"` or `"check"` (defaults to `"color"`). The default option `"color"` will style a selected option similar to how react-select does it, by highlighting the selected option in the color blue. Alternatively if you pass `"check"` for the value, the selected option will be styled like the [Chakra UI Menu component](https://v1.chakra-ui.com/docs/overlay/menu#menu-option-groups) and include a check icon next to the selected option(s). If `isMulti` and `selectedOptionStyle="check"` are passed, space will only be added for the check marks if `hideSelectedOptions={false}` is also passed.
220220

221221
```js
222222
return (
@@ -281,7 +281,7 @@ This package does however offer an alternative to the `styles` prop, `chakraStyl
281281

282282
### `chakraStyles`
283283

284-
In order to use the `chakraStyles` prop, first check the documentation for [the original `styles` prop from the react-select docs](https://react-select.com/styles#style-object). This package offers an identical API for the `chakraStyles` prop, however the `provided` and output style objects use [Chakra's `sx` prop](https://chakra-ui.com/docs/features/the-sx-prop) instead of the default emotion styles the original package offers. This allows you to both use the shorthand styling props you'd normally use to style Chakra components, as well as tokens from your theme such as named colors.
284+
In order to use the `chakraStyles` prop, first check the documentation for [the original `styles` prop from the react-select docs](https://react-select.com/styles#style-object). This package offers an identical API for the `chakraStyles` prop, however the `provided` and output style objects use [Chakra's `sx` prop](https://v1.chakra-ui.com/docs/features/the-sx-prop) instead of the default emotion styles the original package offers. This allows you to both use the shorthand styling props you'd normally use to style Chakra components, as well as tokens from your theme such as named colors.
285285

286286
The API for an individual style function looks like this:
287287

@@ -301,7 +301,7 @@ function option(provided, state) {
301301

302302
All of the style keys offered in the original package can be used here, except for `input` as that does not allow me to use the `chakraStyles` from the select props. The `input` styles are also much more dynamic and should be left alone for the most part.
303303

304-
Most of the components rendered by this package use the basic [Chakra `<Box />` component](https://chakra-ui.com/docs/layout/box) with a few exceptions. Here are the style keys offered and the corresponding Chakra component that is rendered:
304+
Most of the components rendered by this package use the basic [Chakra `<Box />` component](https://v1.chakra-ui.com/docs/layout/box) with a few exceptions. Here are the style keys offered and the corresponding Chakra component that is rendered:
305305

306306
- `clearIndicator` - `Box` (uses theme styles for Chakra's `CloseButton`)
307307
- `container` - `Box`
@@ -413,13 +413,13 @@ If anyone has any suggestions for how to fully replace the `MenuPortal` componen
413413
- Dropdown menu attached to control example:
414414
- TypeScript: https://codesandbox.io/s/chakra-react-select-chakrastyles-v3-3wus8g?file=/app.tsx
415415
- Vanilla JS: https://codesandbox.io/s/chakra-react-select-chakrastyles-vanilla-v3-tewves?file=/example.js
416-
- Default [Chakra `<Select />`](https://chakra-ui.com/docs/form/select) styles example:
416+
- Default [Chakra `<Select />`](https://v1.chakra-ui.com/docs/form/select) styles example:
417417
- TypeScript: https://codesandbox.io/s/chakra-react-select-styled-like-a-default-chakra-select-v3-7273qk?file=/app.tsx
418418
- Vanilla JS: https://codesandbox.io/s/chakra-react-select-styled-like-a-default-chakra-select-vanilla-v3-edv95f?file=/example.js
419419

420420
### Theme Styles
421421

422-
As mentioned above, a few of the custom components this package implements either use styles from the global [Chakra component theme](https://chakra-ui.com/docs/theming/customize-theme#customizing-component-styles) or are themselves those components. As this package pulls directly from your Chakra theme, any changes you make to those components' themes will propagate to the components in this package. Here is a list of all components that will be affected by changes to your global styles:
422+
As mentioned above, a few of the custom components this package implements either use styles from the global [Chakra component theme](https://v1.chakra-ui.com/docs/theming/customize-theme#customizing-component-styles) or are themselves those components. As this package pulls directly from your Chakra theme, any changes you make to those components' themes will propagate to the components in this package. Here is a list of all components that will be affected by changes to your global styles:
423423

424424
| `react-select` component | `chakra-ui` component styles |
425425
| ------------------------ | --------------------------------------------------------------------------------------------------------------- |
@@ -616,7 +616,7 @@ CodeSandbox Examples:
616616

617617
### Custom `LoadingIndicator` (Chakra `Spinner`)
618618

619-
For most sub components, the styling can be easily accomplished using the [`chakraStyles`](#chakrastyles) prop. However, in the case of the `LoadingIndicator` there are a few props which do not directly correlate very well with styling props. To solve that problem, the `chakraComponents.LoadingIndicator` component can be passed a few extra props which are normally available on the Chakra UI [`Spinner`](https://chakra-ui.com/docs/components/feedback/spinner). Here is an example demonstrating which extra props are offered:
619+
For most sub components, the styling can be easily accomplished using the [`chakraStyles`](#chakrastyles) prop. However, in the case of the `LoadingIndicator` there are a few props which do not directly correlate very well with styling props. To solve that problem, the `chakraComponents.LoadingIndicator` component can be passed a few extra props which are normally available on the Chakra UI [`Spinner`](https://v1.chakra-ui.com/docs/components/feedback/spinner). Here is an example demonstrating which extra props are offered:
620620

621621
```jsx
622622
import { AsyncSelect, chakraComponents } from "chakra-react-select";

src/chakra-components/containers.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const SelectContainer = <
4343

4444
return (
4545
<Box
46+
{...innerProps}
4647
className={cx(
4748
{
4849
"--is-disabled": isDisabled,
@@ -52,7 +53,6 @@ export const SelectContainer = <
5253
className
5354
)}
5455
sx={sx}
55-
{...innerProps}
5656
>
5757
{children}
5858
</Box>
@@ -72,6 +72,7 @@ export const ValueContainer = <
7272
cx,
7373
isMulti,
7474
hasValue,
75+
innerProps,
7576
selectProps: { size, chakraStyles },
7677
} = props;
7778

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

99100
return (
100101
<Box
102+
{...innerProps}
101103
className={cx(
102104
{
103105
"value-container": true,

src/chakra-components/group.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const Group = <
2323
headingProps,
2424
label,
2525
selectProps,
26+
innerProps,
2627
} = props;
2728

2829
const { chakraStyles } = selectProps;
@@ -32,7 +33,7 @@ const Group = <
3233
: {};
3334

3435
return (
35-
<Box className={cx({ group: true }, className)} sx={sx}>
36+
<Box {...innerProps} className={cx({ group: true }, className)} sx={sx}>
3637
<Heading
3738
{...headingProps}
3839
selectProps={selectProps}

src/chakra-components/indicators.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export const ClearIndicator = <
178178

179179
return (
180180
<Box
181+
{...innerProps}
181182
role="button"
182183
className={cx(
183184
{
@@ -189,7 +190,6 @@ export const ClearIndicator = <
189190
sx={sx}
190191
data-focused={isFocused ? true : undefined}
191192
aria-label="Clear selected options"
192-
{...innerProps}
193193
>
194194
{children || <CrossIcon sx={iconSx} />}
195195
</Box>
@@ -231,6 +231,7 @@ export const LoadingIndicator = <
231231

232232
return (
233233
<Spinner
234+
{...innerProps}
234235
className={cx(
235236
{
236237
indicator: true,
@@ -239,7 +240,6 @@ export const LoadingIndicator = <
239240
className
240241
)}
241242
sx={sx}
242-
{...innerProps}
243243
size={propsSpinnerSize || spinnerSize}
244244
color={color}
245245
emptyColor={emptyColor}

src/chakra-components/menu.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ const Menu = <Option, IsMulti extends boolean, Group extends GroupBase<Option>>(
4747

4848
return (
4949
<Box
50+
{...innerProps}
5051
ref={innerRef}
5152
className={cx({ menu: true }, className)}
5253
sx={sx}
53-
{...innerProps}
5454
>
5555
<StylesProvider value={menuStyles}>{children}</StylesProvider>
5656
</Box>
@@ -71,6 +71,7 @@ const MenuList = <
7171
children,
7272
maxHeight,
7373
isMulti,
74+
innerProps,
7475
selectProps: { size, chakraStyles },
7576
} = props;
7677

@@ -91,6 +92,7 @@ const MenuList = <
9192

9293
return (
9394
<Box
95+
{...innerProps}
9496
className={cx(
9597
{
9698
"menu-list": true,
@@ -146,6 +148,7 @@ const LoadingMessage = <
146148

147149
return (
148150
<Box
151+
{...innerProps}
149152
className={cx(
150153
{
151154
"menu-notice": true,
@@ -154,7 +157,6 @@ const LoadingMessage = <
154157
className
155158
)}
156159
sx={sx}
157-
{...innerProps}
158160
>
159161
{children}
160162
</Box>
@@ -201,6 +203,7 @@ const NoOptionsMessage = <
201203

202204
return (
203205
<Box
206+
{...innerProps}
204207
className={cx(
205208
{
206209
"menu-notice": true,
@@ -209,7 +212,6 @@ const NoOptionsMessage = <
209212
className
210213
)}
211214
sx={sx}
212-
{...innerProps}
213215
>
214216
{children}
215217
</Box>

src/chakra-components/option.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const Option = <
9999

100100
return (
101101
<Box
102+
{...innerProps}
102103
role="button"
103104
className={cx(
104105
{
@@ -111,7 +112,6 @@ const Option = <
111112
)}
112113
sx={sx}
113114
ref={innerRef}
114-
{...innerProps}
115115
data-disabled={isDisabled ? true : undefined}
116116
aria-disabled={isDisabled ? true : undefined}
117117
>

src/chakra-components/placeholder.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ const Placeholder = <
3434

3535
return (
3636
<Box
37+
{...innerProps}
3738
className={cx(
3839
{
3940
placeholder: true,
4041
},
4142
className
4243
)}
4344
sx={sx}
44-
{...innerProps}
4545
>
4646
{children}
4747
</Box>

0 commit comments

Comments
 (0)