✨(component): 新增CheckBoxGroup disabled属性
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user