arco-design-vue
arco-design-vue copied to clipboard
[Feature Request] `Tag`增加`before-close`方法
- [x] I'm sure this does not appear in the issue list of the repository
RT,有时候close前需要用户确认,可能确认后不需要close。
@llk2yq 你好,tag内部的实现,close 事件会触发 visible = false 会使用 tag 隐藏,这里可以直接设置 visible = true 强制显示
参考:https://stackblitz.com/edit/angular-hblutj?file=src%2FApp.vue
<template>
<a-space>
<template v-for="item in tags" :key="item">
<a-tag @close="handleClose(item)" visible closable>{{ item }}</a-tag>
</template>
</a-space>
</template>
<script>
import { defineComponent } from 'vue';
export default defineComponent({
setup() {
const tags = ['apple', 'banana', 'pear', 'origin'];
const handleClose = (item) => {
// 这里可以 对源数据做修改(拦截或行为确认操作)
console.log(item);
};
return {
tags,
handleClose,
};
},
});
</script>
@hehehai 感谢你的方法。
这样做是否当用户确实需要关闭tag时,需要手动去维护visible 的值?
我觉得可能还是有回调会方便一些。有点类似Modal的关闭逻辑,需要二次确认才是真的关闭。
@llk2yq 嗯,实际上面的情况不需要去维护 visible了,通常 close 事件会触发源数据的改变,例如 tags item 的减少。
这个 feat 需要 @flsion 看下
@llk2yq 类似 on-before-close 的事件在关闭弹出型组件上会有,这个更像是受控类的属性,增加类似 change 事件更统一些
@flsion 这里感觉还是 onBeforeClose: () => boolean | Promise<boolean> 这样合适些
- change 事件应该是 visible 的处理(beforeChange 也一样)
- close 仅是 visible=false 的处理(beforeClose 也一样)
🤔 对于 tag 来说,关心如何去处理它是否要显示,应该没必要(通常添加tag就好,不需要去为tag绑定一个 visible, 具体由组件内部维护)
你觉得呢?