Fix #297 - ToggleButton refactor
parent
18d21ffbce
commit
cbb45c3d80
|
@ -6,14 +6,7 @@ export declare class ToggleButton extends Vue {
|
||||||
offIcon?: string;
|
offIcon?: string;
|
||||||
onLabel?: string;
|
onLabel?: string;
|
||||||
offLabel?: string;
|
offLabel?: string;
|
||||||
inputId?: string;
|
|
||||||
name?: string;
|
|
||||||
iconPos?: string;
|
iconPos?: string;
|
||||||
disabled?: boolean;
|
|
||||||
ariaLabelledBy?: string;
|
ariaLabelledBy?: string;
|
||||||
$emit(eventName: 'click', event: Event): this;
|
$emit(eventName: string, event: Event): this;
|
||||||
$emit(eventName: 'input', value: any): this;
|
|
||||||
$emit(eventName: 'change', event: Event): this;
|
|
||||||
$emit(eventName: 'focus', event: Event): this;
|
|
||||||
$emit(eventName: 'blur', event: Event): this;
|
|
||||||
}
|
}
|
|
@ -1,9 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<div :class="buttonClass" @click="onClick($event)">
|
<div :class="buttonClass" @click="onClick($event)" role="checkbox" :aria-labelledby="ariaLabelledBy" :aria-checked="value" :tabindex="$attrs.disabled ? null : '0'">
|
||||||
<div class="p-hidden-accessible">
|
|
||||||
<input ref="input" type="checkbox" :id="inputId" :name="name" :checked="value" :disabled="disabled"
|
|
||||||
@focus="onFocus($event)" @blur="onBlur($event)" @keydown.enter.prevent="onClick($event)" role="button" :aria-pressed="value" :aria-labelledby="ariaLabelledBy">
|
|
||||||
</div>
|
|
||||||
<span v-if="hasIcon" :class="iconClass"></span>
|
<span v-if="hasIcon" :class="iconClass"></span>
|
||||||
<span class="p-button-text p-unselectable-text p-c">{{label}}</span>
|
<span class="p-button-text p-unselectable-text p-c">{{label}}</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -17,36 +13,19 @@ export default {
|
||||||
offIcon: String,
|
offIcon: String,
|
||||||
onLabel: String,
|
onLabel: String,
|
||||||
offLabel: String,
|
offLabel: String,
|
||||||
inputId: String,
|
|
||||||
name: String,
|
|
||||||
iconPos: {
|
iconPos: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'left'
|
default: 'left'
|
||||||
},
|
},
|
||||||
disabled: Boolean,
|
|
||||||
ariaLabelledBy: String
|
ariaLabelledBy: String
|
||||||
},
|
},
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
focused: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
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.$emit('change', event);
|
this.$emit('change', event);
|
||||||
this.$refs.input.focus();
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
onFocus(event) {
|
|
||||||
this.focused = true;
|
|
||||||
this.$emit('focus', event);
|
|
||||||
},
|
|
||||||
onBlur() {
|
|
||||||
this.focused = false;
|
|
||||||
this.$emit('blur', event);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -54,8 +33,7 @@ export default {
|
||||||
return {
|
return {
|
||||||
'p-button p-togglebutton p-component': true,
|
'p-button p-togglebutton p-component': true,
|
||||||
'p-button-icon-only': this.hasIcon && !this.hasLabel,
|
'p-button-icon-only': this.hasIcon && !this.hasLabel,
|
||||||
'p-disabled': this.disabled,
|
'p-disabled': this.$attrs.disabled,
|
||||||
'p-focus': this.focused,
|
|
||||||
'p-highlight': this.value === true
|
'p-highlight': this.value === true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -73,30 +73,12 @@ export default {
|
||||||
<td>no</td>
|
<td>no</td>
|
||||||
<td>Label for the off state.</td>
|
<td>Label for the off state.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td>inputId</td>
|
|
||||||
<td>string</td>
|
|
||||||
<td>null</td>
|
|
||||||
<td>Identifier of the input element.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>name</td>
|
|
||||||
<td>string</td>
|
|
||||||
<td>null</td>
|
|
||||||
<td>Name of the input element.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>iconPos</td>
|
<td>iconPos</td>
|
||||||
<td>string</td>
|
<td>string</td>
|
||||||
<td>left</td>
|
<td>left</td>
|
||||||
<td>Position of the icon, valid values are "left" and "right".</td>
|
<td>Position of the icon, valid values are "left" and "right".</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td>disabled</td>
|
|
||||||
<td>boolean</td>
|
|
||||||
<td>null</td>
|
|
||||||
<td>When present, it specifies that the element should be disabled.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>ariaLabelledBy</td>
|
<td>ariaLabelledBy</td>
|
||||||
<td>string</td>
|
<td>string</td>
|
||||||
|
|
Loading…
Reference in New Issue