> Markdown version of [Notification](https://vaadin.com/docs/latest/fr/components/notification). Section index: [llms.txt](https://vaadin.com/docs/latest/fr/components/llms.txt)

# <a id="notification"></a>Notification

Notification est utilisé pour fournir un retour à l’utilisateur sur les activités, les processus, et les événements dans l’application.

**Lit** — `notification-basic.ts`

```typescript
const notification = Notification.show('Financial report generated', {
  position: 'middle',
  duration: 0,
});
```

**Flow** — `NotificationBasic.java`

```java
// When creating a notification using the `show` static method,
// the duration is 5-sec by default.
Notification notification = Notification
        .show("Financial report generated");
```

**React** — `notification-basic.tsx`

```typescript
const notification = Notification.show('Financial report generated', {
  position: 'middle',
  duration: 0,
});
```

## <a id="durée"></a>Durée

Par défaut, les notifications restent à l’écran pendant cinq secondes. La durée peut être définie — en millisecondes — et devrait l’être en fonction du contenu et de son importance :

- Utilisez des durées courtes pour les notifications qui contiennent un texte court, sont de moindre importance (par exemple, des opérations terminées sans erreurs), et ne comportent aucun élément interactif.

- Utilisez des durées plus longues pour les notifications qui contiennent un texte plus long, sont plus importantes (par exemple, des erreurs), et comportent des éléments interactifs (par exemple, des liens ou des actions "undo").

Une durée d’au moins cinq secondes (c’est-à-dire, `5000` millisecondes) est recommandée — c’est pourquoi c’est la valeur par défaut — afin de garantir que l’utilisateur ait une chance de lire et de comprendre la notification.

### <a id="notifications-persistantes"></a>Notifications persistantes

Définir la durée à `0` milliseconde désactive la fermeture automatique. Cela garde la notification visible jusqu’à ce qu’elle soit explicitement fermée par l’utilisateur. Ceci devrait être utilisé pour les notifications qui fournissent des informations vitales à l’utilisateur, telles que des erreurs.

Les notifications persistantes devraient contenir un Button qui ferme la notification, ou permet à l’utilisateur d’effectuer l’action appropriée. Les notifications moins importantes ne devraient pas être persistantes, et devraient plutôt disparaître automatiquement après un délai approprié.

## <a id="position"></a>Position

Les notifications peuvent être positionnées dans le viewport dans sept positions non étirées, ou étirées sur toute la largeur en haut ou en bas :

Utilisez l’attribut `position` dans les templates HTML (par exemple, `<vaadin-notification position="top-end"></vaadin-notification>`).

**Lit** — `notification-position.ts`

```typescript
protected override render() {
  return html`
    <vaadin-button @click="${this.show}">top-stretch</vaadin-button>
    <vaadin-button @click="${this.show}">top-start</vaadin-button>
    <vaadin-button @click="${this.show}">top-center</vaadin-button>
    <vaadin-button @click="${this.show}">top-end</vaadin-button>
    <vaadin-button @click="${this.show}">middle</vaadin-button>
    <vaadin-button @click="${this.show}">bottom-start</vaadin-button>
    <vaadin-button @click="${this.show}">bottom-center</vaadin-button>
    <vaadin-button @click="${this.show}">bottom-end</vaadin-button>
    <vaadin-button @click="${this.show}">bottom-stretch</vaadin-button>
  `;
}

show(event: MouseEvent) {
  // Use the button label as the location
  const position = (event.target as HTMLElement).textContent as NotificationPosition;

  Notification.show(position, { position });
}
```

**Flow** — `NotificationPosition.java`

```java
add(createButton(Position.TOP_STRETCH),
        createButton(Position.TOP_START),
        createButton(Position.TOP_CENTER),
        createButton(Position.TOP_END), createButton(Position.MIDDLE),
        createButton(Position.BOTTOM_START),
        createButton(Position.BOTTOM_CENTER),
        createButton(Position.BOTTOM_END),
        createButton(Position.BOTTOM_STRETCH));

...

private Button createButton(Notification.Position position) {
    Button button = new Button(position.getClientName());
    button.addClickListener(event -> show(position));
    return button;
}

...

private void show(Notification.Position position) {
    Notification.show(position.getClientName(), 5000, position);
}
```

`notification-position-example.css`

```css
```

**React** — `notification-position.tsx`

```tsx
<Button onClick={() => show('top-stretch')}>top-stretch</Button>
<Button onClick={() => show('top-start')}>top-start</Button>
<Button onClick={() => show('top-center')}>top-center</Button>
<Button onClick={() => show('top-end')}>top-end</Button>
<Button onClick={() => show('middle')}>middle</Button>
<Button onClick={() => show('bottom-start')}>bottom-start</Button>
<Button onClick={() => show('bottom-center')}>bottom-center</Button>
<Button onClick={() => show('bottom-end')}>bottom-end</Button>
<Button onClick={() => show('bottom-stretch')}>bottom-stretch</Button>
```

**Top End** ou **Bottom Start** sont recommandés pour la plupart des notifications. Ils sont discrets, mais restent visibles. **Middle** est la position la plus perturbatrice, et ne devrait être utilisée que pour des notifications importantes, telles que des erreurs. **Bottom End** est la position la moins intrusive, mais peut passer inaperçue. Les notifications **Stretch**, qui s’étendent sur toute la largeur du viewport, sont perturbatrices, et devraient être réservées aux notifications importantes dont le contenu nécessite plus d’espace.

Les applications avec un bouton de notification, ou un menu déroulant dans l’en-tête ou le pied de page, devraient positionner les notifications pour qu’elles apparaissent dans la même partie de l’écran. Pour une expérience utilisateur cohérente, utilisez une ou deux positions dans toute l’application. Évitez d’utiliser des positions qui pourraient obstruer des parties importantes de l’UI, telles que la navigation.

## <a id="empilement"></a>Empilement

Plusieurs notifications affichées simultanément sont empilées verticalement. L’ordre de celles-ci dépend toutefois de leur positionnement.

Lorsque la moitié inférieure de l’écran est utilisée comme position, une nouvelle notification apparaît sous les notifications plus anciennes. Avec la position définie sur la moitié supérieure, une nouvelle notification apparaît au-dessus des notifications existantes.

## <a id="taille"></a>Taille

Avec le thème Aura et les styles de base, les notifications utilisent une largeur fixe. La largeur ne dépasse jamais la largeur du viewport du navigateur. Vous pouvez modifier la largeur en utilisant la propriété personnalisée CSS `--vaadin-notification-width`.

Avec le thème Lumo, les notifications sont dimensionnées en fonction de leur contenu. Dans les grands viewports, la largeur maximale de la carte est d’un tiers du viewport. Dans les petits viewports (en dessous de 450px), la carte occupe toujours toute la largeur du viewport.

## <a id="éléments-interactifs"></a>Éléments interactifs

Les notifications peuvent contenir du contenu interactif (par exemple, des Buttons ou des liens) qui permettent à l’utilisateur d’effectuer des actions associées.

Par exemple, si une opération échoue, la notification d’erreur pourrait offrir à l’utilisateur la possibilité de réessayer. Ou elle pourrait contenir un lien vers une vue qui permet à l’utilisateur de résoudre le problème.

**Lit** — `notification-retry.ts`

```html
<!-- The duration is set to 0-sec to prevent the notification from auto-close. -->
<vaadin-notification
  theme="error"
  duration="0"
  position="middle"
  .opened="${this.notificationOpened}"
  @closed="${() => {
    this.notificationOpened = false;
  }}"
  ${notificationRenderer(this.renderer, [])}
></vaadin-notification>

<!-- ... -->

renderer: NotificationLitRenderer = () => html`
  <vaadin-horizontal-layout theme="spacing" style="align-items: center; min-width: 350px;">
    <div>Failed to generate report</div>
    <vaadin-button slot="end" @click="${this.close}">Retry</vaadin-button>
    <vaadin-button slot="end" theme="icon" @click="${this.close}" aria-label="Close">
      <vaadin-icon icon="lumo:cross"></vaadin-icon>
    </vaadin-button>
  </vaadin-horizontal-layout>
`;
```

**Flow** — `NotificationRetry.java`

```java
Notification notification = new Notification();
notification.addThemeVariants(NotificationVariant.ERROR);

// this is the default, 0 or negative means the Notification
// is not closed automatically
notification.setDuration(0);

// Now we can compose the content from components
Button retryButton = new RetryButton();
Button closeButton = new CloseButton();

HorizontalLayout layout = new HorizontalLayout(
        new Text("Failed to generate report"));
layout.addToEnd(retryButton, closeButton);
layout.setAlignItems(FlexComponent.Alignment.CENTER);
layout.setMinWidth("350px");
notification.add(layout);

notification.open();
```

**React** — `notification-retry.tsx`

```tsx
{/* The duration is set to 0-sec to prevent the notification from auto-close. */}
<Notification
  theme="error"
  duration={0}
  position="middle"
  opened={notificationOpened.value}
  onClosed={() => {
    notificationOpened.value = false;
  }}
>
  <HorizontalLayout theme="spacing" style={{ alignItems: 'center', minWidth: '350px' }}>
    <div>Failed to generate report</div>
    <Button slot="end" onClick={close}>
      Retry
    </Button>

    <Button slot="end" theme="icon" aria-label="Close" onClick={close}>
      <Icon icon="lumo:cross" />
    </Button>
  </HorizontalLayout>
</Notification>
```

Dans les situations où l’utilisateur pourrait vouloir annuler une action, affichez un bouton "Undo".

**Lit** — `notification-undo.ts`

```html
<vaadin-notification
  duration="10000"
  position="middle"
  .opened="${this.notificationOpened}"
  @closed="${() => {
    this.notificationOpened = false;
  }}"
  ${notificationRenderer(this.renderer, [])}
></vaadin-notification>

<!-- ... -->

renderer: NotificationLitRenderer = () => html`
  <vaadin-horizontal-layout theme="spacing" style="align-items: center; min-width: 300px">
    <div>5 tasks deleted</div>
    <vaadin-button slot="end" @click="${this.close}">Undo</vaadin-button>
    <vaadin-button slot="end" theme="icon" aria-label="Close" @click="${this.close}">
      <vaadin-icon icon="lumo:cross"></vaadin-icon>
    </vaadin-button>
  </vaadin-horizontal-layout>
`;
```

**Flow** — `NotificationUndo.java`

```java
Notification notification = new Notification();
notification.setDuration(10000);

Button undoButton = new UndoButton();
undoButton.addClickListener(event -> {
    // In this example we just close the Notification
    notification.close();
});

HorizontalLayout layout = new HorizontalLayout(
        new Text("5 tasks deleted"));
layout.addToEnd(undoButton, new CloseButton());
layout.setAlignItems(Alignment.CENTER);
layout.setMinWidth("300px");
notification.add(layout);

notification.open();
```

**React** — `notification-undo.tsx`

```tsx
<Notification
  duration={10000}
  position="middle"
  opened={notificationOpened.value}
  onClosed={() => {
    notificationOpened.value = false;
  }}
>
  <HorizontalLayout theme="spacing" style={{ alignItems: 'center', minWidth: '300px' }}>
    <div>5 tasks deleted</div>
    <Button slot="end" onClick={close}>
      Undo
    </Button>

    <Button slot="end" theme="icon" aria-label="Close" onClick={close}>
      <Icon icon="lumo:cross" />
    </Button>
  </HorizontalLayout>
</Notification>
```

Les notifications peuvent également contenir des liens vers des informations pertinentes.

**Lit** — `notification-link.ts`

```html
<!-- The duration is set to 0-sec to prevent the notification from auto-close. -->
<vaadin-notification
  duration="0"
  position="middle"
  .opened="${this.notificationOpened}"
  @closed="${() => {
    this.notificationOpened = false;
  }}"
  ${notificationRenderer(this.renderer, [])}
></vaadin-notification>

<!-- ... -->

renderer: NotificationLitRenderer = () => html`
  <vaadin-horizontal-layout theme="spacing" style="align-items: center;">
    <div>Jason Bailey mentioned you in <a href="#">Project Q4</a></div>
    <vaadin-button slot="end" theme="tertiary" aria-label="Close" @click="${this.close}">
      <vaadin-icon icon="lumo:cross"></vaadin-icon>
    </vaadin-button>
  </vaadin-horizontal-layout>
`;
```

**Flow** — `NotificationLink.java`

```java
// When creating a notification using the constructor,
// the duration is 0-sec by default which means that
// the notification does not close automatically.
Notification notification = new Notification();

Div text = new Div(new Text("Jason Bailey mentioned you in "),
        new Anchor("#", "Project Q4"));

Button closeButton = new Button(new Icon("lumo", "cross"));
closeButton.addThemeVariants(ButtonVariant.TERTIARY);
closeButton.setAriaLabel("Close");
closeButton.addClickListener(event -> {
    notification.close();
});

HorizontalLayout layout = new HorizontalLayout(text);
layout.addToEnd(closeButton);
layout.setAlignItems(Alignment.CENTER);

notification.add(layout);
notification.open();
```

**React** — `notification-link.tsx`

```tsx
{/* The duration is set to 0-sec to prevent the notification from auto-close. */}
<Notification
  duration={0}
  position="middle"
  opened={notificationOpened.value}
  onClosed={() => {
    notificationOpened.value = false;
  }}
>
  <HorizontalLayout theme="spacing" style={{ alignItems: 'center' }}>
    <div>
      Jason Bailey mentioned you in <a href="#">Project Q4</a>
    </div>

    <Button slot="end" theme="tertiary" aria-label="Close" onClick={close}>
      <Icon icon="lumo:cross" />
    </Button>
  </HorizontalLayout>
</Notification>
```

### <a id="accessible-au-clavier"></a>Accessible au clavier

Assurez-vous que les utilisateurs au clavier uniquement puissent accéder aux éléments interactifs dans les notifications.

Rendez la notification persistante pour éviter qu’elle ne disparaisse avant que l’utilisateur ait eu la possibilité de réagir. Fournissez un raccourci clavier — soit pour déclencher l’action elle-même, soit pour déplacer le focus vers la carte de notification — dans les cas où plusieurs éléments interactifs sont présents. Enfin, rendez le raccourci repérable, par exemple, en l’affichant comme partie du contenu de la notification.

**Lit** — `notification-keyboard-a11y.ts`

```typescript
protected override render() {
  return html`
    <vaadin-notification
      duration="10000"
      position="middle"
      .opened="${this.notificationOpened}"
      @closed="${() => {
        this.notificationOpened = false;
      }}"
      ${notificationRenderer(this.renderer, [])}
    ></vaadin-notification>
  `;
}

renderer: NotificationLitRenderer = () => html`
  <vaadin-horizontal-layout style="align-items: center; min-width: 300px;">
    <div>5 tasks deleted</div>
    <vaadin-button slot="end" @click="${this.close}">
      Undo
      <!-- Ideally, this should be hidden if the
               device does not have a physical keyboard -->
      ${this.isMac ? '⌘' : 'Ctrl-'}Z
    </vaadin-button>
  </vaadin-horizontal-layout>
`;

connectedCallback() {
  super.connectedCallback();

  document.addEventListener('keydown', this.onKeyDown);
}

disconnectedCallback() {
  super.disconnectedCallback();

  document.removeEventListener('keydown', this.onKeyDown);
}

onKeyDown = (event: KeyboardEvent) => {
  if (this.notificationOpened && (event.metaKey || event.ctrlKey) && event.key === 'z') {
    // Handle your custom undo logic here
    // Avoid triggering the native undo action
    event.preventDefault();
    this.close();
  }
};
```

**Flow** — `NotificationKeyboardA11y.java`

```java
public Notification show() {
    Notification notification = new Notification();
    notification.setDuration(10000);

    Div statusText = new Div(new Text("5 tasks deleted"));

    HorizontalLayout layout = new HorizontalLayout(statusText);
    layout.addToEnd(new CloseButtonWithShortcutHint());
    layout.setMinWidth("300px");
    layout.setAlignItems(Alignment.CENTER);

    notification.add(layout);
    notification.open();

    return notification;
}

// ...

public void setupUndoShortcut(Notification notification) {
    Shortcuts.addShortcutListener(notification, notification::close,
            Key.of("z"), KeyModifier.META);
    Shortcuts.addShortcutListener(notification, notification::close,
            Key.of("z"), KeyModifier.CONTROL);
}
```

