2022-09-09 20:41:18 +00:00
|
|
|
<template>
|
2022-12-22 08:40:59 +00:00
|
|
|
<AppDoc name="RadioButtonDemo" :sources="sources">
|
2022-12-20 17:28:51 +00:00
|
|
|
<h5>Import via Module</h5>
|
|
|
|
<pre v-code.script><code>
|
2022-09-09 20:41:18 +00:00
|
|
|
import RadioButton from 'primevue/radiobutton';
|
|
|
|
|
|
|
|
</code></pre>
|
|
|
|
|
2022-12-20 17:28:51 +00:00
|
|
|
<h5>Import via CDN</h5>
|
|
|
|
<pre v-code><code>
|
2022-09-09 20:41:18 +00:00
|
|
|
<script src="https://unpkg.com/primevue@^3/core/core.min.js"></script>
|
|
|
|
<script src="https://unpkg.com/primevue@^3/radiobutton/radiobutton.min.js"></script>
|
|
|
|
|
|
|
|
</code></pre>
|
|
|
|
|
2022-12-20 17:28:51 +00:00
|
|
|
<h5>Getting Started</h5>
|
|
|
|
<p>Two-way value binding is defined using the standard v-model directive.</p>
|
|
|
|
<pre v-code><code>
|
2022-09-09 20:41:18 +00:00
|
|
|
<RadioButton name="city" value="Chicago" v-model="city" />
|
|
|
|
<RadioButton name="city" value="Los Angeles" v-model="city" />
|
|
|
|
|
|
|
|
</code></pre>
|
2022-12-20 17:28:51 +00:00
|
|
|
<pre v-code.script><code>
|
2022-09-09 20:41:18 +00:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
city: null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</code></pre>
|
2022-12-20 17:28:51 +00:00
|
|
|
<p>As model is two-way binding enabled, giving a default value to the model is enough to display a radio button as checked by default.</p>
|
|
|
|
<pre v-code.script><code>
|
2022-09-09 20:41:18 +00:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
city: 'Chicago'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</code></pre>
|
|
|
|
|
2022-12-20 17:28:51 +00:00
|
|
|
<h5>Properties</h5>
|
|
|
|
<p>Any valid attribute is passed to the root element implicitly, extended properties are as follows;</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>value</td>
|
|
|
|
<td>any</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Value of the checkbox.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>modelValue</td>
|
|
|
|
<td>any</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Value binding of the checkbox.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>name</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Name of the input element.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>disabled</td>
|
|
|
|
<td>boolean</td>
|
|
|
|
<td>false</td>
|
|
|
|
<td>When present, it specifies that the element should be disabled.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>inputId</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Style class of the component 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>inputStyle</td>
|
|
|
|
<td>any</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Inline style 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 to the focusable input element inside the component.</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>
|
|
|
|
<p>Any valid event such as focus and blur.</p>
|
|
|
|
<div class="doc-tablewrapper">
|
|
|
|
<table class="doc-table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Parameters</th>
|
|
|
|
<th>Description</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>click</td>
|
|
|
|
<td>-</td>
|
|
|
|
<td>Callback to invoke on radio button click.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>change</td>
|
|
|
|
<td>-</td>
|
|
|
|
<td>Callback to invoke on radio button value change.</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-radiobutton</td>
|
|
|
|
<td>Container element</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>p-radiobutton-box</td>
|
|
|
|
<td>Container of icon.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>p-radiobutton-icon</td>
|
|
|
|
<td>Icon element.</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<h5>Accessibility</h5>
|
|
|
|
<h6>Screen Reader</h6>
|
|
|
|
<p>
|
|
|
|
RadioButton component uses a hidden native radio button element internally that is only visible to screen readers. Value to describe the component can either be provided via <i>label</i> tag combined with <i>id</i> prop or using
|
|
|
|
<i>aria-labelledby</i>, <i>aria-label</i> props.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<pre v-code><code>
|
2022-09-09 20:41:18 +00:00
|
|
|
<label for="rb1">One</label>
|
|
|
|
<RadioButton inputId="rb1" />
|
|
|
|
|
|
|
|
<span id="rb2">Two</span>
|
|
|
|
<RadioButton aria-labelledby="rb2" />
|
|
|
|
|
|
|
|
<RadioButton aria-label="Three" />
|
|
|
|
|
|
|
|
</code></pre>
|
|
|
|
|
2022-12-20 17:28:51 +00:00
|
|
|
<h6>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 checked radio button, if there is none within the group then first radio button receives the focus.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<span class="inline-flex flex-column">
|
|
|
|
<i class="mb-1">left arrow</i>
|
|
|
|
<i>up arrow</i>
|
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
<td>Moves focus to the previous radio button, if there is none then last radio button receives the focus.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<span class="inline-flex flex-column">
|
|
|
|
<i class="mb-1">right arrow</i>
|
|
|
|
<i>down arrow</i>
|
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
<td>Moves focus to the next radio button, if there is none then first radio button receives the focus.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><i>space</i></td>
|
|
|
|
<td>If the focused radio button is unchecked, changes the state to checked.</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<h5>Dependencies</h5>
|
|
|
|
<p>None.</p>
|
|
|
|
</AppDoc>
|
2022-09-09 20:41:18 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
sources: {
|
|
|
|
'options-api': {
|
|
|
|
tabName: 'Options API Source',
|
|
|
|
content: `
|
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<h5>Basic</h5>
|
|
|
|
<div class="field-radiobutton">
|
|
|
|
<RadioButton inputId="city1" name="city" value="Chicago" v-model="city" />
|
|
|
|
<label for="city1">Chicago</label>
|
|
|
|
</div>
|
|
|
|
<div class="field-radiobutton">
|
|
|
|
<RadioButton inputId="city2" name="city" value="Los Angeles" v-model="city" />
|
|
|
|
<label for="city2">Los Angeles</label>
|
|
|
|
</div>
|
|
|
|
<div class="field-radiobutton">
|
|
|
|
<RadioButton inputId="city3" name="city" value="New York" v-model="city" />
|
|
|
|
<label for="city3">New York</label>
|
|
|
|
</div>
|
|
|
|
<div class="field-radiobutton">
|
|
|
|
<RadioButton inputId="city4" name="city" value="San Francisco" v-model="city" />
|
|
|
|
<label for="city4">San Francisco</label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<h5>Dynamic Values, Preselection, Value Binding and Disabled Option</h5>
|
|
|
|
<div v-for="category of categories" :key="category.key" class="field-radiobutton">
|
|
|
|
<RadioButton :inputId="category.key" name="category" :value="category.name" v-model="selectedCategory" :disabled="category.key === 'R'" />
|
|
|
|
<label :for="category.key">{{category.name}}</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
city: null,
|
|
|
|
categories: [
|
|
|
|
{name: 'Accounting', key: 'A'},
|
|
|
|
{name: 'Marketing', key: 'M'},
|
|
|
|
{name: 'Production', key: 'P'},
|
|
|
|
{name: 'Research', key: 'R'}
|
|
|
|
],
|
|
|
|
selectedCategory: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.selectedCategory = this.categories[1].name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
<\\/script>
|
|
|
|
`
|
|
|
|
},
|
|
|
|
'composition-api': {
|
|
|
|
tabName: 'Composition API Source',
|
|
|
|
content: `
|
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<h5>Basic</h5>
|
|
|
|
<div class="field-radiobutton">
|
|
|
|
<RadioButton inputId="city1" name="city" value="Chicago" v-model="city" />
|
|
|
|
<label for="city1">Chicago</label>
|
|
|
|
</div>
|
|
|
|
<div class="field-radiobutton">
|
|
|
|
<RadioButton inputId="city2" name="city" value="Los Angeles" v-model="city" />
|
|
|
|
<label for="city2">Los Angeles</label>
|
|
|
|
</div>
|
|
|
|
<div class="field-radiobutton">
|
|
|
|
<RadioButton inputId="city3" name="city" value="New York" v-model="city" />
|
|
|
|
<label for="city3">New York</label>
|
|
|
|
</div>
|
|
|
|
<div class="field-radiobutton">
|
|
|
|
<RadioButton inputId="city4" name="city" value="San Francisco" v-model="city" />
|
|
|
|
<label for="city4">San Francisco</label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<h5>Dynamic Values, Preselection, Value Binding and Disabled Option</h5>
|
|
|
|
<div v-for="category of categories" :key="category.key" class="field-radiobutton">
|
|
|
|
<RadioButton :inputId="category.key" name="category" :value="category.name" v-model="selectedCategory" :disabled="category.key === 'R'" />
|
|
|
|
<label :for="category.key">{{category.name}}</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { ref } from 'vue';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
setup() {
|
|
|
|
const city = ref();
|
|
|
|
const categories = ref([
|
|
|
|
{name: 'Accounting', key: 'A'},
|
|
|
|
{name: 'Marketing', key: 'M'},
|
|
|
|
{name: 'Production', key: 'P'},
|
|
|
|
{name: 'Research', key: 'R'}
|
|
|
|
]);
|
|
|
|
const selectedCategory = ref(categories.value[1].name);
|
|
|
|
|
|
|
|
return { city, categories, selectedCategory }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
<\\/script>
|
|
|
|
`
|
|
|
|
},
|
|
|
|
'browser-source': {
|
|
|
|
tabName: 'Browser Source',
|
|
|
|
imports: `<script src="https://unpkg.com/primevue@^3/radiobutton/radiobutton.min.js"><\\/script>`,
|
|
|
|
content: `<div id="app">
|
|
|
|
<h5>Basic</h5>
|
|
|
|
<div class="field-radiobutton">
|
|
|
|
<p-radiobutton inputId="city1" name="city" value="Chicago" v-model="city"></p-radiobutton>
|
|
|
|
<label for="city1">Chicago</label>
|
|
|
|
</div>
|
|
|
|
<div class="field-radiobutton">
|
|
|
|
<p-radiobutton inputId="city2" name="city" value="Los Angeles" v-model="city"></p-radiobutton>
|
|
|
|
<label for="city2">Los Angeles</label>
|
|
|
|
</div>
|
|
|
|
<div class="field-radiobutton">
|
|
|
|
<p-radiobutton inputId="city3" name="city" value="New York" v-model="city"></p-radiobutton>
|
|
|
|
<label for="city3">New York</label>
|
|
|
|
</div>
|
|
|
|
<div class="field-radiobutton">
|
|
|
|
<p-radiobutton inputId="city4" name="city" value="San Francisco" v-model="city"></p-radiobutton>
|
|
|
|
<label for="city4">San Francisco</label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<h5>Dynamic Values, Preselection, Value Binding and Disabled Option</h5>
|
|
|
|
<div v-for="category of categories" :key="category.key" class="field-radiobutton">
|
|
|
|
<p-radiobutton :inputId="category.key" name="category" :value="category.name" v-model="selectedCategory" :disabled="category.key === 'R'"></p-radiobutton>
|
|
|
|
<label :for="category.key">{{category.name}}</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script type="module">
|
|
|
|
const { createApp, ref } = Vue;
|
|
|
|
|
|
|
|
const App = {
|
|
|
|
setup() {
|
|
|
|
const city = ref();
|
|
|
|
const categories = ref([
|
|
|
|
{name: 'Accounting', key: 'A'},
|
|
|
|
{name: 'Marketing', key: 'M'},
|
|
|
|
{name: 'Production', key: 'P'},
|
|
|
|
{name: 'Research', key: 'R'}
|
|
|
|
]);
|
|
|
|
const selectedCategory = ref(categories.value[1].name);
|
|
|
|
|
|
|
|
return { city, categories, selectedCategory }
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
"p-radiobutton": primevue.radiobutton
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
createApp(App)
|
|
|
|
.use(primevue.config.default)
|
|
|
|
.mount("#app");
|
|
|
|
<\\/script>
|
|
|
|
`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|