Shows important information on a page. Can contain a hint, signal a status change, or indicate a problem.
Alerts come in two sizes. The normal size is the default; pass [compact]="true" for the denser compact size used in tight spaces such as popovers and forms.
By default, alerts are styled conservatively and stand out only by the icon color. If the block gets lost on screen, you can draw attention to it using the colored background variant.
The alertColor input sets the status: error, warning, success or info (the default). It drives the background in the colored variant and auto-tints a projected status icon that has no explicit [color]: the icon is tinted to the matching status color, except info, which is tinted to contrast. Set [color] on the icon yourself to opt out of the auto-tint.
Project a single status icon. The slot renders every [kbq-icon] and [kbq-icon-item] it receives but auto-tints only one of them — a kbq-icon wins over a kbq-icon-item — so any further icon keeps whatever color it was given. Projecting one of each also logs a warning in dev mode.
The block can be hidden by clicking the icon button in the corner of the alert. The alert does not hide itself — listen to the (closed) output (emitted when the close control is activated) and remove or hide the alert in your own code. If the system reports a problem, the alert is displayed permanently and the user cannot close it.
The alert can contain links and buttons; the icon and heading can be omitted. In a lengthy notification, the text can be split into paragraphs.
A paragraph should convey and develop only one idea. For example, if you mix the causes, the essence of the problem, and possible solutions to the situation you are describing in a single paragraph, the reader will quickly get tired and most likely will not understand what they just read.
Try to state the key idea in the first sentence of the paragraph, then expand on it in more detail and back it up with examples. That way the reader can skim the text diagonally and immediately see what each part is about. Sometimes the first sentences of a paragraph are set in bold — these are called run-in headings.
A paragraph should convey and develop only one idea. For example, if you mix the causes, the essence of the problem, and possible solutions to the situation you are describing in a single paragraph, the reader will quickly get tired and most likely will not understand what they just read.
Try to state the key idea in the first sentence of the paragraph, then expand on it in more detail and back it up with examples. That way the reader can skim the text diagonally and immediately see what each part is about. Sometimes the first sentences of a paragraph are set in bold — these are called run-in headings.
role="alert" would make a screen reader announce page-load content unexpectedly.role="alert" for urgent messages, or aria-live="polite" with aria-atomic="true" for non-urgent status, so assistive technology announces it. Alternatively, announce the message with LiveAnnouncer from @angular/cdk/a11y.<span class="cdk-visually-hidden">Error:</span>), and mark a decorative status icon aria-hidden="true".<button> with an accessible name (aria-label="Close") so it is reachable and operable by keyboard.<body>. Move focus to a logical target after removal — prefer FocusMonitor.focusVia from @angular/cdk/a11y so the focus ring is preserved.