From 4c52ab0c58b1beb1a29ba1b7d8616eeee319034a Mon Sep 17 00:00:00 2001 From: hezhihang Date: Thu, 21 Nov 2024 22:36:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=99=9A=E6=8B=9F=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=AB=98=E5=BA=A6=E8=87=AA=E9=80=82=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh-CN/components/form/input-tree.md | 97 +++++++++++++++++++ .../amis/src/renderers/Form/InputTree.tsx | 30 +++--- 2 files changed, 114 insertions(+), 13 deletions(-) diff --git a/docs/zh-CN/components/form/input-tree.md b/docs/zh-CN/components/form/input-tree.md index 02f6499a38f..af590e3ac2b 100755 --- a/docs/zh-CN/components/form/input-tree.md +++ b/docs/zh-CN/components/form/input-tree.md @@ -1362,6 +1362,103 @@ true false false [{label: 'A/B/C', value: 'a/b/c'},{label: 'A } ``` +## 虚拟列表 + +> 6.9.0 以上版本, 开启 heightAuto 后,虚拟列表将自适应高度 + +```schema: scope="body" +{ + "type": "page", + "aside": [ + { + "type": "flex", + "direction": "column", + "isFixedHeight": true, + "style": { + "height": "300px" + }, + "items": [ + { + "type": "input-tree", + "id": "tree", + "name": "tree", + "label": false, + "heightAuto": true, + "virtualThreshold": 5, + "options": [ + { + "label": "Folder A", + "value": 1, + "children": [ + { + "label": "file A", + "value": 2 + }, + { + "label": "file B", + "value": 3 + } + ] + }, + { + "label": "file C", + "value": 4 + }, + { + "label": "file D", + "value": 5 + }, + { + "label": "file E", + "value": 6 + }, + { + "label": "file F", + "value": 7 + }, + { + "label": "file G", + "value": 8 + }, + { + "label": "file H", + "value": 9 + }, + { + "label": "file I", + "value": 10 + }, + { + "label": "file J", + "value": 11 + }, + { + "label": "file K", + "value": 12 + }, + { + "label": "file L", + "value": 13 + } + ], + "wrapperCustomStyle": { + "root": { + "height": "100%" + } + } + } + ] + } + ], + "body": [ + { + "type": "tpl", + "tpl": "开启heightAuto后,设置tree的高度,虚拟列表将自适应" + } + ] +} +``` + ## 属性表 当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置 diff --git a/packages/amis/src/renderers/Form/InputTree.tsx b/packages/amis/src/renderers/Form/InputTree.tsx index c3a590ed59f..c7228e59059 100644 --- a/packages/amis/src/renderers/Form/InputTree.tsx +++ b/packages/amis/src/renderers/Form/InputTree.tsx @@ -255,16 +255,18 @@ export default class TreeControl extends React.Component { } componentDidMount() { - this.initOthersHeight(); - this.handleVirtualListHeight(); - this.unSensor = resizeSensor( - this.rootRef.current?.parentElement!, - () => { - this.handleVirtualListHeight(); - }, - false, - 'height' - ); + if (this.props.heightAuto) { + this.initOthersHeight(); + this.handleVirtualListHeight(); + this.unSensor = resizeSensor( + this.rootRef.current?.parentElement!, + () => { + this.handleVirtualListHeight(); + }, + false, + 'height' + ); + } } componentDidUpdate(prevProps: TreeProps, preState: TreeState) { @@ -292,16 +294,18 @@ export default class TreeControl extends React.Component { 'creatable', 'hideRoot', 'themeCss', - 'wrapperCustomStyle' + 'wrapperCustomStyle', + 'heightAuto' ], prevProps, props - ) + ) && + props.heightAuto ) { this.initOthersHeight(); } - if (preState.othersHeight !== state.othersHeight) { + if (preState.othersHeight !== state.othersHeight && props.heightAuto) { this.handleVirtualListHeight(); } }