🐛(component): [cascader] 修复 trigger
This commit is contained in:
parent
50e8e2a419
commit
dc52add9ee
@ -5,6 +5,7 @@
|
|||||||
>
|
>
|
||||||
<lay-dropdown
|
<lay-dropdown
|
||||||
ref="dropdownRef"
|
ref="dropdownRef"
|
||||||
|
:trigger="trigger"
|
||||||
:autoFitMinWidth="false"
|
:autoFitMinWidth="false"
|
||||||
:updateAtScroll="true"
|
:updateAtScroll="true"
|
||||||
:disabled="dropDownDisabled"
|
:disabled="dropDownDisabled"
|
||||||
@ -73,6 +74,9 @@ import LayInput from "../input/index.vue";
|
|||||||
import LayScroll from "../scroll/index.vue";
|
import LayScroll from "../scroll/index.vue";
|
||||||
import LayDropdown from "../dropdown/index.vue";
|
import LayDropdown from "../dropdown/index.vue";
|
||||||
import { ref, onMounted, watch, useSlots } from "vue";
|
import { ref, onMounted, watch, useSlots } from "vue";
|
||||||
|
|
||||||
|
export type DropdownTrigger = "click" | "hover" | "focus" | "contextMenu";
|
||||||
|
|
||||||
export interface LayCascaderProps {
|
export interface LayCascaderProps {
|
||||||
options?: Array<any> | null;
|
options?: Array<any> | null;
|
||||||
modelValue?: string;
|
modelValue?: string;
|
||||||
@ -82,6 +86,7 @@ export interface LayCascaderProps {
|
|||||||
replaceFields?: { label: string; value: string; children: string };
|
replaceFields?: { label: string; value: string; children: string };
|
||||||
allowClear?: boolean;
|
allowClear?: boolean;
|
||||||
size?: "lg" | "md" | "sm" | "xs";
|
size?: "lg" | "md" | "sm" | "xs";
|
||||||
|
trigger: DropdownTrigger | DropdownTrigger[]
|
||||||
}
|
}
|
||||||
const props = withDefaults(defineProps<LayCascaderProps>(), {
|
const props = withDefaults(defineProps<LayCascaderProps>(), {
|
||||||
options: null,
|
options: null,
|
||||||
@ -91,6 +96,7 @@ const props = withDefaults(defineProps<LayCascaderProps>(), {
|
|||||||
onlyLastLevel: false,
|
onlyLastLevel: false,
|
||||||
allowClear: false,
|
allowClear: false,
|
||||||
size: "md",
|
size: "md",
|
||||||
|
trigger: "click",
|
||||||
replaceFields: () => {
|
replaceFields: () => {
|
||||||
return {
|
return {
|
||||||
label: "label",
|
label: "label",
|
||||||
@ -112,9 +118,9 @@ watch(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
watch(
|
watch(
|
||||||
()=>props.modelValue,
|
() => props.modelValue,
|
||||||
()=>{
|
() => {
|
||||||
if(props.modelValue===null||props.modelValue===''){
|
if (props.modelValue === null || props.modelValue === "") {
|
||||||
onClear();
|
onClear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -274,7 +280,7 @@ const dropDownDisabled = ref(false);
|
|||||||
|
|
||||||
//清除事件
|
//清除事件
|
||||||
const onClear = () => {
|
const onClear = () => {
|
||||||
displayValue.value='';
|
displayValue.value = "";
|
||||||
dropDownDisabled.value = true;
|
dropDownDisabled.value = true;
|
||||||
let arr = JSON.parse(JSON.stringify(treeData.value));
|
let arr = JSON.parse(JSON.stringify(treeData.value));
|
||||||
for (let index = 0; index < arr.length; index++) {
|
for (let index = 0; index < arr.length; index++) {
|
||||||
|
@ -62,7 +62,12 @@ const tagData = useVModel(props, "modelValue", emit, {
|
|||||||
deep: true,
|
deep: true,
|
||||||
defaultValue: [] as TagData[],
|
defaultValue: [] as TagData[],
|
||||||
});
|
});
|
||||||
const tagProps = reactiveOmit(props.tagProps ?? {}, 'closable','size', 'disabled')
|
const tagProps = reactiveOmit(
|
||||||
|
props.tagProps ?? {},
|
||||||
|
"closable",
|
||||||
|
"size",
|
||||||
|
"disabled"
|
||||||
|
);
|
||||||
|
|
||||||
const computedTagData = computed(() => {
|
const computedTagData = computed(() => {
|
||||||
if (!tagData.value) return;
|
if (!tagData.value) return;
|
||||||
@ -199,7 +204,12 @@ defineExpose({
|
|||||||
v-for="(item, index) of computedTagData"
|
v-for="(item, index) of computedTagData"
|
||||||
:key="`${item}-${index}`"
|
:key="`${item}-${index}`"
|
||||||
>
|
>
|
||||||
<LayTag v-bind="tagProps" :closable="!readonly && !disabled" :size="size" @close="handleClose(index)">
|
<LayTag
|
||||||
|
v-bind="tagProps"
|
||||||
|
:closable="!readonly && !disabled"
|
||||||
|
:size="size"
|
||||||
|
@close="handleClose(index)"
|
||||||
|
>
|
||||||
{{ item }}
|
{{ item }}
|
||||||
</LayTag>
|
</LayTag>
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user