Skip to content

Commit 2903612

Browse files
committed
feat(docs): update /options docs
1 parent fbec5b3 commit 2903612

File tree

1 file changed

+65
-17
lines changed

1 file changed

+65
-17
lines changed

docs/options.md

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,96 @@
11
---
2-
title: 'Dropdown Options'
2+
title: 'Options'
33
---
44

5-
# Dropdown Options
5+
# Options
66

7-
## Default format
7+
The `options` prop is the core configuration for populating the dropdown menu. Understanding how to structure your options is essential for effective component usage.
88

9-
When using the `options` prop, you can pass an array of objects to the component. Each object should have a `label` and a `value` property. The `label` property is used to display the option in the dropdown, and the `value` property is the value that will be set to the `v-model` when the option is selected.
9+
## Basic structure
10+
11+
Each option requires two key properties:
1012

1113
```vue
1214
<template>
13-
<VueSelect :options="[{ label: 'Option #1', value: 'option_1' }]" />
15+
<VueSelect
16+
:options="[
17+
{ label: 'JavaScript', value: 'js' },
18+
{ label: 'TypeScript', value: 'ts' }
19+
]"
20+
/>
1421
</template>
1522
```
1623

24+
**Properties:**
25+
26+
- `label`: Text displayed in the dropdown menu
27+
- `value`: Data bound to `v-model` when the option is selected
28+
1729
::: info
18-
If you are using TypeScript, make sure to read the [TypeScript usage](/typescript) section to leverage proper type-safety.
19-
:::
30+
For TypeScript users, import the `Option` type to ensure proper type checking:
31+
32+
```ts
33+
import type { Option } from "vue3-select-component";
2034

21-
## Disabled option(s)
35+
const options: Option<string>[] = [{ label: 'JavaScript', value: 'js' }];
36+
```
37+
:::
2238

23-
You can disable an option by adding a `disabled` property to the object. The `disabled` property should be a boolean.
39+
## Disabling options
2440

25-
When an option is disabled, it cannot be selected nor focused/navigated to using the keyboard.
41+
Individual options can be disabled by adding the `disabled` property:
2642

2743
```vue
2844
<template>
29-
<VueSelect :options="[{ label: 'Option #1', value: 'option_1', disabled: true }]" />
45+
<VueSelect
46+
:options="[
47+
{ label: 'Available', value: 'a1' },
48+
{ label: 'Unavailable', value: 'a2', disabled: true }
49+
]"
50+
/>
3051
</template>
3152
```
3253

33-
## Passing extra properties
54+
Disabled options:
55+
56+
- Cannot be selected
57+
- Cannot be focused with keyboard navigation
58+
- Have distinct visual styling
59+
- Include proper ARIA attributes for accessibility
3460

35-
You can pass extra properties to the options object. The component will ignore them but you will be able to manipulate those extra properties using some props and slots.
61+
## Extended Properties
62+
63+
Options can include additional properties beyond the standard `label`/`value` pair:
3664

3765
```vue
3866
<template>
3967
<VueSelect
40-
:options="[{ label: 'Option #1', value: 'option_1', extra: 'Extra data' }]"
41-
:get-option-label="(option) => `${option.label} - ${option.extra}`"
42-
/>
68+
:options="[
69+
{
70+
label: 'JavaScript',
71+
value: 'js',
72+
version: 'ES2022',
73+
creator: 'Brendan Eich'
74+
}
75+
]"
76+
:get-option-label="option => `${option.label} (${option.version})`"
77+
>
78+
<template #option="{ option }">
79+
{{ option.label }} - Created by {{ option.creator }}
80+
</template>
81+
</VueSelect>
4382
</template>
4483
```
4584

4685
::: info
47-
If you are using TypeScript, make sure to read the [TypeScript usage](/typescript) section to leverage proper type-safety.
86+
When using extended properties with TypeScript, extend the `Option` type:
87+
88+
```ts
89+
type LanguageOption = Option<string> & {
90+
version: string;
91+
creator: string;
92+
};
93+
```
94+
95+
For more details, see the [Extending option properties guide](./typescript.md#extending-option-properties).
4896
:::

0 commit comments

Comments
 (0)