1002 lines
40 KiB
Vue
1002 lines
40 KiB
Vue
<template>
|
|
<AppDoc name="CascadeSelectDemo" :sources="sources">
|
|
<h5>Import via Module</h5>
|
|
<pre v-code.script><code>
|
|
import CascadeSelect from 'primevue/cascadeselect';
|
|
|
|
</code></pre>
|
|
|
|
<h5>Import via CDN</h5>
|
|
<pre v-code><code>
|
|
<script src="https://unpkg.com/primevue@^3/core/core.min.js"></script>
|
|
<script src="https://unpkg.com/primevue@^3/cascadeselect/cascadeselect.min.js"></script>
|
|
|
|
</code></pre>
|
|
|
|
<h5>Getting Started</h5>
|
|
<p>
|
|
CascadeSelect requires a value to bind and a collection of arbitrary objects with a nested hierarchy. <i>optionGroupLabel</i> is used for the text of a category and <i>optionGroupChildren</i> is to define the children of the category.
|
|
Note that order of the <i>optionGroupChildren</i> matters and it should correspond to the data hierarchy.
|
|
</p>
|
|
|
|
<pre v-code><code>
|
|
<CascadeSelect v-model="selectedCity" :options="countries" optionLabel="cname" optionGroupLabel="name"
|
|
:optionGroupChildren="['states', 'cities']" style="minWidth: 14rem" >
|
|
|
|
</code></pre>
|
|
|
|
<pre v-code.script><code>
|
|
data() {
|
|
return {
|
|
selectedCity: null,
|
|
countries: [
|
|
{
|
|
name: 'Australia',
|
|
code: 'AU',
|
|
states: [
|
|
{
|
|
name: 'New South Wales',
|
|
cities: [
|
|
{cname: 'Sydney', code: 'A-SY'},
|
|
{cname: 'Newcastle', code: 'A-NE'},
|
|
{cname: 'Wollongong', code: 'A-WO'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Queensland',
|
|
cities: [
|
|
{cname: 'Brisbane', code: 'A-BR'},
|
|
{cname: 'Townsville', code: 'A-TO'}
|
|
]
|
|
},
|
|
|
|
]
|
|
},
|
|
{
|
|
name: 'Canada',
|
|
code: 'CA',
|
|
states: [
|
|
{
|
|
name: 'Quebec',
|
|
cities: [
|
|
{cname: 'Montreal', code: 'C-MO'},
|
|
{cname: 'Quebec City', code: 'C-QU'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Ontario',
|
|
cities: [
|
|
{cname: 'Ottawa', code: 'C-OT'},
|
|
{cname: 'Toronto', code: 'C-TO'}
|
|
]
|
|
},
|
|
|
|
]
|
|
},
|
|
{
|
|
name: 'United States',
|
|
code: 'US',
|
|
states: [
|
|
{
|
|
name: 'California',
|
|
cities: [
|
|
{cname: 'Los Angeles', code: 'US-LA'},
|
|
{cname: 'San Diego', code: 'US-SD'},
|
|
{cname: 'San Francisco', code: 'US-SF'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Florida',
|
|
cities: [
|
|
{cname: 'Jacksonville', code: 'US-JA'},
|
|
{cname: 'Miami', code: 'US-MI'},
|
|
{cname: 'Tampa', code: 'US-TA'},
|
|
{cname: 'Orlando', code: 'US-OR'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Texas',
|
|
cities: [
|
|
{cname: 'Austin', code: 'US-AU'},
|
|
{cname: 'Dallas', code: 'US-DA'},
|
|
{cname: 'Houston', code: 'US-HO'}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
|
|
</code></pre>
|
|
|
|
<h5>Templating</h5>
|
|
<p>Content of an item can be customized with the <i>option</i> template.</p>
|
|
|
|
<pre v-code><code>
|
|
<CascadeSelect v-model="selectedCity" :options="countries" optionLabel="cname" optionGroupLabel="name"
|
|
:optionGroupChildren="['states', 'cities']" style="minWidth: 14rem">
|
|
<template #option="slotProps">
|
|
<div class="country-item">
|
|
<img src="https://primefaces.org/cdn/primevue/images/flag/flag_placeholder.png" :class="'flag flag-' + slotProps.option.code.toLowerCase()" v-if="slotProps.option.states" />
|
|
<i class="pi pi-compass mr-2" v-if="slotProps.option.cities"></i>
|
|
<i class="pi pi-map-marker mr-2" v-if="slotProps.option.cname"></i>
|
|
<span>{{slotProps.option.cname || slotProps.option.name}}</span>
|
|
</div>
|
|
</template>
|
|
</CascadeSelect>
|
|
|
|
</code></pre>
|
|
|
|
<h5>Properties</h5>
|
|
<p>Any property as style and class are passed to the main container element. Following are the additional properties to configure the component.</p>
|
|
<div class="doc-tablewrapper">
|
|
<table class="doc-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Type</th>
|
|
<th>Default</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>modelValue</td>
|
|
<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 | function</td>
|
|
<td>null</td>
|
|
<td>Property name or getter function to use as the label of an option.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>optionValue</td>
|
|
<td>string | function</td>
|
|
<td>null</td>
|
|
<td>Property name or getter function to use as the value of an option, defaults to the option itself when not defined.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>optionDisabled</td>
|
|
<td>string | function</td>
|
|
<td>null</td>
|
|
<td>Property name or getter function to use as the disabled flag of an option, defaults to false when not defined.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>optionGroupLabel</td>
|
|
<td>string | function</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>array | function</td>
|
|
<td>null</td>
|
|
<td>Property name or getter function to retrieve the items of a group.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>placeholder</td>
|
|
<td>string</td>
|
|
<td>null</td>
|
|
<td>Default text to display when no option is selected.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>disabled</td>
|
|
<td>boolean</td>
|
|
<td>false</td>
|
|
<td>When present, it specifies that the component should be disabled.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>dataKey</td>
|
|
<td>string</td>
|
|
<td>null</td>
|
|
<td>A property to uniquely identify an option.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>inputId</td>
|
|
<td>string</td>
|
|
<td>null</td>
|
|
<td>Identifier of the underlying input element.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>inputStyle</td>
|
|
<td>any</td>
|
|
<td>null</td>
|
|
<td>Inline style of the input field.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>inputClass</td>
|
|
<td>string</td>
|
|
<td>null</td>
|
|
<td>Style class of the input field.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>inputProps</td>
|
|
<td>object</td>
|
|
<td>null</td>
|
|
<td>Uses to pass all properties of the HTMLInputElement/HTMLSpanElement to the focusable input element inside the component.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>panelStyle</td>
|
|
<td>any</td>
|
|
<td>null</td>
|
|
<td>Inline style of the overlay panel.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>panelClass</td>
|
|
<td>string</td>
|
|
<td>null</td>
|
|
<td>Style class of the overlay panel.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>panelProps</td>
|
|
<td>object</td>
|
|
<td>null</td>
|
|
<td>Uses to pass all properties of the HTMLDivElement to the overlay panel.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>appendTo</td>
|
|
<td>string</td>
|
|
<td>body</td>
|
|
<td>A valid query selector or an HTMLElement to specify where the overlay gets attached. Special keywords are "body" for document body and "self" for the element itself.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>loading</td>
|
|
<td>boolean</td>
|
|
<td>false</td>
|
|
<td>Whether the dropdown is in loading state.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>dropdownIcon</td>
|
|
<td>string</td>
|
|
<td>pi pi-chevron-down</td>
|
|
<td>Icon to display in the dropdown.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>loadingIcon</td>
|
|
<td>string</td>
|
|
<td>pi pi-spinner pi-spin</td>
|
|
<td>Icon to display in loading state.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>optionGroupIcon</td>
|
|
<td>string</td>
|
|
<td>pi pi-angle-right</td>
|
|
<td>Icon to display in the option group.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>autoOptionFocus</td>
|
|
<td>boolean</td>
|
|
<td>true</td>
|
|
<td>Whether to focus on the first visible or selected element when the overlay panel is shown.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>selectOnFocus</td>
|
|
<td>boolean</td>
|
|
<td>false</td>
|
|
<td>When enabled, the focused option is selected/opened.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>searchLocale</td>
|
|
<td>string</td>
|
|
<td>undefined</td>
|
|
<td>Locale to use in searching. The default locale is the host environment's current locale.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>searchMessage</td>
|
|
<td>string</td>
|
|
<td>{0} results are available</td>
|
|
<td>Text to be displayed in hidden accessible field when filtering returns any results. Defaults to value from PrimeVue locale configuration.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>selectionMessage</td>
|
|
<td>string</td>
|
|
<td>{0} items selected</td>
|
|
<td>Text to be displayed in hidden accessible field when options are selected. Defaults to value from PrimeVue locale configuration.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>emptySelectionMessage</td>
|
|
<td>string</td>
|
|
<td>No selected item</td>
|
|
<td>Text to be displayed in hidden accessible field when any option is not selected. Defaults to value from PrimeVue locale configuration.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>emptySearchMessage</td>
|
|
<td>string</td>
|
|
<td>No results found</td>
|
|
<td>Text to be displayed 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 available options</td>
|
|
<td>Text to be displayed when there are no options available. Defaults to value from PrimeVue locale configuration.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>tabindex</td>
|
|
<td>number</td>
|
|
<td>0</td>
|
|
<td>Index of the element in tabbing order.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>aria-label</td>
|
|
<td>string</td>
|
|
<td>null</td>
|
|
<td>Defines a string value that labels an interactive element.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>aria-labelledby</td>
|
|
<td>string</td>
|
|
<td>null</td>
|
|
<td>Establishes relationships between the component and label(s) where its value should be one or more element IDs.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<h5>Events</h5>
|
|
<div class="doc-tablewrapper">
|
|
<table class="doc-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Parameters</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<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>focus</td>
|
|
<td>event</td>
|
|
<td>Callback to invoke when the component receives focus.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>blur</td>
|
|
<td>event</td>
|
|
<td>Callback to invoke when the component loses focus.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>click</td>
|
|
<td>event</td>
|
|
<td>Callback to invoke on click.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>group-change</td>
|
|
<td>
|
|
event.originalEvent: Original event <br />
|
|
event.value: Selected option group
|
|
</td>
|
|
<td>Callback to invoke when a group changes.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>before-show</td>
|
|
<td>-</td>
|
|
<td>Callback to invoke before the overlay is shown.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>before-hide</td>
|
|
<td>-</td>
|
|
<td>Callback to invoke before the overlay is hidden.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>show</td>
|
|
<td>-</td>
|
|
<td>Callback to invoke when the overlay is shown.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>hide</td>
|
|
<td>-</td>
|
|
<td>Callback to invoke when the overlay is hidden.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<h5>Slots</h5>
|
|
<div class="doc-tablewrapper">
|
|
<table class="doc-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Parameters</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>value</td>
|
|
<td>
|
|
value: Value of the component <br />
|
|
placeholder: Placeholder text to show
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>option</td>
|
|
<td>option: Option instance</td>
|
|
</tr>
|
|
<tr>
|
|
<td>indicator</td>
|
|
<td>-</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<h5>Styling</h5>
|
|
<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>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Element</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>p-cascadeselect</td>
|
|
<td>Container element.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>p-cascadeselect-label</td>
|
|
<td>Element to display label of selected option.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>p-cascadeselect-trigger</td>
|
|
<td>Icon element.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>p-cascadeselect-panel</td>
|
|
<td>Icon element.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>p-cascadeselect-items-wrapper</td>
|
|
<td>Wrapper element of items list.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>p-cascadeselect-items</td>
|
|
<td>List element of items.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>p-cascadeselect-item</td>
|
|
<td>An item in the list.</td>
|
|
</tr>
|
|
<tr>
|
|
<td>p-overlay-open</td>
|
|
<td>Container element when overlay is visible.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<h5>Accessibility</h5>
|
|
<h6>Screen Reader</h6>
|
|
<p>
|
|
Value to describe the component can either be provided with <i>aria-labelledby</i> or <i>aria-label</i> props. The cascadeselect element has a <i>combobox</i> role in addition to <i>aria-haspopup</i> and <i>aria-expanded</i> attributes.
|
|
The relation between the combobox and the popup is created with <i>aria-controls</i> that refers to the id of the popup.
|
|
</p>
|
|
<p>
|
|
The popup list has an id that refers to the <i>aria-controls</i> attribute of the <i>combobox</i> element and uses <i>tree</i> as the role. Each list item has a <i>treeitem</i> role along with <i>aria-label</i>, <i>aria-selected</i> and
|
|
<i>aria-expanded</i> attributes. The container element of a treenode has the <i>group</i> role. The <i>aria-setsize</i>, <i>aria-posinset</i> and <i>aria-level</i> attributes are calculated implicitly and added to each treeitem.
|
|
</p>
|
|
|
|
<pre v-code><code>
|
|
<span id="dd1">Options</span>
|
|
<CascadeSelect aria-labelledby="dd1" />
|
|
|
|
<CascadeSelect aria-label="Options" />
|
|
|
|
</code></pre>
|
|
|
|
<h6>Closed State Keyboard Support</h6>
|
|
<div class="doc-tablewrapper">
|
|
<table class="doc-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Key</th>
|
|
<th>Function</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td><i>tab</i></td>
|
|
<td>Moves focus to the cascadeselect element.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>space</i></td>
|
|
<td>Opens the popup and moves visual focus to the selected option, if there is none then first option receives the focus.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>enter</i></td>
|
|
<td>Opens the popup and moves visual focus to the selected option, if there is none then first option receives the focus.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>down arrow</i></td>
|
|
<td>Opens the popup and moves visual focus to the selected option, if there is none then first option receives the focus.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>up arrow</i></td>
|
|
<td>Opens the popup and moves visual focus to the selected option, if there is none then last option receives the focus.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>any printable character</i></td>
|
|
<td>Opens the popup and moves focus to the option whose label starts with the characters being typed, if there is none then first option receives the focus.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<h6>Popup Keyboard Support</h6>
|
|
<div class="doc-tablewrapper">
|
|
<table class="doc-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Key</th>
|
|
<th>Function</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td><i>tab</i></td>
|
|
<td>Hides the popup and moves focus to the next tabbable element. If there is none, the focusable option is selected and the overlay is closed then moves focus to next element in page.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>shift</i> + <i>tab</i></td>
|
|
<td>Hides the popup and moves focus to the previous tabbable element.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>enter</i></td>
|
|
<td>Selects the focused option and closes the popup.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>space</i></td>
|
|
<td>Selects the focused option and closes the popup.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>escape</i></td>
|
|
<td>Closes the popup, moves focus to the cascadeselect element.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>down arrow</i></td>
|
|
<td>Moves focus to the next option.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>up arrow</i></td>
|
|
<td>Moves focus to the previous option.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>alt</i> + <i>up arrow</i></td>
|
|
<td>Selects the focused option and closes the popup, then moves focus to the cascadeselect element.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>right arrow</i></td>
|
|
<td>If option is closed, opens the option otherwise moves focus to the first child option.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>left arrow</i></td>
|
|
<td>If option is open, closes the option otherwise moves focus to the parent option.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>home</i></td>
|
|
<td>Moves input cursor at the end, if not then moves focus to the first option.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>end</i></td>
|
|
<td>Moves input cursor at the beginning, if not then moves focus to the last option.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><i>any printable character</i></td>
|
|
<td>Moves focus to the option whose label starts with the characters being typed.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<h5>Dependencies</h5>
|
|
<p>None.</p>
|
|
</AppDoc>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
sources: {
|
|
'options-api': {
|
|
tabName: 'Options API Source',
|
|
content: `
|
|
<template>
|
|
<div>
|
|
<h5>Basic</h5>
|
|
<CascadeSelect v-model="selectedCity1" :options="countries" optionLabel="cname" optionGroupLabel="name"
|
|
:optionGroupChildren="['states', 'cities']" style="minWidth: 14rem" placeholder="Select a City" />
|
|
|
|
<h5>Templating</h5>
|
|
<CascadeSelect v-model="selectedCity2" :options="countries" optionLabel="cname" optionGroupLabel="name"
|
|
:optionGroupChildren="['states', 'cities']" style="minWidth: 14rem" placeholder="Select a City">
|
|
<template #option="slotProps">
|
|
<div class="country-item">
|
|
<img src="https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png" v-if="slotProps.option.states" />
|
|
<i class="pi pi-compass mr-2" v-if="slotProps.option.cities"></i>
|
|
<i class="pi pi-map-marker mr-2" v-if="slotProps.option.cname"></i>
|
|
<span>{{slotProps.option.cname || slotProps.option.name}}</span>
|
|
</div>
|
|
</template>
|
|
</CascadeSelect>
|
|
|
|
<h5>Loading State</h5>
|
|
<CascadeSelect placeholder="Loading..." loading style="minWidth: 14rem"></CascadeSelect>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
selectedCity1: null,
|
|
selectedCity2: null,
|
|
countries: [
|
|
{
|
|
name: 'Australia',
|
|
code: 'AU',
|
|
states: [
|
|
{
|
|
name: 'New South Wales',
|
|
cities: [
|
|
{cname: 'Sydney', code: 'A-SY'},
|
|
{cname: 'Newcastle', code: 'A-NE'},
|
|
{cname: 'Wollongong', code: 'A-WO'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Queensland',
|
|
cities: [
|
|
{cname: 'Brisbane', code: 'A-BR'},
|
|
{cname: 'Townsville', code: 'A-TO'}
|
|
]
|
|
},
|
|
|
|
]
|
|
},
|
|
{
|
|
name: 'Canada',
|
|
code: 'CA',
|
|
states: [
|
|
{
|
|
name: 'Quebec',
|
|
cities: [
|
|
{cname: 'Montreal', code: 'C-MO'},
|
|
{cname: 'Quebec City', code: 'C-QU'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Ontario',
|
|
cities: [
|
|
{cname: 'Ottawa', code: 'C-OT'},
|
|
{cname: 'Toronto', code: 'C-TO'}
|
|
]
|
|
},
|
|
|
|
]
|
|
},
|
|
{
|
|
name: 'United States',
|
|
code: 'US',
|
|
states: [
|
|
{
|
|
name: 'California',
|
|
cities: [
|
|
{cname: 'Los Angeles', code: 'US-LA'},
|
|
{cname: 'San Diego', code: 'US-SD'},
|
|
{cname: 'San Francisco', code: 'US-SF'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Florida',
|
|
cities: [
|
|
{cname: 'Jacksonville', code: 'US-JA'},
|
|
{cname: 'Miami', code: 'US-MI'},
|
|
{cname: 'Tampa', code: 'US-TA'},
|
|
{cname: 'Orlando', code: 'US-OR'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Texas',
|
|
cities: [
|
|
{cname: 'Austin', code: 'US-AU'},
|
|
{cname: 'Dallas', code: 'US-DA'},
|
|
{cname: 'Houston', code: 'US-HO'}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
<\\/script>
|
|
|
|
<style>
|
|
img {
|
|
width: 18px;
|
|
margin-right: 0.5rem;
|
|
}
|
|
</style>
|
|
`
|
|
},
|
|
'composition-api': {
|
|
tabName: 'Composition API Source',
|
|
content: `
|
|
<template>
|
|
<div>
|
|
<h5>Basic</h5>
|
|
<CascadeSelect v-model="selectedCity1" :options="countries" optionLabel="cname" optionGroupLabel="name"
|
|
:optionGroupChildren="['states', 'cities']" style="minWidth: 14rem" placeholder="Select a City" />
|
|
|
|
<h5>Templating</h5>
|
|
<CascadeSelect v-model="selectedCity2" :options="countries" optionLabel="cname" optionGroupLabel="name"
|
|
:optionGroupChildren="['states', 'cities']" style="minWidth: 14rem" placeholder="Select a City">
|
|
<template #option="slotProps">
|
|
<div class="country-item">
|
|
<img src="https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png" v-if="slotProps.option.states" />
|
|
<i class="pi pi-compass mr-2" v-if="slotProps.option.cities"></i>
|
|
<i class="pi pi-map-marker mr-2" v-if="slotProps.option.cname"></i>
|
|
<span>{{slotProps.option.cname || slotProps.option.name}}</span>
|
|
</div>
|
|
</template>
|
|
</CascadeSelect>
|
|
|
|
<h5>Loading State</h5>
|
|
<CascadeSelect placeholder="Loading..." loading style="minWidth: 14rem"></CascadeSelect>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { ref } from 'vue';
|
|
|
|
export default {
|
|
setup() {
|
|
const selectedCity1 = ref();
|
|
const selectedCity2 = ref();
|
|
const countries = ref([
|
|
{
|
|
name: 'Australia',
|
|
code: 'AU',
|
|
states: [
|
|
{
|
|
name: 'New South Wales',
|
|
cities: [
|
|
{cname: 'Sydney', code: 'A-SY'},
|
|
{cname: 'Newcastle', code: 'A-NE'},
|
|
{cname: 'Wollongong', code: 'A-WO'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Queensland',
|
|
cities: [
|
|
{cname: 'Brisbane', code: 'A-BR'},
|
|
{cname: 'Townsville', code: 'A-TO'}
|
|
]
|
|
},
|
|
|
|
]
|
|
},
|
|
{
|
|
name: 'Canada',
|
|
code: 'CA',
|
|
states: [
|
|
{
|
|
name: 'Quebec',
|
|
cities: [
|
|
{cname: 'Montreal', code: 'C-MO'},
|
|
{cname: 'Quebec City', code: 'C-QU'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Ontario',
|
|
cities: [
|
|
{cname: 'Ottawa', code: 'C-OT'},
|
|
{cname: 'Toronto', code: 'C-TO'}
|
|
]
|
|
},
|
|
|
|
]
|
|
},
|
|
{
|
|
name: 'United States',
|
|
code: 'US',
|
|
states: [
|
|
{
|
|
name: 'California',
|
|
cities: [
|
|
{cname: 'Los Angeles', code: 'US-LA'},
|
|
{cname: 'San Diego', code: 'US-SD'},
|
|
{cname: 'San Francisco', code: 'US-SF'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Florida',
|
|
cities: [
|
|
{cname: 'Jacksonville', code: 'US-JA'},
|
|
{cname: 'Miami', code: 'US-MI'},
|
|
{cname: 'Tampa', code: 'US-TA'},
|
|
{cname: 'Orlando', code: 'US-OR'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Texas',
|
|
cities: [
|
|
{cname: 'Austin', code: 'US-AU'},
|
|
{cname: 'Dallas', code: 'US-DA'},
|
|
{cname: 'Houston', code: 'US-HO'}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]);
|
|
|
|
return { selectedCity1, selectedCity2, countries }
|
|
}
|
|
}
|
|
<\\/script>
|
|
|
|
<style>
|
|
img {
|
|
width: 18px;
|
|
margin-right: 0.5rem;
|
|
}
|
|
</style>
|
|
`
|
|
},
|
|
'browser-source': {
|
|
tabName: 'Browser Source',
|
|
imports: `<script src="https://unpkg.com/primevue@^3/cascadeselect/cascadeselect.min.js"><\\/script>`,
|
|
content: `
|
|
<div id="app">
|
|
<h5>Basic</h5>
|
|
<p-cascadeselect v-model="selectedCity1" :options="countries" option-label="cname" option-group-label="name"
|
|
:option-group-children="['states', 'cities']" style="minWidth: 14rem" placeholder="Select a City"></p-cascadeselect>
|
|
|
|
<h5>Templating</h5>
|
|
<p-cascadeselect v-model="selectedCity2" :options="countries" option-label="cname" option-group-label="name"
|
|
:option-group-children="['states', 'cities']" style="minWidth: 14rem" placeholder="Select a City">
|
|
<template #option="slotProps">
|
|
<div class="country-item">
|
|
<img src="https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png" v-if="slotProps.option.states" />
|
|
<i class="pi pi-compass mr-2" v-if="slotProps.option.cities"></i>
|
|
<i class="pi pi-map-marker mr-2" v-if="slotProps.option.cname"></i>
|
|
<span>{{slotProps.option.cname || slotProps.option.name}}</span>
|
|
</div>
|
|
</template>
|
|
</p-cascadeselect>
|
|
|
|
<h5>Loading State</h5>
|
|
<p-cascadeselect placeholder="Loading..." loading style="minWidth: 14rem"></p-cascadeselect>
|
|
</div>
|
|
|
|
<script type="module">
|
|
const { createApp, ref } = Vue;
|
|
|
|
const App = {
|
|
setup() {
|
|
const selectedCity1 = ref();
|
|
const selectedCity2 = ref();
|
|
const countries = ref([
|
|
{
|
|
name: 'Australia',
|
|
code: 'AU',
|
|
states: [
|
|
{
|
|
name: 'New South Wales',
|
|
cities: [
|
|
{cname: 'Sydney', code: 'A-SY'},
|
|
{cname: 'Newcastle', code: 'A-NE'},
|
|
{cname: 'Wollongong', code: 'A-WO'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Queensland',
|
|
cities: [
|
|
{cname: 'Brisbane', code: 'A-BR'},
|
|
{cname: 'Townsville', code: 'A-TO'}
|
|
]
|
|
},
|
|
|
|
]
|
|
},
|
|
{
|
|
name: 'Canada',
|
|
code: 'CA',
|
|
states: [
|
|
{
|
|
name: 'Quebec',
|
|
cities: [
|
|
{cname: 'Montreal', code: 'C-MO'},
|
|
{cname: 'Quebec City', code: 'C-QU'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Ontario',
|
|
cities: [
|
|
{cname: 'Ottawa', code: 'C-OT'},
|
|
{cname: 'Toronto', code: 'C-TO'}
|
|
]
|
|
},
|
|
|
|
]
|
|
},
|
|
{
|
|
name: 'United States',
|
|
code: 'US',
|
|
states: [
|
|
{
|
|
name: 'California',
|
|
cities: [
|
|
{cname: 'Los Angeles', code: 'US-LA'},
|
|
{cname: 'San Diego', code: 'US-SD'},
|
|
{cname: 'San Francisco', code: 'US-SF'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Florida',
|
|
cities: [
|
|
{cname: 'Jacksonville', code: 'US-JA'},
|
|
{cname: 'Miami', code: 'US-MI'},
|
|
{cname: 'Tampa', code: 'US-TA'},
|
|
{cname: 'Orlando', code: 'US-OR'}
|
|
]
|
|
},
|
|
{
|
|
name: 'Texas',
|
|
cities: [
|
|
{cname: 'Austin', code: 'US-AU'},
|
|
{cname: 'Dallas', code: 'US-DA'},
|
|
{cname: 'Houston', code: 'US-HO'}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]);
|
|
|
|
return { selectedCity1, selectedCity2, countries }
|
|
},
|
|
components: {
|
|
"p-cascadeselect": primevue.cascadeselect
|
|
}
|
|
};
|
|
|
|
createApp(App)
|
|
.use(primevue.config.default)
|
|
.mount("#app");
|
|
<\\/script>
|
|
|
|
<style>
|
|
img {
|
|
width: 18px;
|
|
margin-right: 0.5rem;
|
|
}
|
|
</style>
|
|
`
|
|
}
|
|
}
|
|
};
|
|
}
|
|
};
|
|
</script>
|