-
Notifications
You must be signed in to change notification settings - Fork 13.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix](alert, actionSheet, picker and toast): Call pressed button handler, regardless 'role' #28952
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we write a test that verifies the callback (handler) is called with cancel
role buttons?
If you need any help or direction on this, let me know!
core/src/components/alert/alert.tsx
Outdated
@@ -462,12 +462,12 @@ export class Alert implements ComponentInterface, OverlayInterface { | |||
private async buttonClick(button: AlertButton) { | |||
const role = button.role; | |||
const values = this.getValues(); | |||
if (isCancel(role)) { | |||
if (isCancel(role) && button.handler === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll need to ask the team, but this change does change the current behavior of a cancel
role button with a custom handler that returns false
.
Previously, it would have dismissed the overlay. With the proposed changes it would not dismiss.
I think the change in behavior is valid/expected, but never hurts to get a second opinion 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello! After speaking with the team, I'd advise we adjust the implementation pattern here. We should de-risk and validate a use case for needing to prevent a dismiss with a cancel role, before making that change.
The proposed fix for the original issue should execute the handler callback, but not prevent dismissing. Something to the effect of:
private async buttonClick(button: AlertButton) {
const role = button.role;
const values = this.getValues();
const returnData = await this.callButtonHandler(button, values);
if (isCancel(role)) {
/**
* Cancel roles should always dismiss the alert,
* even if the handler function returns `false`.
*/
return this.dismiss({ values, ...returnData }, role);
}
if (returnData !== false) {
return this.dismiss({ values, ...returnData }, role);
}
return false;
}
While investigating this issue further, I found that ion-action-sheet
, ion-picker
, and ion-toast
all have very similar implementations and likely the same problematic behavior.
We can discuss more in Slack, but I think addressing the fix across all these implementations would be great to knock out together, once we validate the path for one. I can help out here if desired.
@joselrio changes look great! Are we able to write an automated test using Playwright to validate the button handler is called? Feel free to ping me on Slack if you have questions on how to write the test. |
Hi @sean-perkins, Can you please take a look at the latest stuff I made to this? Cheers, |
Hello @joselrio can you incorporate the changes that I applied here: 91b5b8b#diff-5ce56bbcb3bd1b1e868dd811c6c96de0bb2d8f72d3dde47fb2d83c48989b6159 for the picker component tests, to the remaining overlays? A few key points on why we would prefer this change:
Let me know if you have any questions or concerns! |
Issue number: resolves #23037
What is the current behavior?
If two buttons in an alert both have the cancel role, only the first handler will ever be called, regardless of which button is pressed.
Based on @sean-perkins comments, fix has been added to ion-action-sheet, ion-picker, and ion-toast as well since they had the same issue.
What is the new behavior?
Now the handler for the pressed button is called, regardless of its 'role'.
Does this introduce a breaking change?
Other information
Alert:
Action Sheet:
Picker
Toast: