(component): 新增CheckBoxGroup disabled属性

This commit is contained in:
0o张不歪o0
2022-07-13 16:12:29 +08:00
parent 29afa1114f
commit eaa66f6d5a
4 changed files with 27 additions and 4 deletions

View File

@@ -27,6 +27,7 @@ const props = withDefaults(defineProps<LayCheckboxProps>(), {
});
const checkboxGroup: any = inject("checkboxGroup", {});
const checkboxGroupDisabled: boolean = inject("checkboxGroupDisabled", false);
const isGroup = computed(() => {
return (
@@ -92,7 +93,7 @@ const setArrayModelValue = function (checked: any) {
};
const handleClick = function () {
if (!props.disabled) {
if (!props.disabled&&!checkboxGroupDisabled) {
isChecked.value = !isChecked.value;
}
};
@@ -104,7 +105,7 @@ const handleClick = function () {
<div
class="layui-unselect layui-form-checkbox"
:class="{
'layui-checkbox-disabled layui-disabled': disabled,
'layui-checkbox-disabled layui-disabled': disabled||checkboxGroupDisabled,
'layui-form-checked': isChecked,
}"
:lay-skin="skin"

View File

@@ -10,10 +10,12 @@ import { Recordable } from "../../types";
export interface LayCheckboxGroupProps {
modelValue?: Recordable[];
disabled?:boolean
}
const props = withDefaults(defineProps<LayCheckboxGroupProps>(), {
modelValue: () => [],
disabled:false
});
const emit = defineEmits(["update:modelValue", "change"]);
@@ -21,7 +23,7 @@ const emit = defineEmits(["update:modelValue", "change"]);
const modelValue = ref(props.modelValue);
provide("checkboxGroup", { name: "LayCheckboxGroup", modelValue: modelValue });
provide("checkboxGroupDisabled",props.disabled)
watch(
() => modelValue,
(val) => {
@@ -35,10 +37,11 @@ watch(
() => props.modelValue,
(val) => (modelValue.value = val)
);
</script>
<template>
<div class="layui-checkbox-group">
<div class="layui-checkbox-group" :class="{'layui-checkbox-group-disabled':disabled}">
<slot></slot>
</div>
</template>