Files
ionic-framework/core/src/components/alert
Ross Gerbasi 147a6090e4 refactor(theming): alpha color refactor and theme cleanup (#14161)
* Cleanup for iOS mode used in material variables
Refactor to alpha variables for colors in the color map
updated theme builder with new alpha variables
updated theme builder with duplicate default CSS modes

* moved alpha transform into css-var
removed ion-color-alpha
fixes for disabled css-variable mode
added defaults for user configurable variables

* revert to spinner related code
2018-03-15 11:53:48 -04:00
..

ion-alert

An Alert is a dialog that presents users with information or collects information from the user using inputs. An alert appears on top of the app's content, and must be manually dismissed by the user before they can resume interaction with the app. It can also optionally have a title, subTitle and message.

Creating

Alerts can be created using a Alert Controller. They can be customized by passing alert options in the alert controller's create method.

Buttons

In the array of buttons, each button includes properties for its text, and optionally a handler. If a handler returns false then the alert will not automatically be dismissed when the button is clicked. All buttons will show up in the order they have been added to the buttons array from left to right. Note: The right most button (the last one in the array) is the main button.

Optionally, a role property can be added to a button, such as cancel. If a cancel role is on one of the buttons, then if the alert is dismissed by tapping the backdrop, then it will fire the handler from the button with a cancel role.

Inputs

Alerts can also include several different inputs whose data can be passed back to the app. Inputs can be used as a simple way to prompt users for information. Radios, checkboxes and text inputs are all accepted, but they cannot be mixed. For example, an alert could have all radio button inputs, or all checkbox inputs, but the same alert cannot mix radio and checkbox inputs. Do note however, different types of "text"" inputs can be mixed, such as url, email, text, etc. If you require a complex form UI which doesn't fit within the guidelines of an alert then we recommend building the form within a modal instead.

async function presentAlert() {
  const alertController = document.querySelector('ion-alert-controller');
  await alertController.componentOnReady();

  const alert = await alertController.create({
    title: 'Alert',
    subTitle: 'Subtitle',
    message: 'This is an alert message.',
    buttons: ['OK']
  });
  return await alert.present();
}

Properties

buttons

Array of buttons to be added to the alert.

cssClass

string

Additional classes to apply for custom CSS. If multiple classes are provided they should be separated by spaces.

enableBackdropDismiss

boolean

If true, the alert will be dismissed when the backdrop is clicked. Defaults to true.

enterAnimation

Animation to use when the alert is presented.

inputs

Array of input to show in the alert.

leaveAnimation

Animation to use when the alert is dismissed.

message

string

The main message to be displayed in the alert.

overlayId

number

subTitle

string

The subtitle in the heading of the alert. Displayed under the title.

title

string

The main title in the heading of the alert.

translucent

boolean

If true, the alert will be translucent. Defaults to false.

willAnimate

boolean

If true, the alert will animate. Defaults to true.

Attributes

buttons

Array of buttons to be added to the alert.

css-class

string

Additional classes to apply for custom CSS. If multiple classes are provided they should be separated by spaces.

enable-backdrop-dismiss

boolean

If true, the alert will be dismissed when the backdrop is clicked. Defaults to true.

enter-animation

Animation to use when the alert is presented.

inputs

Array of input to show in the alert.

leave-animation

Animation to use when the alert is dismissed.

message

string

The main message to be displayed in the alert.

overlay-id

number

sub-title

string

The subtitle in the heading of the alert. Displayed under the title.

title

string

The main title in the heading of the alert.

translucent

boolean

If true, the alert will be translucent. Defaults to false.

will-animate

boolean

If true, the alert will animate. Defaults to true.

Events

ionAlertDidDismiss

Emitted after the alert has dismissed.

ionAlertDidLoad

Emitted after the alert has presented.

ionAlertDidPresent

Emitted after the alert has presented.

ionAlertDidUnload

Emitted before the alert has presented.

ionAlertWillDismiss

Emitted before the alert has dismissed.

ionAlertWillPresent

Emitted before the alert has presented.

Methods

dismiss()

Dismiss the alert overlay after it has been presented.

onDidDismiss()

onWillDismiss()

present()

Present the alert overlay after it has been created.


Built with StencilJS