**React** — `notification-keyboard-a11y.tsx`

```tsx
useEffect(() => {
  const onKeyDown = (event: KeyboardEvent) => {
    if (notificationOpened.value && (event.metaKey || event.ctrlKey) && event.key === 'z') {
      event.preventDefault();
      close();
    }
  };

  document.addEventListener('keydown', onKeyDown);

  return () => {
    document.removeEventListener('keydown', onKeyDown);
  };
}, [notificationOpened.value]);

return (
  <>
    <Button disabled={notificationOpened.value} onClick={open}>
      Show notification
    </Button>

    <Notification
      duration={10000}
      position="middle"
      opened={notificationOpened.value}
      onClosed={() => {
        notificationOpened.value = false;
      }}
    >
      <HorizontalLayout style={{ alignItems: 'center', minWidth: '300px' }}>
        <div>5 tasks deleted</div>
        <Button slot="end" onClick={close}>
          Undo
          {isMac ? '⌘' : 'Ctrl-'}Z
        </Button>
      </HorizontalLayout>
    </Notification>
  </>
);
```

## <a id="icônes-autre-mise-en-forme-enrichie"></a>Icônes & autre mise en forme enrichie

Les icônes et d’autres mises en forme de contenu peuvent être utilisées pour fournir des informations et des repères visuels utiles. Par exemple, vous pourriez faire cela pour rendre les notifications d’erreur et de succès plus faciles à distinguer pour les utilisateurs atteints de daltonisme.

