diff --git a/lib/list/src/component/list.tsx b/lib/list/src/component/list.tsx index fdbc757022..5c74dafe38 100644 --- a/lib/list/src/component/list.tsx +++ b/lib/list/src/component/list.tsx @@ -1,4 +1,4 @@ -import {$, HElement, classes, fetchData, mergeProps, removeUndefinedProps} from '@zui/core'; +import {$, Computed, HElement, classes, fetchData, mergeProps, removeUndefinedProps} from '@zui/core'; import {CommonList} from '@zui/common-list/src/component'; import {Listitem} from './listitem'; @@ -24,10 +24,26 @@ export class List
>(() => {
+ const map = new Set this.isChecked(key!, index) === true);
}
- toggleAllChecked(checked?: boolean): void {
+ toggleAllChecked(checked?: boolean) {
if (checked === undefined) {
checked = !this.isAllChecked();
}
- this.toggleChecked(this._renderedItems.map(x => x.key!), checked);
+ return this.toggleChecked(this._renderedItems.map(x => x.key!), checked);
}
- toggleChecked(keyOrChange: ItemKey | ItemKey[] | Record ({
+ await this.changeState(prevState => ({
checked: {
...prevState.checked,
...change,
},
- }), () => {
+ } as Partial {
+ const activeMap = this.props.multipleActive ? (keys as string[]).reduce ): ComponentChildren {
+ this._hasIcons = false;
+ this._hasCheckbox = false;
+ this._activeSet.compute();
const children = super._getChildren(props) as ComponentChild[];
const {loadFailed} = this.state;
if (loadFailed) {
diff --git a/lib/list/src/component/nested-list.tsx b/lib/list/src/component/nested-list.tsx
index a44ae2a5e6..889ca9cfad 100644
--- a/lib/list/src/component/nested-list.tsx
+++ b/lib/list/src/component/nested-list.tsx
@@ -58,8 +58,9 @@ function parentKeys(keyPath: string) {
}, []);
}
-function initItemMap(items: Item[], itemKey: string | undefined, map: Map extends List {
@@ -191,7 +199,7 @@ export class NestedList {
+ await this.changeState(prevState => {
const newNestedShow: Record ;
}, this._preserveState);
}
@@ -255,7 +263,7 @@ export class NestedList , checked?: CheckedType): void {
+ async toggleChecked(keyOrChange: ItemKey | ItemKey[] | Record {
+ await this.changeState(({checked: prevChecked}) => {
const isChecked = (item: ItemInfo) => {
return change[item.keyPath] ?? prevChecked[item.keyPath] ?? item.data.checked ?? false;
};
@@ -313,19 +321,76 @@ export class NestedList ;
}, () => {
const checkState = this.state.checked;
this.props.onCheck?.call(this, change, Object.keys(checkState).filter(x => checkState[x] === true));
});
- } else {
- const {parentKey, onCheck} = this.props;
- const nestedChange = Object.keys(change).reduce >((propMap, key) => {
propMap[key] = props[key as keyof P];
return propMap;
@@ -370,9 +436,10 @@ export class NestedList extends CommonListProps), () => {
const checkState = this.state.checked;
this.props.onCheck?.call(this, change, Object.keys(checkState).filter(x => checkState[x] === true));
});
@@ -139,6 +155,77 @@ export class List;
+ }, () => {
+ this.props.onActive?.call(this, keys as string[], active!);
+ });
+ }
+
+ getNextItem(key: string | undefined, condition?: (item: Item, index: number) => boolean, step = 1, items: Item[] | undefined = undefined): Item | undefined {
+ items = items || this._renderedItems;
+ if (key === undefined) {
+ return items.at(step ? 0 : -1);
+ }
+ const count = items.length;
+ let index = items.findIndex(x => x.key === key);
+ if (index < 0 || count < 2) {
+ return items.at(step ? 0 : -1);
+ }
+ let checkCount = 0;
+ condition = condition || ((x) => x.type === 'item' && !x.disabled);
+ while (checkCount < count) {
+ index = (index + step + count) % count;
+ const nextItem = items[index];
+ if (nextItem && condition.call(this, nextItem, index)) {
+ return nextItem;
+ }
+ checkCount++;
+ }
+ }
+
+ getPrevItem(key: string | undefined, condition?: (item: Item, index: number) => boolean): Item | undefined {
+ return this.getNextItem(key, condition, -1);
+ }
+
+ activeNext(condition?: (item: Item, index: number) => boolean, step = 1) {
+ const nextItem = this.getNextItem(this.getActiveKey(), condition, step);
+ if (nextItem) {
+ this.toggleActive(nextItem.key!);
+ }
+ }
+
+ activePrev(condition?: (item: Item, index: number) => boolean) {
+ this.activeNext(condition, -1);
+ }
+
protected _afterRender(firstRender: boolean) {
this.props.afterRender?.call(this, firstRender);
}
@@ -168,10 +255,13 @@ export class List