Skip to content

Proposal: Alert should fire onDismiss when no Close option is available #8865

Closed

Description

Summary

The Alert module already exposes functionality for onDismiss for Android. On Android, when the user sets cancelable to true, the alert works in a "light dismiss" mode where tapping anywhere on the screen will dismiss the alert and fire onDismiss.

The proposal is to piggy back on this available prop onDismiss prop for Android, and when the ContentDialog is dismissed with the Esc key, and no "neutral" option is available, fire the dismiss action rather than the neutral button press, which presumably does not have a callback.

On RNW, we could presumably also implement cancelable, but since that's not been the behavior thus far (XAML ContentDialogs displayed for alerts have always been "dismissable" by pressing Esc), we can save that for a future improvement.

Motivation

There is no way to know when a user dismisses an alert with the Esc key as opposed to clicking one of the ContentDialog buttons:

Basic Example

Alert.alert('Alert', 'Warning, an alert is being shown', [], {onDismiss: () => console.log('Dismissed!')});

Open Questions

  • Should we also support cancelable?
  • If we do support cancelable, should the default value be false as on Android?
  • This is technically a breaking change, as users may create a "neutral" callback without adding any button text, but it would be very strange to register a neutral button callback without any text (unless you are relying on an implementation detail of react-native-windows Alert).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions