Skip to content

Commit e4e63fa

Browse files
committed
* list: add isAllExpanded method to determine if all nested items are expanded.
1 parent 0f08495 commit e4e63fa

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

lib/list/src/component/nested-list.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,21 @@ export class NestedList<P extends NestedListProps = NestedListProps, S extends N
236236
return !!(nestedShow[keyPath] ?? this.state.defaultShow);
237237
}
238238

239+
isAllExpanded() {
240+
const {nestedShow} = this;
241+
if (typeof nestedShow === 'boolean') {
242+
return nestedShow;
243+
}
244+
const {defaultShow} = this.state;
245+
if (!Object.keys(nestedShow).length) {
246+
return !!defaultShow;
247+
}
248+
const itemMap = this.getItemMap(true);
249+
return Array.from(itemMap.entries()).every(([keyPath]) => {
250+
return nestedShow[keyPath] ?? defaultShow;
251+
});
252+
}
253+
239254
async toggle(keyPath: string, toggle?: boolean, reset?: boolean) {
240255
const isExpanded = this.isExpanded(keyPath);
241256
if (!reset && toggle === isExpanded) {

0 commit comments

Comments
 (0)