Merge pull request #3892 from igrowp/tabs-event

fix: tabs 触发change事件调整
This commit is contained in:
hsm-lv 2022-03-30 15:36:40 +08:00 committed by GitHub
commit f7093678d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -319,7 +319,7 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
} else {
const tab = this.resolveTabByKey(this.activeKey);
if (tab && value !== ((tab as any).value ?? tab.title)) {
this.handleChange((tab as any).value ?? tab.title, name);
onChange((tab as any).value ?? tab.title, name);
}
}
}
@ -438,7 +438,7 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
} else if (this.activeKey !== prevState.activeKey) {
const tab = this.resolveTabByKey(this.activeKey);
if (tab && value !== ((tab as any).value ?? tab.title)) {
this.handleChange((tab as any).value ?? tab.title, name);
onChange((tab as any).value ?? tab.title, name);
}
}
}
@ -566,8 +566,8 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
}
@autobind
handleSelect(key: any) {
const {env, onSelect, id} = this.props;
async handleSelect(key: any) {
const {dispatchEvent, data, env, onSelect, id} = this.props;
env.tracker?.({
eventType: 'tabChange',
@ -577,6 +577,16 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
}
});
const rendererEvent = await dispatchEvent(
'change',
createObject(data, {
value: key
})
);
if (rendererEvent?.prevented) {
return;
}
// 是 hash需要更新到地址栏
if (typeof key === 'string' && env) {
env.updateLocation(`#${key}`);
@ -597,22 +607,6 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
}
}
@autobind
async handleChange(key: any, name: any) {
const {dispatchEvent, data, onChange} = this.props;
const rendererEvent = await dispatchEvent(
'change',
createObject(data, {
value: key
})
);
if (rendererEvent?.prevented) {
return;
}
onChange && onChange(key, name);
}
/**
*
*/