Refactor RadioButton

pull/12/head
cagataycivici 2019-05-22 19:26:55 +03:00
parent 491188eb57
commit baa322b16e
2 changed files with 6 additions and 47 deletions

View File

@ -1,10 +1,9 @@
<template> <template>
<div class="p-radiobutton p-component" @click="onClick($event)"> <div class="p-radiobutton p-component" @click="onClick($event)">
<div class="p-hidden-accessible"> <div class="p-hidden-accessible">
<input ref="input" :id="inputId" type="radio" :name="name" :checked="checked" :disabled="disabled" @focus="onFocus($event)" @blur="onBlur($event)" <input ref="input" type="radio" :checked="checked" :value="value" v-bind="$attrs" @focus="onFocus($event)" @blur="onBlur($event)">
:autocomplete="autocomplete" :autofocus="autofocus">
</div> </div>
<div ref="box" :class="['p-radiobutton-box p-component', {'p-highlight': checked, 'p-disabled': disabled, 'p-focus': focused}]"> <div ref="box" :class="['p-radiobutton-box p-component', {'p-highlight': checked, 'p-disabled': $attrs.disabled, 'p-focus': focused}]">
<span :class="['p-radiobutton-icon p-c', {'pi pi-circle-on': checked}]"></span> <span :class="['p-radiobutton-icon p-c', {'pi pi-circle-on': checked}]"></span>
</div> </div>
</div> </div>
@ -15,13 +14,8 @@
export default { export default {
props: { props: {
inputId: String,
name: String,
value: null, value: null,
disabled: Boolean, modelValue: null
modelValue: null,
autofocus: Boolean,
autocomplete: String
}, },
model: { model: {
prop: 'modelValue', prop: 'modelValue',
@ -34,7 +28,7 @@
}, },
methods: { methods: {
onClick(event) { onClick(event) {
if (!this.disabled) { if (!this.$attrs.disabled) {
this.$emit('click', event); this.$emit('click', event);
this.$emit('input', this.value); this.$emit('input', this.value);
this.$refs.input.focus(); this.$refs.input.focus();

View File

@ -34,6 +34,7 @@ export default {
</CodeHighlight> </CodeHighlight>
<h3>Properties</h3> <h3>Properties</h3>
<p>Any valid attribute such as name and autofocus are passed to the underlying input element. Following is the additional property to configure the component.</p>
<div class="doc-tablewrapper"> <div class="doc-tablewrapper">
<table class="doc-table"> <table class="doc-table">
<thead> <thead>
@ -45,47 +46,11 @@ export default {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr>
<td>inputId</td>
<td>string</td>
<td>null</td>
<td>Unique identifier of the inner native radiobutton.</td>
</tr>
<tr>
<td>name</td>
<td>string</td>
<td>null</td>
<td>Name of the checkbox element .</td>
</tr>
<tr> <tr>
<td>value</td> <td>value</td>
<td>any</td>
<td>null</td>
<td>Value of the radiobutton.</td>
</tr>
<tr>
<td>disabled</td>
<td>boolean</td>
<td>false</td>
<td>When present, it specifies that the element value cannot be altered.</td>
</tr>
<tr>
<td>modelValue</td>
<td>any</td>
<td>null</td>
<td>Value of the checkbox.</td>
</tr>
<tr>
<td>autofocus</td>
<td>boolean</td> <td>boolean</td>
<td>null</td> <td>null</td>
<td>When present, it specifies that the element should automatically get focus when the page loads.</td> <td>Value of the component.</td>
</tr>
<tr>
<td>autocomplete</td>
<td>string</td>
<td>null</td>
<td>Whether or not an the element should have autocomplete enabled.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>