primevue-mirror/src/views/listbox/ListboxDoc.vue

553 lines
23 KiB
Vue
Raw Normal View History

2019-03-25 12:21:45 +00:00
<template>
<div class="content-section documentation">
<TabView>
<TabPanel header="Documentation">
2020-06-17 19:29:33 +00:00
<h5>Import</h5>
2021-02-03 10:10:30 +00:00
<pre v-code.script><code>
2019-03-25 12:21:45 +00:00
import Listbox from 'primevue/listbox';
2020-09-24 11:14:55 +00:00
</code></pre>
2019-03-25 12:21:45 +00:00
2020-06-17 19:29:33 +00:00
<h5>Getting Started</h5>
2019-05-22 15:20:03 +00:00
<p>Listbox requires a value to bind and a collection of arbitrary objects along with the <i>optionLabel</i> property to specify the label property of the option.</p>
2021-02-03 10:10:30 +00:00
<pre v-code><code>
2019-05-22 16:30:18 +00:00
&lt;Listbox v-model="selectedCity" :options="cities" optionLabel="name" /&gt;
2019-05-22 15:20:03 +00:00
2020-09-24 11:14:55 +00:00
</code></pre>
2021-02-03 10:10:30 +00:00
<pre v-code.script><code>
2019-03-25 12:21:45 +00:00
data() {
return {
selectedCity: null,
cities: [
{name: 'New York', code: 'NY'},
{name: 'Rome', code: 'RM'},
{name: 'London', code: 'LDN'},
{name: 'Istanbul', code: 'IST'},
{name: 'Paris', code: 'PRS'}
]
}
}
2020-09-24 11:14:55 +00:00
</code></pre>
2019-03-25 12:21:45 +00:00
2020-06-17 19:29:33 +00:00
<h5>Selection</h5>
2019-03-25 12:21:45 +00:00
<p>Listbox allows selection of either single or multiple items. In single case, model should be a single object reference whereas in multiple case should be an array. Multiple items can either be selected
using metaKey or toggled individually depending on the value of <i>metaKeySelection</i> property value which is true by default. On touch enabled
devices metaKeySelection is turned off automatically.</p>
2021-02-03 10:10:30 +00:00
<pre v-code><code>
2019-05-22 16:30:18 +00:00
&lt;Listbox v-model="selectedCity" :options="cities" optionLabel="name" :multiple="true"/&gt;
2020-09-24 11:14:55 +00:00
</code></pre>
2019-03-25 12:21:45 +00:00
2021-02-15 08:50:11 +00:00
<h5>Templating</h5>
2021-02-15 12:35:52 +00:00
<p>Label of an option is used as the display text of an item by default, for custom content support define an <i>option</i> template that gets the option instance as a parameter.
2021-02-15 08:50:11 +00:00
In addition <i>optiongroup</i>, <i>header</i>, <i>footer</i>, <i>emptyfilter</i> and <i>empty</i> slots are provided for further customization.</p>
2021-02-03 10:10:30 +00:00
<pre v-code><code><template v-pre>
2019-05-22 16:30:18 +00:00
&lt;Listbox v-model="selectedCars" :options="cars" :multiple="true" :filter="true" optionLabel="brand" listStyle="max-height:250px" style="width:15em"&gt;
2021-02-15 08:50:11 +00:00
&lt;template #header&gt;&lt;/template&gt;
&lt;template #option="slotProps"&gt;
2020-04-29 12:18:38 +00:00
&lt;div&gt;
&lt;img :alt="slotProps.option.brand" :src="'demo/images/car/' + slotProps.option.brand + '.png'" /&gt;
&lt;span&gt;{{slotProps.option.brand}}&lt;/span&gt;
2019-03-25 12:21:45 +00:00
&lt;/div&gt;
&lt;/template&gt;
2021-02-15 08:50:11 +00:00
&lt;template #footer&gt;&lt;/footer&gt;
2019-03-25 12:21:45 +00:00
&lt;/Listbox&gt;
</template>
2021-02-15 08:50:11 +00:00
</code></pre>
<h5>Grouping</h5>
<p>Options groups are specified with the <i>optionGroupLabel</i> and <i>optionGroupChildren</i> properties.</p>
<pre v-code.script><code>
export default {
data() {
return {
selectedGroupedCity: null,
groupedCities: [{
label: 'Germany', code: 'DE',
items: [
{label: 'Berlin', value: 'Berlin'},
{label: 'Frankfurt', value: 'Frankfurt'},
{label: 'Hamburg', value: 'Hamburg'},
{label: 'Munich', value: 'Munich'}
]
},
{
label: 'USA', code: 'US',
items: [
{label: 'Chicago', value: 'Chicago'},
{label: 'Los Angeles', value: 'Los Angeles'},
{label: 'New York', value: 'New York'},
{label: 'San Francisco', value: 'San Francisco'}
]
},
{
label: 'Japan', code: 'JP',
items: [
{label: 'Kyoto', value: 'Kyoto'},
{label: 'Osaka', value: 'Osaka'},
{label: 'Tokyo', value: 'Tokyo'},
{label: 'Yokohama', value: 'Yokohama'}
]
}]
}
}
}
</code></pre>
<pre v-code><code><template v-pre>
<Listbox v-model="selectedGroupedCity" :options="groupedCities"
optionLabel="label" optionGroupLabel="label" optionGroupChildren="items">
</Listbox>
</template>
2020-09-24 11:14:55 +00:00
</code></pre>
2019-03-25 12:21:45 +00:00
2020-06-17 19:29:33 +00:00
<h5>Filter</h5>
2021-02-15 08:50:11 +00:00
<p>Filtering allows searching items in the list using an input field at the header. In order to use filtering, enable <i>filter</i> property. By default,
optionLabel is used when searching and <i>filterFields</i> can be used to customize the fields being utilized. Furthermore, <i>filterMatchMode</i> is available
to define the search algorithm. Valid values are "contains" (default), "startsWith" and "endsWith".</p>
2021-02-03 10:10:30 +00:00
<pre v-code><code>
2019-05-22 16:30:18 +00:00
&lt;Listbox v-model="selectedCity" :options="cities" optionLabel="name" :filter="true"/&gt;
2020-09-24 11:14:55 +00:00
</code></pre>
2019-03-25 12:21:45 +00:00
2020-06-17 19:29:33 +00:00
<h5>Properties</h5>
2020-01-13 09:04:50 +00:00
<p>Any property as style and class are passed to the main container element. Following are the additional properties to configure the component.</p>
2019-03-25 12:21:45 +00:00
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
2019-05-22 15:20:03 +00:00
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
2019-03-25 12:21:45 +00:00
</thead>
<tbody>
2019-05-22 15:20:03 +00:00
<tr>
2020-09-21 12:27:08 +00:00
<td>modelValue</td>
2019-05-22 15:20:03 +00:00
<td>any</td>
<td>null</td>
<td>Value of the component.</td>
</tr>
<tr>
<td>options</td>
<td>array</td>
<td>null</td>
<td>An array of selectitems to display as the available options.</td>
</tr>
<tr>
<td>optionLabel</td>
<td>string</td>
<td>null</td>
2020-09-08 12:25:15 +00:00
<td>Property name or getter function to use as the label of an option.</td>
2019-05-22 15:20:03 +00:00
</tr>
<tr>
<td>optionValue</td>
<td>string</td>
<td>null</td>
2020-09-08 12:25:15 +00:00
<td>Property name or getter function to use as the value of an option, defaults to the option itself when not defined.</td>
2019-05-22 15:20:03 +00:00
</tr>
<tr>
<td>optionDisabled</td>
<td>boolean</td>
<td>null</td>
2020-09-08 12:25:15 +00:00
<td>Property name or getter function to use as the disabled flag of an option, defaults to false when not defined.</td>
2019-05-22 15:20:03 +00:00
</tr>
2021-02-15 08:50:11 +00:00
<tr>
<td>optionGroupLabel</td>
<td>string</td>
<td>null</td>
<td>Property name or getter function to use as the label of an option group.</td>
</tr>
<tr>
<td>optionGroupChildren</td>
<td>string</td>
<td>null</td>
<td>Property name or getter function that refers to the children options of option group.</td>
</tr>
2019-05-22 15:20:03 +00:00
<tr>
<td>listStyle</td>
<td>string</td>
<td>null</td>
<td>Inline style of inner list element.</td>
</tr>
<tr>
<td>disabled</td>
<td>boolean</td>
<td>false</td>
<td>When specified, disables the component.</td>
</tr>
<tr>
<td>dataKey</td>
<td>string</td>
<td>false</td>
2020-07-01 17:52:25 +00:00
<td>A property to uniquely identify an option.</td>
2019-05-22 15:20:03 +00:00
</tr>
<tr>
<td>multiple</td>
<td>boolean</td>
<td>false</td>
<td>When specified, allows selecting multiple values.</td>
</tr>
<tr>
<td>metaKeySelection</td>
<td>boolean</td>
<td>true</td>
<td>Defines how multiple items can be selected, when true metaKey needs to be pressed to select or unselect an item and when set to false selection of each item
can be toggled individually. On touch enabled devices, metaKeySelection is turned off automatically.</td>
</tr>
<tr>
<td>filter</td>
<td>boolean</td>
<td>false</td>
<td>When specified, displays a filter input at header.</td>
</tr>
<tr>
<td>filterPlaceholder</td>
<td>string</td>
<td>null</td>
<td>Placeholder text to show when filter input is empty.</td>
</tr>
<tr>
<td>filterLocale</td>
<td>string</td>
<td>undefined</td>
<td>Locale to use in filtering. The default locale is the host environment's current locale.</td>
</tr>
2021-02-15 08:50:11 +00:00
<tr>
<td>filterMatchMode</td>
<td>string</td>
<td>contains</td>
<td>Defines the filtering algorithm to use when searching the options. Valid values are "contains" (default), "startsWith" and "endsWith"</td>
</tr>
<tr>
<td>filterFields</td>
<td>array</td>
<td>null</td>
<td>Fields used when filtering the options, defaults to optionLabel.</td>
</tr>
<tr>
<td>emptyFilterMessage</td>
<td>string</td>
<td>No results found</td>
2021-02-15 08:50:11 +00:00
<td>Text to display when filtering does not return any results. Defaults to value from PrimeVue locale configuration.</td>
</tr>
<tr>
<td>emptyMessage</td>
<td>string</td>
<td>No results found</td>
<td>Text to display when there are no options available. Defaults to value from PrimeVue locale configuration.</td>
2019-05-22 15:20:03 +00:00
</tr>
2019-03-25 12:21:45 +00:00
</tbody>
</table>
</div>
2020-06-17 19:29:33 +00:00
<h5>Events</h5>
2019-03-25 12:21:45 +00:00
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
2019-05-22 15:20:03 +00:00
<tr>
<th>Name</th>
<th>Parameters</th>
<th>Description</th>
</tr>
2019-03-25 12:21:45 +00:00
</thead>
<tbody>
2019-05-22 15:20:03 +00:00
<tr>
<td>change</td>
<td>event.originalEvent: Original event <br />
event.value: Selected option value </td>
<td>Callback to invoke on value change.</td>
</tr>
<tr>
<td>filter</td>
<td>event.originalEvent: Original event <br />
event.value: Filter value </td>
<td>Callback to invoke on filter input.</td>
2019-05-22 15:20:03 +00:00
</tr>
2019-03-25 12:21:45 +00:00
</tbody>
</table>
</div>
2021-02-15 08:50:11 +00:00
<h5>Slots</h5>
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
<tr>
<th>Name</th>
<th>Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td>option</td>
<td>option: Option instance <br />
index: Index of the option</td>
</tr>
<tr>
<td>optiongroup</td>
<td>option: OptionGroup instance <br />
index: Index of the option group</td>
</tr>
<tr>
<td>header</td>
<td>value: Value of the component <br />
options: Displayed options</td>
</tr>
<tr>
<td>footer</td>
<td>value: Value of the component <br />
options: Displayed options</td>
</tr>
<tr>
<td>emptyfilter</td>
<td>-</td>
</tr>
<tr>
<td>empty</td>
<td>-</td>
</tr>
</tbody>
</table>
</div>
2020-06-17 19:29:33 +00:00
<h5>Styling</h5>
2019-03-25 12:21:45 +00:00
<p>Following is the list of structural style classes, for theming classes visit <router-link to="/theming">theming</router-link> page.</p>
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
2019-05-22 15:20:03 +00:00
<tr>
<th>Name</th>
<th>Element</th>
</tr>
2019-03-25 12:21:45 +00:00
</thead>
<tbody>
2019-05-22 15:20:03 +00:00
<tr>
<td>p-listbox</td>
<td>Main container element.</td>
</tr>
<tr>
<td>p-listbox-header</td>
<td>Header element.</td>
</tr>
<tr>
<td>p-listbox-list-wrapper</td>
<td>Container of list element.</td>
</tr>
<tr>
<td>p-listbox-list</td>
<td>List element.</td>
</tr>
<tr>
<td>p-listbox-item</td>
<td>An item in the list element.</td>
</tr>
2019-03-25 12:21:45 +00:00
</tbody>
</table>
</div>
2020-06-17 19:29:33 +00:00
<h5>Dependencies</h5>
2019-03-25 12:21:45 +00:00
<p>None.</p>
</TabPanel>
<TabPanel header="Source">
2021-01-07 14:16:53 +00:00
<div class="p-d-flex p-jc-between">
<a href="https://github.com/primefaces/primevue/tree/master/src/views/listbox" class="btn-viewsource" target="_blank" rel="noopener noreferrer">
<span>View on GitHub</span>
</a>
<LiveEditor name="ListboxDemo" :sources="sources"/>
</div>
2021-02-03 10:10:30 +00:00
<pre v-code><code><template v-pre>
2020-07-01 12:21:42 +00:00
&lt;h5&gt;Single&lt;/h5&gt;
&lt;Listbox v-model="selectedCity" :options="cities" optionLabel="name" style="width:15rem" /&gt;
2019-03-25 12:21:45 +00:00
2021-02-15 08:50:11 +00:00
&lt;h5&gt;Grouped&lt;/h5&gt;
&lt;Listbox v-model="selectedGroupedCity" :options="groupedCities" optionLabel="label" style="width:15rem" optionGroupLabel="label" optionGroupChildren="items" listStyle="max-height:250px"&gt;
&lt;template #optiongroup="slotProps"&gt;
&lt;div class="p-d-flex p-ai-center country-item"&gt;
&lt;img src="../../assets/images/flag_placeholder.png" :class="'flag flag-' + slotProps.option.code.toLowerCase()" width="18" /&gt;
&lt;div&gt;{{slotProps.option.label}}&lt;/div&gt;
&lt;/div&gt;
&lt;/template&gt;
&lt;/Listbox&gt;
2020-07-01 12:21:42 +00:00
&lt;h5&gt;Advanced with Templating, Filtering and Multiple Selection&lt;/h5&gt;
2021-02-15 08:50:11 +00:00
&lt;Listbox v-model="selectedCountries" :options="countries" :multiple="true" :filter="true" optionLabel="name" listStyle="max-height:250px" style="width:15rem" filterPlaceholder="Search"&gt;
2019-08-04 12:19:34 +00:00
&lt;template #option="slotProps"&gt;
2020-07-01 12:21:42 +00:00
&lt;div class="country-item"&gt;
&lt;img src="../../assets/images/flag_placeholder.png" :class="'flag flag-' + slotProps.option.code.toLowerCase()" /&gt;
&lt;div&gt;{{slotProps.option.name}}&lt;/div&gt;
2019-08-04 12:19:34 +00:00
&lt;/div&gt;
&lt;/template&gt;
&lt;/Listbox&gt;
2019-03-25 12:21:45 +00:00
</template>
2020-09-24 11:14:55 +00:00
</code></pre>
2019-03-25 12:21:45 +00:00
2021-02-03 10:10:30 +00:00
<pre v-code.script><code>
2019-03-25 12:21:45 +00:00
export default {
2020-07-01 12:21:42 +00:00
data() {
return {
selectedCity: null,
selectedCountries: null,
2021-02-15 08:50:11 +00:00
selectedGroupedCity: null,
2020-07-01 12:21:42 +00:00
cities: [
{name: 'New York', code: 'NY'},
{name: 'Rome', code: 'RM'},
{name: 'London', code: 'LDN'},
{name: 'Istanbul', code: 'IST'},
{name: 'Paris', code: 'PRS'}
],
countries: [
{name: 'Australia', code: 'AU'},
2020-07-01 12:33:00 +00:00
{name: 'Brazil', code: 'BR'},
2020-07-01 12:21:42 +00:00
{name: 'China', code: 'CN'},
2020-07-01 12:33:00 +00:00
{name: 'Egypt', code: 'EG'},
{name: 'France', code: 'FR'},
2020-07-01 12:21:42 +00:00
{name: 'Germany', code: 'DE'},
{name: 'India', code: 'IN'},
{name: 'Japan', code: 'JP'},
{name: 'Spain', code: 'ES'},
{name: 'United States', code: 'US'}
2021-02-15 08:50:11 +00:00
],
groupedCities: [{
label: 'Germany', code: 'DE',
items: [
{label: 'Berlin', value: 'Berlin'},
{label: 'Frankfurt', value: 'Frankfurt'},
{label: 'Hamburg', value: 'Hamburg'},
{label: 'Munich', value: 'Munich'}
]
},
{
label: 'USA', code: 'US',
items: [
{label: 'Chicago', value: 'Chicago'},
{label: 'Los Angeles', value: 'Los Angeles'},
{label: 'New York', value: 'New York'},
{label: 'San Francisco', value: 'San Francisco'}
]
},
{
label: 'Japan', code: 'JP',
items: [
{label: 'Kyoto', value: 'Kyoto'},
{label: 'Osaka', value: 'Osaka'},
{label: 'Tokyo', value: 'Tokyo'},
{label: 'Yokohama', value: 'Yokohama'}
]
}]
2020-07-01 12:21:42 +00:00
}
2020-04-29 12:18:38 +00:00
}
}
2020-09-24 11:14:55 +00:00
</code></pre>
2019-03-25 12:21:45 +00:00
</TabPanel>
</TabView>
</div>
2021-01-07 14:16:53 +00:00
</template>
<script>
import LiveEditor from '../liveeditor/LiveEditor';
export default {
data() {
return {
sources: {
'template': {
content: `<template>
<div class="layout-content">
<div class="content-section implementation">
<div class="card">
<h5>Single</h5>
<Listbox v-model="selectedCity" :options="cities" optionLabel="name" style="width:15rem" />
2021-02-15 08:50:11 +00:00
<h5>Grouped</h5>
<Listbox v-model="selectedGroupedCity" :options="groupedCities" optionLabel="label" style="width:15rem" optionGroupLabel="label" optionGroupChildren="items" listStyle="max-height:250px">
<template #optiongroup="slotProps">
<div class="p-d-flex p-ai-center country-item">
<img src="../../assets/images/flag_placeholder.png" :class="'flag flag-' + slotProps.option.code.toLowerCase()" width="18" />
<div>{{slotProps.option.label}}</div>
</div>
</template>
</Listbox>
2021-01-07 14:16:53 +00:00
<h5>Advanced with Templating, Filtering and Multiple Selection</h5>
2021-02-15 08:50:11 +00:00
<Listbox v-model="selectedCountries" :options="countries" :multiple="true" :filter="true" optionLabel="name" listStyle="max-height:250px" style="width:15rem" filterPlaceholder="Search">
2021-01-07 14:16:53 +00:00
<template #option="slotProps">
<div class="country-item">
2021-02-15 08:50:11 +00:00
<img src="../../assets/images/flag_placeholder.png" :class="'flag flag-' + slotProps.option.code.toLowerCase()" />
2021-01-07 14:16:53 +00:00
<div>{{slotProps.option.name}}</div>
</div>
</template>
</Listbox>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
selectedCity: null,
selectedCountries: null,
2021-02-15 08:50:11 +00:00
selectedGroupedCity: null,
2021-01-07 14:16:53 +00:00
cities: [
{name: 'New York', code: 'NY'},
{name: 'Rome', code: 'RM'},
{name: 'London', code: 'LDN'},
{name: 'Istanbul', code: 'IST'},
{name: 'Paris', code: 'PRS'}
],
countries: [
{name: 'Australia', code: 'AU'},
{name: 'Brazil', code: 'BR'},
{name: 'China', code: 'CN'},
{name: 'Egypt', code: 'EG'},
{name: 'France', code: 'FR'},
{name: 'Germany', code: 'DE'},
{name: 'India', code: 'IN'},
{name: 'Japan', code: 'JP'},
{name: 'Spain', code: 'ES'},
{name: 'United States', code: 'US'}
2021-02-15 08:50:11 +00:00
],
groupedCities: [{
label: 'Germany', code: 'DE',
items: [
{label: 'Berlin', value: 'Berlin'},
{label: 'Frankfurt', value: 'Frankfurt'},
{label: 'Hamburg', value: 'Hamburg'},
{label: 'Munich', value: 'Munich'}
]
},
{
label: 'USA', code: 'US',
items: [
{label: 'Chicago', value: 'Chicago'},
{label: 'Los Angeles', value: 'Los Angeles'},
{label: 'New York', value: 'New York'},
{label: 'San Francisco', value: 'San Francisco'}
]
},
{
label: 'Japan', code: 'JP',
items: [
{label: 'Kyoto', value: 'Kyoto'},
{label: 'Osaka', value: 'Osaka'},
{label: 'Tokyo', value: 'Tokyo'},
{label: 'Yokohama', value: 'Yokohama'}
]
}]
2021-01-07 14:16:53 +00:00
}
}
}`
}
}
}
},
components: {
LiveEditor
}
}
</script>