forked from bootstrap-vue-next/bootstrap-vue-next
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(BFormSelect): Refactor (bootstrap-vue-next#2460)
* docs(BFormSelect): Refactor examples * docs: Normalize options docs between checkbox, radio and select * docs: Factor out options property documentation * docs: remnove unused code fragments
- Loading branch information
Showing
21 changed files
with
264 additions
and
536 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Options | ||
|
||
## Options Property | ||
|
||
`options` can be an array of strings or objects, or a key-value object. Available fields: | ||
|
||
- **`value`** The selected value which will be set on `v-model` | ||
- **`disabled`** Disables item for selection | ||
- **`text`** Display text | ||
|
||
`value` can be a string, number, or simple object. Avoid using complex types in values. | ||
|
||
::: info NOTE | ||
The BootstrapVue field `html` on the `options` object has been deprecated. See our | ||
[Migration Guide](/docs/migration-guide/#v-html) for details. | ||
::: | ||
|
||
### Options as an array | ||
|
||
<<< FRAGMENT ./demo/OptionsArray.ts#snippet{ts} | ||
|
||
If an array entry is a string, it will be used for both the generated `value` and `text` fields. | ||
|
||
You can mix using strings and [objects](#options-as-an-array-of-objects) in the array. | ||
|
||
Internally, BootstrapVueNext will convert the above array to the following array (the | ||
[array of objects](#options-as-an-array-of-objects)) format: | ||
|
||
<<< FRAGMENT ./demo/OptionsObjectArray.ts#snippet{ts} | ||
|
||
### Options as an array of objects | ||
|
||
<<< FRAGMENT ./demo/OptionsObjectArrayRaw.ts#snippet{ts} | ||
|
||
If `value` is missing, then `text` will be used as both the `value` and `text` fields. | ||
|
||
Internally, BootstrapVueNext will convert the above array to the following array (the | ||
[array of objects](#options-as-an-array-of-objects)) format: | ||
|
||
<<< FRAGMENT ./demo/OptionsObjectArrayNormalized.ts#snippet{ts} | ||
|
||
### Changing the option field names | ||
|
||
If you want to customize the field property names (for example using `name` field for display | ||
`text`) you can easily change them by setting the `text-field`, `value-field`, and | ||
`disabled-field` props to a string that contains the property name you would like to use: |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
apps/docs/src/docs/components/demo/RadioObjectArrayNormalized.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<template> | ||
<BFormSelect | ||
v-model="selected" | ||
:options="exFieldNamesOptions" | ||
class="mb-3" | ||
value-field="item" | ||
text-field="name" | ||
disabled-field="notEnabled" | ||
/> | ||
|
||
<div class="mt-3"> | ||
Selected: <strong>{{ selected }}</strong> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import {ref} from 'vue' | ||
const exFieldNamesOptions = [ | ||
{item: 'A', name: 'Option A'}, | ||
{item: 'B', name: 'Option B'}, | ||
{item: 'D', name: 'Option C', notEnabled: true}, | ||
{item: {d: 1}, name: 'Option D'}, | ||
] | ||
const selected = ref('A') | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<template> | ||
<BFormSelect v-model="selected" :options="exMultiOptions" multiple :select-size="4" /> | ||
|
||
<div class="mt-3"> | ||
Selected: <strong>{{ selected }}</strong> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import {ref} from 'vue' | ||
const exMultiOptions = [ | ||
{value: 'a', text: 'This is First option'}, | ||
{value: 'b', text: 'Default Selected Option'}, | ||
{value: 'c', text: 'This is another option'}, | ||
{value: 'd', text: 'This one is disabled', disabled: true}, | ||
{value: 'e', text: 'This is option e'}, | ||
{value: 'f', text: 'This is option f'}, | ||
{value: 'g', text: 'This is option g'}, | ||
] | ||
const selected = ref(['b']) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<template> | ||
<BFormSelect v-model="selected" :options="ex1GroupOptions" /> | ||
|
||
<div class="mt-3"> | ||
Selected: <strong>{{ selected }}</strong> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import {ref} from 'vue' | ||
const ex1GroupOptions = [ | ||
{value: null, text: 'Please select an option'}, | ||
{value: 'a', text: 'This is First option'}, | ||
{value: 'b', text: 'Selected Option', disabled: true}, | ||
{ | ||
label: 'Grouped options', | ||
options: [ | ||
{value: {C: '3PO'}, text: 'Option with object value'}, | ||
{value: {R: '2D2'}, text: 'Another option with object value'}, | ||
], | ||
}, | ||
] | ||
const selected = ref() | ||
</script> |
21 changes: 21 additions & 0 deletions
21
apps/docs/src/docs/components/demo/SelectOptionsManual.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<template> | ||
<BFormSelect v-model="selected"> | ||
<BFormSelectOption :value="null">Please select an option</BFormSelectOption> | ||
<BFormSelectOption value="a">Option A</BFormSelectOption> | ||
<BFormSelectOption value="b" disabled>Option B (disabled)</BFormSelectOption> | ||
<BFormSelectOptionGroup label="Grouped options"> | ||
<BFormSelectOption :value="{C: '3PO'}">Option with object value</BFormSelectOption> | ||
<BFormSelectOption :value="{R: '2D2'}">Another option with object value</BFormSelectOption> | ||
</BFormSelectOptionGroup> | ||
</BFormSelect> | ||
|
||
<div class="mt-3"> | ||
Selected: <strong>{{ selected }}</strong> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import {ref} from 'vue' | ||
const selected = ref(null) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<template> | ||
<BFormSelect v-model="selected" :options="exFirstSlotOptions" class="mb-3"> | ||
<!-- This slot appears above the options from 'options' prop --> | ||
<template #first> | ||
<BFormSelectOption :value="null" disabled>-- Please select an option --</BFormSelectOption> | ||
</template> | ||
|
||
<!-- These options will appear after the ones from 'options' prop --> | ||
<BFormSelectOption value="C">Option C</BFormSelectOption> | ||
<BFormSelectOption value="D">Option D</BFormSelectOption> | ||
</BFormSelect> | ||
|
||
<div class="mt-3"> | ||
Selected: <strong>{{ selected }}</strong> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import {ref} from 'vue' | ||
const exFirstSlotOptions = [ | ||
{value: 'A', text: 'Option A (from options prop)'}, | ||
{value: 'B', text: 'Option B (from options prop)'}, | ||
] | ||
const selected = ref(null) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
```vue | ||
<template> | ||
<BFormSelect v-model="selected" :options="ex1Options" /> | ||
|
||
<BFormSelect v-model="selected" :options="ex1Options" size="sm" class="mt-3" /> | ||
|
||
<div class="mt-3"> | ||
Selected: <strong>{{ selected }}</strong> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import {ref} from 'vue' | ||
const ex1Options = [ | ||
{value: null, text: 'Please select an option'}, | ||
{value: 'a', text: 'This is First option'}, | ||
{value: 'b', text: 'Selected Option'}, | ||
{value: {C: '3PO'}, text: 'This is an option with object value'}, | ||
{value: 'd', text: 'This one is disabled', disabled: true}, | ||
] | ||
const selected = ref(null) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<template> | ||
<BFormSelect v-model="selected" :options="ex1Options" /> | ||
|
||
<div class="mt-3"> | ||
Selected: <strong>{{ selected }}</strong> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import {ref} from 'vue' | ||
const ex1Options = [ | ||
{value: null, text: 'Please select an option'}, | ||
{value: 'a', text: 'This is First option'}, | ||
{value: 'b', text: 'Selected Option'}, | ||
{value: {C: '3PO'}, text: 'This is an option with object value'}, | ||
{value: 'd', text: 'This one is disabled', disabled: true}, | ||
] | ||
const selected = ref() | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<template> | ||
<BFormSelect v-model="selected" :options="ex1Options" :select-size="4" /> | ||
|
||
<div class="mt-3"> | ||
Selected: <strong>{{ selected }}</strong> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import {ref} from 'vue' | ||
const ex1Options = [ | ||
{value: null, text: 'Please select an option'}, | ||
{value: 'a', text: 'This is First option'}, | ||
{value: 'b', text: 'Selected Option'}, | ||
{value: {C: '3PO'}, text: 'This is an option with object value'}, | ||
{value: 'd', text: 'This one is disabled', disabled: true}, | ||
] | ||
const selected = ref() | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.