mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
feat:事件干预逻辑
This commit is contained in:
parent
8d46a49195
commit
fc1d3b9be3
@ -151,16 +151,23 @@ export default class SelectControl extends React.Component<SelectProps, any> {
|
||||
this.input && this.input.focus();
|
||||
}
|
||||
|
||||
dispatchEvent(eventName: SelectRendererEvent, e: any = {}) {
|
||||
async dispatchEvent(eventName: SelectRendererEvent, e: any = {}) {
|
||||
const event = 'on' + eventName.charAt(0).toUpperCase() + eventName.slice(1);
|
||||
const {dispatchEvent, options} = this.props;
|
||||
dispatchEvent(eventName, createObject(e, {
|
||||
options
|
||||
}));
|
||||
// 触发渲染器事件
|
||||
const rendererEvent = await dispatchEvent(
|
||||
eventName,
|
||||
createObject(e, {
|
||||
options
|
||||
})
|
||||
);
|
||||
if (rendererEvent?.prevented) {
|
||||
return;
|
||||
}
|
||||
this.props[event](e);
|
||||
}
|
||||
|
||||
changeValue(value: Option | Array<Option> | string | void) {
|
||||
async changeValue(value: Option | Array<Option> | string | void) {
|
||||
const {
|
||||
joinValues,
|
||||
extractValue,
|
||||
@ -215,10 +222,14 @@ export default class SelectControl extends React.Component<SelectProps, any> {
|
||||
// 不设置没法回显
|
||||
additonalOptions.length && setOptions(options.concat(additonalOptions));
|
||||
|
||||
dispatchEvent('change', {
|
||||
const rendererEvent = await dispatchEvent('change', {
|
||||
value: newValue,
|
||||
options
|
||||
});
|
||||
if (rendererEvent?.prevented) {
|
||||
return;
|
||||
}
|
||||
|
||||
onChange(newValue);
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ export class BaseTransferRenderer<
|
||||
T extends OptionsControlProps = BaseTransferProps
|
||||
> extends React.Component<T> {
|
||||
@autobind
|
||||
handleChange(value: Array<Option> | Option, optionModified?: boolean) {
|
||||
async handleChange(value: Array<Option> | Option, optionModified?: boolean) {
|
||||
const {
|
||||
onChange,
|
||||
joinValues,
|
||||
@ -179,11 +179,19 @@ export class BaseTransferRenderer<
|
||||
|
||||
(newOptions.length > options.length || optionModified) &&
|
||||
setOptions(newOptions, true);
|
||||
|
||||
dispatchEvent('change', {
|
||||
value: newValue,
|
||||
options
|
||||
});
|
||||
|
||||
// 触发渲染器事件
|
||||
const rendererEvent = await dispatchEvent(
|
||||
'change',
|
||||
{
|
||||
value: newValue,
|
||||
options
|
||||
}
|
||||
);
|
||||
if (rendererEvent?.prevented) {
|
||||
return;
|
||||
}
|
||||
|
||||
onChange(newValue);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user