AlertViewElement

An AlertViewElement writes a <div> element with the role "alert" to the output.

Element and builder

The AlertViewElement has an equivalent AlertViewElementBuilder. A builder can be created using BootstrapUiBuilders.alert() factory methods.

AlertViewElement attributes

Attribute Description Default

Type

A AlertViewElement has the following default styles: INFO,WARNING,DANGER, SUCCESS

Not set by default

closeLabel

An aria-label shown for the close icon

Not set by default

dismissible

A boolean indicating if the AlertViewElement can be dismissed

False by default

Examples

Creating a simple alert

Given the following builder configuration

BootstrapUiBuilders
    .alert()
    .danger()
    .text( "This is a danger alert—check it out!\n" )
    .build();

The following markup would be rendered:

<div role="alert" class="alert alert-danger">This is a danger alert—check it out!</div>

Creating an alert with several options

Given the following builder configuration

BootstrapUiBuilders
    .alert()
    .closeLabel( "Close alert" )
    .dismissible( false )
    .success()
    .text( "This is a success alert—check it out!\n" )
    .build();

The following markup would be rendered:

<div role="alert" class="alert alert-dismissible alert-success">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close alert">
        <span aria-hidden="true">×</span>
    </button>
    This is a success alert—check it out!
</div>