2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2022-12-08 11:04:25 +00:00
|
|
|
<div :class="['p-checkbox p-component', { 'p-checkbox-focused': focused, 'p-disabled': disabled }]" @click="onClick" @keydown.space.prevent="onClick">
|
|
|
|
<div class="p-hidden-accessible">
|
|
|
|
<input ref="input" type="checkbox" :checked="checked" :disabled="disabled" :tabindex="disabled ? null : '0'" :aria-label="headerCheckboxAriaLabel" @focus="onFocus($event)" @blur="onBlur($event)" />
|
|
|
|
</div>
|
|
|
|
<div ref="box" :class="['p-checkbox-box p-component', { 'p-highlight': checked, 'p-disabled': disabled, 'p-focus': focused }]">
|
2022-09-14 11:26:01 +00:00
|
|
|
<span :class="['p-checkbox-icon', { 'pi pi-check': checked }]"></span>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-12-08 11:04:25 +00:00
|
|
|
import { DomHandler } from 'primevue/utils';
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
export default {
|
|
|
|
name: 'HeaderCheckbox',
|
|
|
|
emits: ['change'],
|
|
|
|
props: {
|
2022-12-08 11:04:25 +00:00
|
|
|
checked: null,
|
|
|
|
disabled: null
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
focused: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onClick(event) {
|
2022-12-08 11:04:25 +00:00
|
|
|
if (!this.disabled) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$emit('change', {
|
|
|
|
originalEvent: event,
|
|
|
|
checked: !this.checked
|
|
|
|
});
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
DomHandler.focus(this.$refs.input);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onFocus() {
|
|
|
|
this.focused = true;
|
|
|
|
},
|
|
|
|
onBlur() {
|
|
|
|
this.focused = false;
|
|
|
|
}
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
headerCheckboxAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? (this.checked ? this.$primevue.config.locale.aria.selectAll : this.$primevue.config.locale.aria.unselectAll) : undefined;
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|