diff --git a/src/assets/menu/menu.json b/src/assets/menu/menu.json index eea2e8587..f1d7e1619 100644 --- a/src/assets/menu/menu.json +++ b/src/assets/menu/menu.json @@ -459,6 +459,10 @@ { "name": "Filter", "to": "/tree/filter" + }, + { + "name": "Scroll", + "to": "/tree/scroll" } ] }, diff --git a/src/components/tree/Tree.d.ts b/src/components/tree/Tree.d.ts index c4dfbc275..897c97a05 100755 --- a/src/components/tree/Tree.d.ts +++ b/src/components/tree/Tree.d.ts @@ -13,6 +13,7 @@ interface TreeProps { filterMode?: string; filterPlaceholder?: string; filterLocale?: string; + scrollHeight?: string; } declare class Tree { diff --git a/src/components/tree/Tree.vue b/src/components/tree/Tree.vue index 0cf4fc83e..06b0c55d4 100755 --- a/src/components/tree/Tree.vue +++ b/src/components/tree/Tree.vue @@ -10,11 +10,13 @@ @keydown="onFilterKeydown" v-model="filterValue" /> - +
+ +
@@ -73,6 +75,10 @@ export default { filterLocale: { type: String, default: undefined + }, + scrollHeight: { + type: String, + default: null } }, data() { @@ -243,7 +249,8 @@ export default { containerClass() { return ['p-tree p-component', { 'p-tree-selectable': this.selectionMode != null, - 'p-tree-loading': this.loading + 'p-tree-loading': this.loading, + 'p-tree-flex-scrollable': this.scrollHeight === 'flex' }]; }, loadingIconClass() { @@ -294,6 +301,10 @@ export default { list-style-type: none; } +.p-tree-wrapper { + overflow: auto; +} + .p-treenode-selectable { cursor: pointer; user-select: none; @@ -346,4 +357,15 @@ export default { align-items: center; justify-content: center; } + +.p-tree-flex-scrollable { + display: flex; + flex: 1; + height: 100%; + flex-direction: column; +} + +.p-tree-flex-scrollable .p-tree-wrapper { + flex: 1; +} diff --git a/src/router/index.js b/src/router/index.js index d482f0934..f0d9f2340 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -706,6 +706,11 @@ const routes = [ name: 'treefilter', component: () => import('../views/tree/TreeFilterDemo.vue') }, + { + path: '/tree/scroll', + name: 'treescroll', + component: () => import('../views/tree/TreeScrollDemo.vue') + }, { path: '/treeselect', name: 'treeselect', diff --git a/src/views/tree/TreeDoc.vue b/src/views/tree/TreeDoc.vue index 7803065fb..23221fd12 100755 --- a/src/views/tree/TreeDoc.vue +++ b/src/views/tree/TreeDoc.vue @@ -486,6 +486,30 @@ export default { } } + + +
Scrolling
+

Scrolling is used to preserve space as content of the tree is dynamic and enabled by scrollHeight property.

+

+
+ +
Flex Scroll
+

In cases where viewport should adjust itself according to the table parent's height instead of a fixed viewport height, set scrollHeight option as flex. In example below, + table is inside a Dialog where viewport size dynamically responds to the dialog size changes such as maximizing.

+ +

 
Filtering
diff --git a/src/views/tree/TreeScrollDemo.vue b/src/views/tree/TreeScrollDemo.vue new file mode 100644 index 000000000..9165182d3 --- /dev/null +++ b/src/views/tree/TreeScrollDemo.vue @@ -0,0 +1,217 @@ + + + + + \ No newline at end of file