Skip to content

Commit

Permalink
sure the event target is the component itself. fixed #353
Browse files Browse the repository at this point in the history
  • Loading branch information
zdhxiong committed Oct 19, 2024
1 parent 16fbb66 commit 0032335
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
8 changes: 5 additions & 3 deletions packages/mdui/src/functions/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ export const alert = (options: Options): Promise<void> => {
});
}

$(dialog).on('close', () => {
isResolve ? resolve() : reject();
offLocaleReady(dialog);
$(dialog).on('close', (e) => {
if (e.target === dialog) {
isResolve ? resolve() : reject();
offLocaleReady(dialog);
}
});
});
};
8 changes: 5 additions & 3 deletions packages/mdui/src/functions/confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,11 @@ export const confirm = (options: Options): Promise<void> => {
});
}

$(dialog).on('close', () => {
isResolve ? resolve() : reject();
offLocaleReady(dialog);
$(dialog).on('close', (e) => {
if (e.target === dialog) {
isResolve ? resolve() : reject();
offLocaleReady(dialog);
}
});
});
};
12 changes: 9 additions & 3 deletions packages/mdui/src/functions/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ export const dialog = (options: Options): Dialog => {
} else if (callbacks.includes(key)) {
const eventName = toKebabCase(key.slice(2));

$dialog.on(eventName, () => {
value.call(dialog, dialog);
$dialog.on(eventName, (e) => {
if (e.target === dialog) {
value.call(dialog, dialog);
}
});
}
});
Expand Down Expand Up @@ -194,7 +196,11 @@ export const dialog = (options: Options): Dialog => {
});
}

$dialog.appendTo('body').on('closed', () => {
$dialog.appendTo('body').on('closed', (e) => {
if (e.target !== dialog) {
return;
}

$dialog.remove();

if (options.queue) {
Expand Down
8 changes: 5 additions & 3 deletions packages/mdui/src/functions/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,11 @@ export const prompt = (options: Options): Promise<string> => {
});
}

$(dialog).on('close', () => {
isResolve ? resolve(textField.value) : reject();
offLocaleReady(dialog);
$(dialog).on('close', (e) => {
if (e.target === dialog) {
isResolve ? resolve(textField.value) : reject();
offLocaleReady(dialog);
}
});
});
};
12 changes: 10 additions & 2 deletions packages/mdui/src/functions/snackbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ export const snackbar = (options: Options): Snackbar => {
) {
const eventName = toKebabCase(key.slice(2));

$snackbar.on(eventName, () => {
$snackbar.on(eventName, (e) => {
if (e.target !== snackbar) {
return;
}

if (key === 'onActionClick') {
const actionClick = (options.onActionClick ?? returnTrue).call(
snackbar,
Expand Down Expand Up @@ -163,7 +167,11 @@ export const snackbar = (options: Options): Snackbar => {
}
});

$snackbar.appendTo('body').on('closed', () => {
$snackbar.appendTo('body').on('closed', (e) => {
if (e.target !== snackbar) {
return;
}

$snackbar.remove();

if (options.queue) {
Expand Down

0 comments on commit 0032335

Please sign in to comment.