Accessibility for Checkbox

pull/2760/head
mertsincan 2022-07-04 14:03:27 +01:00
parent 99876ded02
commit 6e87fe23c8
1 changed files with 19 additions and 14 deletions

View File

@ -1,9 +1,9 @@
<template> <template>
<div :class="containerClass" @click="onClick($event)" :style="style"> <div :class="containerClass" @click="onClick($event)">
<div class="p-hidden-accessible"> <div class="p-hidden-accessible">
<input ref="input" type="checkbox" :checked="checked" :value="value" v-bind="$attrs" @focus="onFocus" @blur="onBlur"> <input :id="inputId" ref="input" type="checkbox" :value="value" :checked="checked" :disabled="disabled" @focus="onFocus($event)" @blur="onBlur($event)" v-bind="inputProps">
</div> </div>
<div ref="box" :class="['p-checkbox-box', {'p-highlight': checked, 'p-disabled': $attrs.disabled, 'p-focus': focused}]"> <div ref="box" :class="['p-checkbox-box', {'p-highlight': checked, 'p-disabled': disabled, 'p-focus': focused}]">
<span :class="['p-checkbox-icon', {'pi pi-check': checked}]"></span> <span :class="['p-checkbox-icon', {'pi pi-check': checked}]"></span>
</div> </div>
</div> </div>
@ -14,14 +14,11 @@ import {ObjectUtils} from 'primevue/utils';
export default { export default {
name: 'Checkbox', name: 'Checkbox',
inheritAttrs: false, emits: ['click', 'update:modelValue', 'change', 'input', 'focus', 'blur'],
emits: ['click', 'update:modelValue', 'change', 'input'],
props: { props: {
value: null, value: null,
modelValue: null, modelValue: null,
binary: Boolean, binary: Boolean,
class: null,
style: null,
trueValue: { trueValue: {
type: null, type: null,
default: true default: true
@ -29,16 +26,22 @@ export default {
falseValue: { falseValue: {
type: null, type: null,
default: false default: false
} },
disabled: {
type: Boolean,
default: false
},
inputId: null,
inputProps: null
}, },
data() { data() {
return { return {
focused: false focused: false
}; }
}, },
methods: { methods: {
onClick(event) { onClick(event) {
if (!this.$attrs.disabled) { if (!this.disabled) {
let newModelValue; let newModelValue;
if (this.binary) { if (this.binary) {
@ -58,11 +61,13 @@ export default {
this.$refs.input.focus(); this.$refs.input.focus();
} }
}, },
onFocus() { onFocus(event) {
this.focused = true; this.focused = true;
this.$emit('focus', event);
}, },
onBlur() { onBlur(event) {
this.focused = false; this.focused = false;
this.$emit('blur', event);
} }
}, },
computed: { computed: {
@ -71,9 +76,9 @@ export default {
}, },
containerClass() { containerClass() {
return [ return [
'p-checkbox p-component', this.class, { 'p-checkbox p-component', {
'p-checkbox-checked': this.checked, 'p-checkbox-checked': this.checked,
'p-checkbox-disabled': this.$attrs.disabled, 'p-checkbox-disabled': this.disabled,
'p-checkbox-focused': this.focused 'p-checkbox-focused': this.focused
}]; }];
} }