**Lit** — `notification-rich.ts`

```html
<!-- The duration is set to 0-sec to prevent the notification from auto-close. -->
<vaadin-notification
  duration="0"
  ${notificationRenderer(
    () => html`
      <vaadin-horizontal-layout
        theme="spacing"
        style="align-items: center; min-width: 350px;"
      >
        <vaadin-icon icon="vaadin:check-circle"></vaadin-icon>
        <div>Application submitted!</div>
        <vaadin-button slot="end">View</vaadin-button>
        <vaadin-button slot="end" theme="icon" aria-label="Close">
          <vaadin-icon icon="lumo:cross"></vaadin-icon>
        </vaadin-button>
      </vaadin-horizontal-layout>
    `,
    []
  )}
  theme="success"
  position="middle"
></vaadin-notification>

<vaadin-notification
  duration="0"
  ${notificationRenderer(
    () => html`
      <vaadin-horizontal-layout
        theme="spacing"
        style="align-items: center; min-width: 350px;"
      >
        <vaadin-icon icon="vaadin:warning"></vaadin-icon>
        <div>Failed to generate report</div>
        <vaadin-button slot="end">Retry</vaadin-button>
        <vaadin-button slot="end" theme="icon" aria-label="Close">
          <vaadin-icon icon="lumo:cross"></vaadin-icon>
        </vaadin-button>
      </vaadin-horizontal-layout>
    `,
    []
  )}
  theme="error"
  position="middle"
></vaadin-notification>

<vaadin-notification
  duration="0"
  ${notificationRenderer(
    () => html`
      <vaadin-horizontal-layout
        theme="spacing"
        style="align-items: center; min-width: 350px;"
      >
        <vaadin-avatar name="Jason Bailey"></vaadin-avatar>
        <div><b>Jason Bailey</b> mentioned you in <a href="#">Project Q4</a></div>
        <vaadin-button slot="end" theme="icon" aria-label="Close">
          <vaadin-icon icon="lumo:cross"></vaadin-icon>
        </vaadin-button>
      </vaadin-horizontal-layout>
    `,
    []
  )}
  position="middle"
></vaadin-notification>
```

