# Message

An inline status message that stays in the page flow, next to the content it is about. Use it for persistent feedback such as form errors or account notices; for short-lived confirmations use a toast.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-message`
- Source: [libs/ui/src/lib/atoms/message/message.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/atoms/message/message.ts)

```typescript title="Import"
import { Message } from '@vigdx/ui/message';
```

## Severities

`variant` sets the severity and its icon: `info` (default), `success`, `warning` and `error`. Pass the body as `text` and an optional bold `heading` (formerly `title`, now deprecated: it also set the native tooltip).

```typescript title="message-severities.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Message } from '@vigdx/ui/message';

@Component({
  selector: 'app-message-severities',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Message],
  template: `
    <div class="flex w-full max-w-xl flex-col gap-3">
      <vig-message text="Your trial ends in 5 days." />
      <vig-message variant="success" text="Payment received. Thank you!" />
      <vig-message
        variant="warning"
        heading="Storage almost full"
        text="You have used 92% of your 10 GB."
      />
      <vig-message
        variant="error"
        heading="Upload failed"
        text="The file is larger than 25 MB. Choose a smaller file and try again."
      />
    </div>
  `,
})
export class MessageSeveritiesDemo {}
```

## Custom content

Without `text`, the projected content becomes the body, e.g. a list of errors or a sentence with a link. The neutral variants (`primary`, `secondary`) suit plain notes; `showIcon` hides the icon.

```typescript title="message-content.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Link } from '@vigdx/ui/link';
import { Message } from '@vigdx/ui/message';

@Component({
  selector: 'app-message-content',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Link, Message],
  template: `
    <div class="flex w-full max-w-xl flex-col gap-3">
      <vig-message variant="warning" heading="Please fix 2 fields">
        <ul class="mt-1 list-disc ps-5">
          <li>Email must be a valid address.</li>
          <li>Password needs at least 12 characters.</li>
        </ul>
      </vig-message>
      <vig-message variant="secondary" [showIcon]="false">
        Prices exclude VAT. See the <vig-link href="#billing-faq">billing FAQ</vig-link> for
        details.
      </vig-message>
    </div>
  `,
})
export class MessageContentDemo {}
```

## Closable

`closable` adds a dismiss button. The message hides itself and emits `closed`; remove it with `@if` to bring it back later or to remember the choice.

```typescript title="message-closable.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { Button } from '@vigdx/ui/button';
import { Message } from '@vigdx/ui/message';

@Component({
  selector: 'app-message-closable',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Button, Message],
  template: `
    <div class="flex w-full max-w-xl flex-col items-start gap-3">
      @if (visible()) {
        <vig-message
          class="w-full"
          heading="New: dark mode"
          text="Switch themes from the toolbar at the top of the page."
          [closable]="true"
          (closed)="visible.set(false)"
        />
      } @else {
        <vig-button
          label="Show the message again"
          variant="secondary"
          size="sm"
          (click)="visible.set(true)"
        />
      }
    </div>
  `,
})
export class MessageClosableDemo {
  protected readonly visible = signal(true);
}
```

## Styling hooks

Internal elements carry a stable `data-part` and the component's `data-scope`; both are public API, so removing one is a breaking change. Select a part by both, e.g. `[data-scope="message"][data-part="root"] { … }`: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through `aria-*` and, where listed, a `data-state`; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other `data-*` attributes listed below (such as `data-opening` while an overlay animates) are API too. See [Customizing](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="message"]`

| Part | Element | data-state |
| --- | --- | --- |
| `root` | The message box. | `info, success, warning, error …` |
| `icon` | The leading status icon (`showIcon`). |   |
| `content` | Wrapper of the heading and text. |   |
| `heading` | The bold heading line. |   |
| `text` | The body text (`text`). |   |
| `close` | The close button (`closable`). |   |

## Accessibility

- `error` and `warning` messages have `role="alert"` and are announced immediately; the other variants use `role="status"` and are announced politely. `[live]="false"` drops the role where something else announces the message, as `vig-toaster` does.
- Live regions announce changes, not content present on page load. To announce a message, render it in response to the event (e.g. a failed submit) rather than hiding it with CSS.
- The icon is decorative; the severity must also be clear from the text or the heading.
- The dismiss button is named by `closeAriaLabel` (localized “Dismiss” by default). When it had focus, closing moves focus to the next focusable element after the message, or the previous one at the end of the page, so keyboard users keep their place (a `closed` handler may focus something else instead).

## API

### Message

Selector: `vig-message` · Kind: component

Inline alert for contextual feedback (PrimeNG p-message territory). Error/warning announce assertively via role="alert"; the rest use role="status". Closing hides the message and emits `closed`; when focus was on the close button it moves to the next focusable element after the message (else the previous one), so keyboard users keep their place instead of falling back to the top of the page.

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `closable` | `boolean` | `false` | — |
| `closeAriaLabel` | `string \| undefined` | `undefined` | — |
| `heading` | `string \| undefined` | `undefined` | Optional bold heading line above the body. |
| `live` | `boolean` | `true` | Whether the message is a live region (`alert`/`status`). Turn it off where something else announces it, as vig-toaster does, so it is not read twice. |
| `showIcon` | `boolean` | `true` | — |
| `text` | `string \| undefined` | `undefined` | Body text; projected content is used when omitted. |
| `title` | `string \| undefined` | `undefined` | **Deprecated**: Use `heading`; `title` is also the native tooltip attribute. Still honored when `heading` is unset, and never shown as a tooltip. |
| `variant` | `MessageVariant` | `'info'` | — |

#### Outputs

| Name | Payload | Description |
| --- | --- | --- |
| `closed` | `void` | — |
