Skip to content

Commit ba175ca

Browse files
authored
Merge branch 'main' into main
2 parents 834569f + cba2df5 commit ba175ca

File tree

6 files changed

+70
-48
lines changed

6 files changed

+70
-48
lines changed

README.md

Lines changed: 62 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ Check out these demos:
3232

3333
- [Usage](#usage)
3434
- [Extra Props](#extra-props)
35-
- [`size`](#size--options-sm-md-lg--default-md)
35+
- [`size`](#size--options-sm--md--lg--default-md)
3636
- [`colorScheme`](#colorscheme)
37-
- [`variant`](#variant)
38-
- [`tagVariant`](#tagvariant--options-subtle-solid-outline--default-subtle)
37+
- [`tagVariant`](#tagvariant--options-subtle--solid--outline--default-subtle)
3938
- [`isInvalid`](#isinvalid--default-false)
4039
- [`focusBorderColor` / `errorBorderColor`](#focusbordercolor--default-blue500--errorbordercolor--default-red500)
4140
- [`useBasicStyles`](#usebasicstyles--default-false)
42-
- [`hasStickyGroupHeaders`](#hasstickygroupheaders--default-false)
43-
- [`selectedOptionStyle`](#selectedoptionstyle--options-color-check--default-color)
41+
- [`variant`](#variant)
42+
- [`selectedOptionStyle`](#selectedoptionstyle--options-color--check--default-color)
4443
- [`selectedOptionColor`](#selectedoptioncolor--default-blue)
44+
- [`hasStickyGroupHeaders`](#hasstickygroupheaders--default-false)
4545
- [`isFixed`](#isfixed)
4646
- [Styling](#styling)
4747
- [`chakraStyles`](#chakrastyles)
@@ -96,13 +96,13 @@ const {
9696
} = require("chakra-react-select");
9797
```
9898

99-
All of the types and other exports from the original `react-select` package are also exported from this package, so you can import any of them if you need them.
99+
All of exports, including types, from the original `react-select` package are also exported from this package, so you can import any of them if you need them. The only exception is the root `Select` components.
100100

101-
In order to use this component, you can implement it and use it like you would normally use [react-select](https://react-select.com/home). It should accept almost all of the props that the original takes, with a few additions and exceptions listed below.
101+
Implementing this component in your application should be almost identical to how you'd normally use [react-select](https://react-select.com/home). It will accept all of the props that the original package does, with a few additions and exceptions listed below. So if you have a question on basic usage, your best bet is to check the original docs or google "How to (some functionality) with react-select" and just swap out `react-select` for `chakra-react-select`.
102102

103103
## Extra Props
104104

105-
#### `size` — Options: `sm`, `md`, `lg` — Default: `md`
105+
#### `size` — Options: `sm` | `md` | `lg` — Default: `md`
106106

107107
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/components/input#changing-the-size-of-the-input) (with the exception of `xs` because it's too small to work).
108108

@@ -116,6 +116,8 @@ return (
116116
);
117117
```
118118

119+
[![CS-JS]](https://codesandbox.io/s/chakra-react-select-sizes-w9sf8e?file=/example.js)
120+
119121
#### `colorScheme`
120122

121123
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/components/tag/props), or if you have a custom color palette, any of the custom color names in that will be available instead.
@@ -142,17 +144,9 @@ return (
142144
);
143145
```
144146

145-
#### `variant`
147+
[![CS-JS]](https://codesandbox.io/s/chakra-react-select-color-schemes-c38jlo?file=/example.js)
146148

147-
You can set `outline`, `unstyled`, `flushed` or `filled`, which will reflect the same styles of Chakra-Ui select possible appearances [Check chakra-ui variants styles](https://chakra-ui.com/docs/components/select#changing-the-appearance)!
148-
149-
```js
150-
return (
151-
<Select variant="flushed" />
152-
);
153-
```
154-
155-
#### `tagVariant` — Options: `subtle`, `solid`, `outline` — Default: `subtle`
149+
#### `tagVariant` — Options: `subtle` | `solid` | `outline` — Default: `subtle`
156150

157151
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/components/tag/props).
158152

@@ -178,6 +172,8 @@ return (
178172
);
179173
```
180174

175+
[![CS-JS]](https://codesandbox.io/s/chakra-react-select-tag-variants-w31gnt?file=/example.js)
176+
181177
#### `isInvalid` — Default: `false`
182178

183179
You can pass `isInvalid` to the select component to style it like the Chakra `<Input />` is styled when it receives the same prop.
@@ -202,21 +198,25 @@ return (
202198
);
203199
```
204200

201+
[![CS-JS]](https://codesandbox.io/s/chakra-react-select-invalid-disabled-0hyl8l?file=/example.js)
202+
205203
#### `focusBorderColor` — Default: `blue.500` | `errorBorderColor` — Default: `red.500`
206204

207205
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/components/input#changing-the-focus-and-error-border-colors).
208206

209207
```js
210208
return (
211209
<>
210+
<Select errorBorderColor="orange.500" isInvalid />
212211
<Select focusBorderColor="green.500" />
213-
<Select errorBorderColor="orange.500" />
214212
</>
215213
);
216214
```
217215

218216
![Orange errorBorderColor](./github/custom-error-border.png)
219217

218+
[![CS-JS]](https://codesandbox.io/s/chakra-react-select-border-colors-gjo4zd?file=/example.js)
219+
220220
#### `useBasicStyles` — Default: `false`
221221

222222
If this prop is passed, the dropdown indicator at the right of the component will be styled in the same way [the original Chakra `Select` component](https://chakra-ui.com/docs/components/select) is styled, instead of being styled as an [`InputRightAddon`](https://chakra-ui.com/docs/components/input#left-and-right-addons). The original purpose of styling it as an addon was to create visual separation between the dropdown indicator and the button for clearing the selected options. However, as this button only appears when `isMulti` is passed, using this style could make more sense for a single select.
@@ -231,23 +231,11 @@ return (
231231

232232
![useBasicStyles dark mode](./github/use-basic-styles-dark.png)
233233

234-
#### `hasStickyGroupHeaders` — Default: `false`
235-
236-
One additional feature which isn’t specific to Chakra or react-select is sticky group headers. It adds a border to the bottom of the header and keeps it in view while its corresponding group of options is visible. This can be very nice for when you have long lists of grouped options so you can always tell which group of options you're looking at. To add it, pass the `hasStickyGroupHeaders` prop to the select component.
237-
238-
```js
239-
return <Select hasStickyGroupHeaders />;
240-
```
241-
242-
[![CS-JS]](https://codesandbox.io/s/chakra-react-select-hasstickygroupheaders-wg39g?file=/example.js)
243-
244-
**NOTE:** It has recently been discovered that when using this prop, navigating up through the available options with the arrow key will keep the focused option underneath the header, as it will not scroll enough to account for it being there. So if this is an issue for you, avoid this prop. A fix for this is being investigated.
245-
246-
![Sticky Group Headers](./github/sticky-group-headers.png)
234+
[![CS-JS]](https://codesandbox.io/s/chakra-react-select-usebasicstyles-jjnqsd?file=/example.js)
247235

248-
#### `selectedOptionStyle` — Options: `color`, `check` — Default: `color`
236+
#### `selectedOptionStyle` — Options: `color` | `check` — Default: `color`
249237

250-
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/components/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.
238+
As of `v1.3.0` you can pass the prop `selectedOptionStyle` with either `"color"` or `"check"`. 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/components/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.
251239

252240
```js
253241
return (
@@ -262,6 +250,18 @@ return (
262250

263251
![Check Highlighted Selected Option](./github/check-selected-option.png)
264252

253+
[![CS-JS]](https://codesandbox.io/s/chakra-react-select-border-selectedoptionstyle-yxkcos?file=/example.js)
254+
255+
#### `variant`
256+
257+
You can set `outline`, `unstyled`, `flushed` or `filled`, which will reflect the same styles of Chakra-Ui select possible appearances [Check chakra-ui variants styles](https://chakra-ui.com/docs/components/select#changing-the-appearance)!
258+
259+
```js
260+
return (
261+
<Select variant="flushed" />
262+
);
263+
```
264+
265265
#### `selectedOptionColor` — Default: `blue`
266266

267267
If you choose to stick with the default `selectedOptionStyle="color"`, you have one additional styling option. If you do not like the default of blue for the highlight color, you can pass the `selectedOptionColor` prop to change it. This prop will accept any named color from your color theme, and it will use the `500` value in light mode or the `300` value in dark mode.
@@ -279,6 +279,22 @@ return (
279279

280280
![Purple Selected Option Color (dark mode)](./github/purple-selected-option-dark.png)
281281

282+
[![CS-JS]](https://codesandbox.io/s/chakra-react-select-border-selectedoptioncolor-yyd321?file=/example.js)
283+
284+
#### `hasStickyGroupHeaders` — Default: `false`
285+
286+
One additional feature which isn’t specific to Chakra or react-select is sticky group headers. It adds a border to the bottom of the header and keeps it in view while its corresponding group of options is visible. This can be very nice for when you have long lists of grouped options so you can always tell which group of options you're looking at. To add it, pass the `hasStickyGroupHeaders` prop to the select component.
287+
288+
```js
289+
return <Select hasStickyGroupHeaders />;
290+
```
291+
292+
[![CS-JS]](https://codesandbox.io/s/chakra-react-select-hasstickygroupheaders-wg39g?file=/example.js)
293+
294+
**NOTE:** It has recently been discovered that when using this prop, navigating up through the available options with the arrow key will keep the focused option underneath the header, as it will not scroll enough to account for it being there. So if this is an issue for you, avoid this prop. A fix for this is being investigated.
295+
296+
![Sticky Group Headers](./github/sticky-group-headers.png)
297+
282298
#### `isFixed`
283299

284300
In your options objects, you can add the key `isFixed: true` to emulate the example in the [react-select docs](https://react-select.com/home#fixed-options). This will prevent the options which have this flag from having the remove button on its corresponding tag, and it changes the default `tagVariant` for that tag to be solid. This only applies when using `isMulti`.
@@ -330,7 +346,7 @@ function option(provided, state) {
330346
}
331347
```
332348

333-
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.
349+
All of the style keys offered in the original package can be used in the `chakraStyles` prop except for `menuPortal`. Along with [some other caveats](#caveats), this is explained below.
334350

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

@@ -707,17 +723,25 @@ Being a wrapper for `react-select`, all of the customizations done to react-sele
707723
To do so, simply import the hook from this package, and call it by passing in any extra custom props you'd like into it and spread it onto a base `react-select` component:
708724

709725
```jsx
726+
import { useState } from "react";
710727
import { useChakraSelectProps } from "chakra-react-select";
711728
import Select from "react-select";
729+
import { options } from "./data";
712730

713-
const CustomSelect = (customSelectProps) => {
714-
const selectProps = useChakraSelectProps(customSelectProps);
731+
const CustomSelect = () => {
732+
const [selectedOptions, setSelectedOptions] = useState([]);
733+
734+
const selectProps = useChakraSelectProps({
735+
isMulti: true,
736+
value: selectedOptions,
737+
onChange: setSelectedOptions,
738+
});
715739

716740
return <Select {...selectProps} />;
717741
};
718742
```
719743

720-
One example of how you might use this is to customize the component `react-google-places-autocomplete`, which is an autocomplete dropdown for Google Places that uses the `AsyncSelect` from `react-select` as it's core. Therefore, it accepts all of the same select props as the core react-select does which means you can use the `useChakraSelectProps` hook to style it:
744+
One example of how you might use this is to customize the component `react-google-places-autocomplete`, which is an autocomplete dropdown for Google Places that uses the `AsyncSelect` from `react-select` as it's core. Therefore, it accepts all of the same select props as the core react-select does meaning you can use the `useChakraSelectProps` hook to style it:
721745

722746
```jsx
723747
import { useState } from "react";

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chakra-react-select",
3-
"version": "4.1.4",
3+
"version": "4.1.5",
44
"description": "A Chakra UI wrapper for the popular library React Select",
55
"license": "MIT",
66
"author": "Chris Sandvik <chris.sandvik@gmail.com>",

src/chakra-components/containers.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ export const SelectContainer = <
3030
const initialSx: CSSObject = {
3131
position: "relative",
3232
direction: isRtl ? "rtl" : undefined,
33-
// When disabled, react-select sets the pointer-state to none which prevents
34-
// the `not-allowed` cursor style from chakra from getting applied to the
35-
// Control when it is disabled
36-
pointerEvents: "auto",
33+
...(isDisabled ? { cursor: "not-allowed" } : {}),
3734
};
3835

3936
const sx = chakraStyles?.container

src/chakra-components/control.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const Control = <
6161
overflow: "hidden",
6262
height: "auto",
6363
minHeight: heights[size || "md"],
64+
...(isDisabled ? { pointerEvents: "none" } : {}),
6465
};
6566

6667
const sx = chakraStyles?.control

src/module-augmentation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ declare module "react-select/dist/declarations/src/Select" {
2929
* Options: `sm` | `md` | `lg`
3030
*
3131
* @defaultValue `md`
32-
* @see {@link https://github.com/csandman/chakra-react-select#size--options-sm-md-lg--default-md}
32+
* @see {@link https://github.com/csandman/chakra-react-select#size--options-sm--md--lg--default-md}
3333
* @see {@link https://chakra-ui.com/docs/components/input#changing-the-size-of-the-input}
3434
*/
3535
size?: Size;
@@ -93,7 +93,7 @@ declare module "react-select/dist/declarations/src/Select" {
9393
* Options: "subtle" | "solid" | "outline"
9494
*
9595
* @defaultValue `subtle`
96-
* @see {@link https://github.com/csandman/chakra-react-select#tagvariant--options-subtle-solid-outline--default-subtle}
96+
* @see {@link https://github.com/csandman/chakra-react-select#tagvariant--options-subtle--solid--outline--default-subtle}
9797
* @see {@link https://chakra-ui.com/docs/data-display/tag#props}
9898
*/
9999
tagVariant?: TagVariant;
@@ -115,7 +115,7 @@ declare module "react-select/dist/declarations/src/Select" {
115115
* Options: `color` | `check`
116116
*
117117
* @defaultValue `color`
118-
* @see {@link https://github.com/csandman/chakra-react-select#selectedoptionstyle--options-color-check--default-color}
118+
* @see {@link https://github.com/csandman/chakra-react-select#selectedoptionstyle--options-color--check--default-color}
119119
* @see {@link https://chakra-ui.com/docs/components/menu#menu-option-groups}
120120
*/
121121
selectedOptionStyle?: SelectedOptionStyle;

0 commit comments

Comments
 (0)