|
1 | | -# Select |
| 1 | +import SEO from '../components/SEO' |
| 2 | + |
| 3 | +<SEO |
| 4 | + title="Select" |
| 5 | + description="Select component is a component that allows users pick a value from predefined options. Ideally, it should be used when there are more than 5 options, otherwise you might consider using a radio group instead." |
| 6 | +/> |
| 7 | + |
| 8 | +# Select |
| 9 | + |
| 10 | +Select component is a component that allows users pick a value from predefined options. Ideally, it should be used when there are more than 5 options, otherwise you might consider using a radio group instead. |
| 11 | + |
| 12 | +## Import |
| 13 | + |
| 14 | +```js |
| 15 | +import { CSelect } from '@chakra-ui/vue' |
| 16 | +``` |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +Here's a basic usage of the Select component. |
| 23 | + |
| 24 | +```vue live=true |
| 25 | +<template> |
| 26 | + <c-box mb="3" w="300px"> |
| 27 | + <c-select v-model="burgerType" placeholder="Select Burger"> |
| 28 | + <option value="grilled">Grilled Backyard Burger</option> |
| 29 | + <option value="pub-style">The Pub-Style Burger</option> |
| 30 | + <option value="jucy-lucy">The Jucy Lucy</option> |
| 31 | + </c-select> |
| 32 | + </c-box> |
| 33 | +</template> |
| 34 | +<script> |
| 35 | +export default { |
| 36 | + data() { |
| 37 | + return { |
| 38 | + burgerType: '' |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | +</script> |
| 43 | +``` |
| 44 | + |
| 45 | +### Changing the size of the Select |
| 46 | + |
| 47 | +There are three sizes of select : large (48px), default (40px) and small (32px). |
| 48 | + |
| 49 | +```vue live=true |
| 50 | +<c-stack :spacing="3"> |
| 51 | + <c-select placeholder="large size" size="lg" /> |
| 52 | + <c-select placeholder="default size" size="md" /> |
| 53 | + <c-select placeholder="small size" size="sm" /> |
| 54 | +</c-sack> |
| 55 | +``` |
| 56 | + |
| 57 | +### Changing the appearance of the Select |
| 58 | + |
| 59 | +Just like the input component, select comes in 3 variants, `outline`, `unstyled` |
| 60 | +, `flushed` , and `filled`. Pass the `variant` prop and set it to either of |
| 61 | +these values. |
| 62 | + |
| 63 | +```vue live=true |
| 64 | +<c-stack :spacing="3"> |
| 65 | + <c-select variant="outline" placeholder="Outline" /> |
| 66 | + <c-select variant="filled" placeholder="Filled" /> |
| 67 | + <c-select variant="flushed" placeholder="Flushed" /> |
| 68 | + <c-select variant="unstyled" placeholder="Unstyled" /> |
| 69 | +</c-stack> |
| 70 | +``` |
| 71 | + |
| 72 | +### Overriding the styles of the Select |
| 73 | + |
| 74 | +Even though the select comes with predefined styles, you can override pretty |
| 75 | +much any property. Here's we'll override the background color. |
| 76 | + |
| 77 | +```vue live=true |
| 78 | +<c-select |
| 79 | + backgroundColor="tomato" |
| 80 | + borderColor="tomato" |
| 81 | + color="white" |
| 82 | + placeholder="Woohoo! A new background color!" |
| 83 | +/> |
| 84 | +``` |
| 85 | + |
| 86 | +## Props |
| 87 | + |
| 88 | +The Select component composes [PseudoBox](/pseudoBox) so you can pass all `PseudoBox` props. |
| 89 | + |
| 90 | +| Name | Type | Default | Description | |
| 91 | +| ------------------ | ------------------------------------------ | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 92 | +| `size` | `sm`, `md`, `lg` | `md` | The visual size of the `select` element. | |
| 93 | +| `icon` | `string` | `chevron-down` | The icon to use in place if the `chevron-down` | |
| 94 | +| `iconSize` | `BoxProps['size']` | `20px` | The visual size of the icon | |
| 95 | +| `variant` | `outline`, `unstyled`, `flushed`, `filled` | `outline` | The variant of the select style to use. | |
| 96 | +| `focusBorderColor` | `string` | | The border color when the select is focused. | |
| 97 | +| `errorBorderColor` | `string` | | The border color when `isInvalid` is set to `true`. | |
| 98 | +| `isDisabled` | `boolean` | `false` | If `true`, the select will be disabled. This sets `aria-disabled=true` and you can style this state by passing `_disabled` prop. | |
| 99 | +| `isInvalid` | `boolean` | `false` | If `true`, the `select` will indicate an error. This sets `aria-invalid=true` and you can style this state by passing `_invalid` prop. | |
| 100 | +| `isRequired` | `boolean` | `false` | If `true`, the select element will be required. | |
| 101 | +| `isReadOnly` | `boolean` | `false` | If `true`, prevents the value of the select from being edited. | |
| 102 | +| `rootProps` | `BoxProps` | | The props to pass to the wrapper of the select. The select is wrapped in a `Box` to help align the icon, if you want to pass some props to that wrapper, use this prop | |
| 103 | + |
| 104 | +## Slots |
| 105 | + |
| 106 | +| Name | Description | |
| 107 | +| ------- | -------------------------------------------------------- | |
| 108 | +| default | contains the `<option>` element as children of `CSelect` | |
0 commit comments