**Flow** — `NotificationRich.java`

```java
public Notification createSubmitSuccess() {
    Notification notification = new Notification();
    notification.addThemeVariants(NotificationVariant.SUCCESS);

    Icon icon = VaadinIcon.CHECK_CIRCLE.create();

    Button viewBtn = new Button("View");

    HorizontalLayout layout = new HorizontalLayout(icon,
            new Text("Application submitted!"));
    layout.addToEnd(viewBtn, createCloseBtn());
    layout.setAlignItems(FlexComponent.Alignment.CENTER);
    layout.setMinWidth("350px");

    notification.add(layout);

    return notification;
}

public Notification createReportError() {
    Notification notification = new Notification();
    notification.addThemeVariants(NotificationVariant.ERROR);

    Icon icon = VaadinIcon.WARNING.create();
    Button retryBtn = new Button("Retry");

    HorizontalLayout layout = new HorizontalLayout(icon,
            new Text("Failed to generate report!"));
    layout.addToEnd(retryBtn, createCloseBtn());
    layout.setAlignItems(FlexComponent.Alignment.CENTER);
    layout.setMinWidth("350px");

    notification.add(layout);

    return notification;
}

public Notification createMentionNotification() {
    Notification notification = new Notification();

    Avatar avatar = new Avatar("Jason Bailey");

    Span name = new Span("Jason Bailey");
    name.getStyle().set("font-weight", "500");

    Div info = new Div(name, new Text(" mentioned you in "),
            new Anchor("#", "Project Q4"));

    HorizontalLayout layout = new HorizontalLayout(avatar, info);
    layout.addToEnd(createCloseBtn());
    layout.setAlignItems(FlexComponent.Alignment.CENTER);
    layout.setMinWidth("350px");

    notification.add(layout);

    return notification;
}

public static Button createCloseBtn() {
    Button closeBtn = new Button(VaadinIcon.CLOSE_SMALL.create());

    return closeBtn;
}
```

