From 9c072f205550ae1dd6102077058eb217ff02cdce Mon Sep 17 00:00:00 2001
From: GaoNeng <31283122+GaoNeng-wWw@users.noreply.github.com>
Date: Thu, 27 Jun 2024 16:32:51 +0800
Subject: [PATCH] feat(tree-menu): clearable (#1672)
---
examples/sites/demos/apis/tree-menu.js | 11 +
.../tree-menu/clearable-composition-api.vue | 192 ++++++++++++++++++
.../demos/pc/app/tree-menu/clearable.spec.ts | 20 ++
.../demos/pc/app/tree-menu/clearable.vue | 182 +++++++++++++++++
.../pc/app/tree-menu/webdoc/tree-menu.js | 13 ++
packages/renderless/src/tree-menu/vue.ts | 3 +-
packages/renderless/types/tree-menu.type.ts | 3 +-
packages/vue/src/tree-menu/src/index.ts | 4 +
packages/vue/src/tree-menu/src/pc.vue | 5 +
9 files changed, 431 insertions(+), 2 deletions(-)
create mode 100644 examples/sites/demos/pc/app/tree-menu/clearable-composition-api.vue
create mode 100644 examples/sites/demos/pc/app/tree-menu/clearable.spec.ts
create mode 100644 examples/sites/demos/pc/app/tree-menu/clearable.vue
diff --git a/examples/sites/demos/apis/tree-menu.js b/examples/sites/demos/apis/tree-menu.js
index 3156c6841..ec0e59e7a 100644
--- a/examples/sites/demos/apis/tree-menu.js
+++ b/examples/sites/demos/apis/tree-menu.js
@@ -397,6 +397,17 @@ export default {
},
mode: ['pc'],
pcDemo: 'text-wrap'
+ },
+ {
+ name: 'clearable',
+ type: 'boolean',
+ defaultValue: 'false',
+ desc: {
+ 'zh-CN': '搜索框是否可清空',
+ 'en-US': 'Can the search box be cleared'
+ },
+ mode: ['pc'],
+ pcDemo: 'clearable'
}
],
events: [
diff --git a/examples/sites/demos/pc/app/tree-menu/clearable-composition-api.vue b/examples/sites/demos/pc/app/tree-menu/clearable-composition-api.vue
new file mode 100644
index 000000000..91c528468
--- /dev/null
+++ b/examples/sites/demos/pc/app/tree-menu/clearable-composition-api.vue
@@ -0,0 +1,192 @@
+
+
Event description
\nnode-click: Listen for events when a node is clicked.
\ncurrent-change: Listen for events where the currently selected node changes.
\nnode-expand: Listen for events that node expands.
\nnode-collapse: Listen for events when a node is folded up.
\ncheck-change: When checked, listen for events related to changes in checked nodes.
\nclearable
属性来标明是否允许显示搜索框清空按钮',
+ 'en-US':
+ 'Indicate whether to allow the search box clear button to be displayed by setting theclearable
property'
+ },
+ codeFiles: ['clearable.vue']
}
]
}
diff --git a/packages/renderless/src/tree-menu/vue.ts b/packages/renderless/src/tree-menu/vue.ts
index fb0db4574..eec8857dd 100644
--- a/packages/renderless/src/tree-menu/vue.ts
+++ b/packages/renderless/src/tree-menu/vue.ts
@@ -91,7 +91,8 @@ export const renderless = (
treeStyle: computed(() => api.computedTreeStyle()),
defaultExpandedKeys: computed(() =>
props.defaultExpandedKeys && props.defaultExpandedKeys.length ? props.defaultExpandedKeys : state.currentKey
- )
+ ),
+ clearable: computed(() => props.clearable)
})
Object.assign(api, {
diff --git a/packages/renderless/types/tree-menu.type.ts b/packages/renderless/types/tree-menu.type.ts
index 981e17501..7fa04a2eb 100644
--- a/packages/renderless/types/tree-menu.type.ts
+++ b/packages/renderless/types/tree-menu.type.ts
@@ -1,4 +1,4 @@
-import type { ExtractPropTypes } from 'vue'
+import type { ComputedRef, ExtractPropTypes } from 'vue'
import type { treeMenuProps } from '@/tree-menu/src'
import type {
initData,
@@ -31,6 +31,7 @@ export interface ITreeMenuState {
data?: unknown[]
filterText: string
isCollapsed: boolean
+ clearable: ComputedRef