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 }]" @click="onClick">
|
|
|
|
<div class="p-hidden-accessible">
|
|
|
|
<input ref="input" type="checkbox" :checked="checked" :disabled="$attrs.disabled" :tabindex="$attrs.disabled ? null : '0'" :aria-label="checkboxAriaLabel" @focus="onFocus($event)" @blur="onBlur($event)" @keydown="onKeydown" />
|
|
|
|
</div>
|
|
|
|
<div ref="box" :class="['p-checkbox-box p-component', { 'p-highlight': checked, 'p-disabled': $attrs.disabled, 'p-focus': focused }]">
|
2023-04-18 07:35:20 +00:00
|
|
|
<component v-if="rowCheckboxIconTemplate" :is="rowCheckboxIconTemplate" :checked="checked" class="p-checkbox-icon" />
|
|
|
|
<CheckIcon v-else class="p-checkbox-icon" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-04-13 14:42:33 +00:00
|
|
|
import CheckIcon from 'primevue/icon/check';
|
2022-12-08 11:04:25 +00:00
|
|
|
import { DomHandler } from 'primevue/utils';
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
export default {
|
|
|
|
name: 'RowCheckbox',
|
|
|
|
emits: ['change'],
|
|
|
|
props: {
|
2022-09-14 11:26:01 +00:00
|
|
|
value: null,
|
2023-04-13 14:42:33 +00:00
|
|
|
checked: null,
|
|
|
|
rowCheckboxIconTemplate: {
|
2023-04-13 18:05:42 +00:00
|
|
|
type: Function,
|
2023-04-13 14:42:33 +00:00
|
|
|
default: null
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
focused: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onClick(event) {
|
|
|
|
if (!this.$attrs.disabled) {
|
|
|
|
this.$emit('change', {
|
|
|
|
originalEvent: event,
|
|
|
|
data: this.value
|
|
|
|
});
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
DomHandler.focus(this.$refs.input);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
event.preventDefault();
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onFocus() {
|
|
|
|
this.focused = true;
|
|
|
|
},
|
|
|
|
onBlur() {
|
|
|
|
this.focused = false;
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
onKeydown(event) {
|
|
|
|
switch (event.code) {
|
|
|
|
case 'Space': {
|
|
|
|
this.onClick(event);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
checkboxAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? (this.checked ? this.$primevue.config.locale.aria.selectRow : this.$primevue.config.locale.aria.unselectRow) : undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2023-04-13 14:42:33 +00:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
CheckIcon: CheckIcon
|
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>
|