**React** — `notification-rich.tsx`

```tsx
{/* The duration is set to 0-sec to prevent the notification from auto-close. */}
<Notification duration={0} theme="success" position="middle" opened>
  <HorizontalLayout theme="spacing" style={{ alignItems: 'center', minWidth: '350px' }}>
    <Icon icon="vaadin:check-circle" />
    <div>Application submitted!</div>
    <Button slot="end">View</Button>
    <Button slot="end" theme="icon" aria-label="Close">
      <Icon icon="lumo:cross" />
    </Button>
  </HorizontalLayout>
</Notification>

<Notification duration={0} theme="error" position="middle" opened>
  <HorizontalLayout theme="spacing" style={{ alignItems: 'center', minWidth: '350px' }}>
    <Icon icon="vaadin:warning" />
    <div>Failed to generate report</div>
    <Button slot="end">Retry</Button>
    <Button slot="end" theme="icon" aria-label="Close">
      <Icon icon="lumo:cross" />
    </Button>
  </HorizontalLayout>
</Notification>

<Notification duration={0} position="middle" opened>
  <HorizontalLayout theme="spacing" style={{ alignItems: 'center', minWidth: '350px' }}>
    <Avatar name="Jason Bailey" />
    <div>
      <b>Jason Bailey</b> mentioned you in <a href="#">Project Q4</a>
    </div>
    <Button slot="end" theme="icon" aria-label="Close">
      <Icon icon="lumo:cross" />
    </Button>
  </HorizontalLayout>
</Notification>
```

## <a id="helper-statique"></a>Helper statique

Pour des notifications simples, ponctuelles, il est pratique d’utiliser la méthode helper statique `show()`. Le helper gère le cycle de vie de la notification, et l’ajoute et la supprime du DOM, automatiquement.

**Flow**

```java
// Afficher une notification simple basée sur du texte
Notification notification = Notification.show("Financial report generated");
notification.setPosition(Notification.Position.MIDDLE);
```

**React**

```tsx
import { Notification } from '@vaadin/react-components';

// Show a simple text-based notification
Notification.show('Financial report generated', {
  position: 'middle',
});
```

**Lit**

```typescript
import { html } from 'lit';
import { Notification } from '@vaadin/notification';

// Show a simple text-based notification
Notification.show('Financial report generated', {
  position: 'middle',
});

// Show a notification with markup using a Lit template
Notification.show(
  html`
    <b>@John:</b>
    &nbsp;
    <span>
      How about lunch at
      <i>12:30pm</i>?
    </span>
  `,
  { position: 'middle' }
);
```

## <a id="bonnes-pratiques"></a>Bonnes pratiques

### <a id="utiliser-avec-parcimonie"></a>Utiliser avec parcimonie

Les notifications sont perturbatrices par conception et devraient être utilisées avec parcimonie. Utilisez moins de notifications en les réservant aux informations plus importantes qui pourraient autrement passer inaperçues pour l’utilisateur.

Les notifications moins urgentes peuvent être fournies via un lien ou un menu déroulant dans l’en-tête ou le pied de page de l’application, au lieu de notifications immédiates.

**Lit** — `notification-popup.ts`

