fix(amis): Collapse细节完善,以及onCollapse剔除多余的参数

This commit is contained in:
wibetter 2023-12-10 19:08:38 +08:00
parent 8aac5c078f
commit f41e6364e5
3 changed files with 11 additions and 13 deletions

View File

@ -45,7 +45,7 @@ export interface CollapseProps extends ThemeProps {
headingClassName?: string;
collapseHeader?: React.ReactElement | null;
size?: 'xs' | 'sm' | 'md' | 'lg' | 'base';
onCollapse?: (item: any, collapsed: boolean) => void;
onCollapse?: (collapsed: boolean) => void;
wrapperComponent?: any;
headingComponent?: any;
translate?: TranslateFn;
@ -110,7 +110,7 @@ export class Collapse extends React.Component<CollapseProps, CollapseState> {
return;
}
const newCollapsed = !this.state.collapsed;
props.onCollapse?.(props, newCollapsed);
props.onCollapse?.(newCollapsed);
this.setState({
collapsed: newCollapsed
});
@ -131,7 +131,7 @@ export class Collapse extends React.Component<CollapseProps, CollapseState> {
collapsed: targetState
},
() => {
this.props.onCollapse?.(this.props, targetState);
this.props.onCollapse?.(targetState);
}
);
}

View File

@ -90,18 +90,16 @@ class CollapseGroup extends React.Component<
if (this.props.accordion) {
activeKeys = [];
} else {
for (let i = 0; i < activeKeys.length; i++) {
if (activeKeys[i] === collapseId) {
activeKeys.splice(i, 1); // 剔除开启状态
break;
}
const activeKeyIndex = activeKeys.indexOf(collapseId);
if (activeKeyIndex !== -1) {
activeKeys.splice(activeKeyIndex, 1); // 剔除开启状态
}
}
} else {
// 展开折叠器
if (this.props.accordion) {
activeKeys = [collapseId as string];
} else {
} else if (activeKeys.indexOf(collapseId) === -1) {
activeKeys.push(collapseId as string);
}
}
@ -134,7 +132,7 @@ class CollapseGroup extends React.Component<
collapsed,
expandIcon: this.props.expandIcon,
propsUpdate: true,
onCollapse: (item: CollapseItem, collapsed: boolean) =>
onCollapse: (collapsed: boolean) =>
this.collapseChange(collapseId, collapsed)
});
});

View File

@ -131,7 +131,7 @@ export default class Collapse extends React.Component<CollapseProps, {}> {
basicCollapse = React.createRef<any>();
@autobind
async handleCollapseChange(props: any, collapsed: boolean) {
async handleCollapseChange(collapsed: boolean) {
const {dispatchEvent, onCollapse} = this.props;
const eventData = resolveEventData(this.props, {
collapsed
@ -150,7 +150,7 @@ export default class Collapse extends React.Component<CollapseProps, {}> {
return;
}
onCollapse?.(props, collapsed);
onCollapse?.(collapsed);
}
doAction(action: ActionObject, args: object, throwErrors: boolean): any {
@ -159,7 +159,7 @@ export default class Collapse extends React.Component<CollapseProps, {}> {
}
if (['expand', 'collapse'].includes(action.actionType!)) {
const targetState = action.actionType === 'collapse';
this.handleCollapseChange(this.props, targetState);
this.handleCollapseChange(targetState);
const collapseInstance = (
this.basicCollapse?.current as any
)?.getWrappedInstance?.();