```typescript
protected override render() {
  return html`
    <vaadin-button id="target" aria-label="notifications" theme="tertiary icon">
      <vaadin-icon icon="lumo:bell"></vaadin-icon>
      <vaadin-badge number="4" theme="error filled"></vaadin-badge>
    </vaadin-button>
    <vaadin-popover for="target">
      <div>Show notifications here</div>
    </vaadin-popover>
  `;
}
```

**Flow** — `NotificationPopup.java`

```java
var bellBtn = new MessagesButton();
bellBtn.setUnreadMessages(4);
bellBtn.setAriaLabel("notifications");

Popover popover = new Popover();
popover.setTarget(bellBtn);
Div content = new Div("Show notifications here");
popover.add(content);
```

**React** — `notification-popup.tsx`

```tsx
<>
  <Button id="target" aria-label="notifications" theme="tertiary icon">
    <Icon icon="lumo:bell" />
    <Badge
      number={4}
      theme="error filled"
      style={{ position: 'absolute', transform: 'translate(-40%, -30%)' }}
    />
  </Button>
  <Popover for="target">
    <div>Show notifications here</div>
  </Popover>
</>
```

### <a id="limiter-la-longueur-du-contenu"></a>Limiter la longueur du contenu

Les notifications devraient être brèves et aller droit au but. Essayez de limiter le contenu à une ou deux lignes. Plus d’informations peuvent être fournies via un lien intégré ou un Button.

Afficher un aperçu d’un contenu plus long, et créer un lien vers les détails complets.

`notification-content-length-do.ts`

```typescript
import '@vaadin/button';
import '@vaadin/horizontal-layout';
import '@vaadin/icon';
import '@vaadin/notification';
import '@vaadin/vaadin-lumo-styles/vaadin-iconset';
import { html, LitElement } from 'lit';
import { applyTheme } from 'Frontend/demo/theme';

export class Example extends LitElement {
  protected override createRenderRoot() {
    const root = super.createRenderRoot();
    applyTheme(root);
    return root;
  }

  protected override render() {
    return html`
      <vaadin-notification-card slot="middle">
        <vaadin-horizontal-layout theme="spacing" style="align-items: center;">
          <div>
            <div>Aria Bailey</div>
            <div style="font-size: 0.875rem; color: var(--vaadin-text-color-secondary);">
              Yeah, I know. But could you help me with...
            </div>
          </div>
          <vaadin-button slot="end">View</vaadin-button>
          <vaadin-button slot="end" theme="icon">
            <vaadin-icon icon="lumo:cross"></vaadin-icon>
          </vaadin-button>
        </vaadin-horizontal-layout>
      </vaadin-notification-card>
    `;
  }
}
```

Ne pas afficher tous les détails dans la notification.

`notification-content-length-dont.ts`

```typescript
import '@vaadin/button';
import '@vaadin/horizontal-layout';
import '@vaadin/icon';
import '@vaadin/notification';
import '@vaadin/vaadin-lumo-styles/vaadin-iconset';
import { html, LitElement } from 'lit';
import { applyTheme } from 'Frontend/demo/theme';

export class Example extends LitElement {
  protected override createRenderRoot() {
    const root = super.createRenderRoot();
    applyTheme(root);
    return root;
  }

  protected override render() {
    return html`
      <vaadin-notification-card slot="middle">
        <vaadin-horizontal-layout theme="spacing" style="align-items: center;">
          <div>
            <div>New message from Aria Bailey</div>
            <div style="font-size: 0.875rem; color: var(--vaadin-text-color-secondary);">
              Yeah, I know. But could you help me with this. I’m not sure where the bug is in my
              CSS? The checkmark doesn’t get the right color. I’m trying to use the CSS custom
              properties from our design system, but for some reason it’s not working.
            </div>
          </div>
          <vaadin-button slot="end" theme="icon">
            <vaadin-icon icon="lumo:cross"></vaadin-icon>
          </vaadin-button>
        </vaadin-horizontal-layout>
      </vaadin-notification-card>
    `;
  }
}
```

## <a id="composants-associés"></a>Composants associés

| Component                                                        | Recommandation d’utilisation                                                                                             |
| ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| [Dialog](https://vaadin.com/docs/latest/fr/components/dialog.md) | Dialog devrait être utilisé à la place de Notification pour tout ce qui nécessite une action immédiate de l’utilisateur. |

`77E15AD0-F634-4D81-8C4D-FAC7A21D889B`
