Skip to content

Conversation

@sissbruecker
Copy link
Contributor

@sissbruecker sissbruecker commented Dec 11, 2025

Description

Adds a dashboard-item-before-remove event that can be canceled to prevent automatic removal of an item or section. This gives manual control over the removal, for example to show a confirmation dialog. The event provides the relevant item or section that should be removed, and optionally the section in which the item is in, which then allows to programmatically remove the item after a confirmation.

Example usage:

dashboard.addEventListener('dashboard-item-before-remove', async (e) => {
  e.preventDefault();

  const item = e.detail.item;

  const dialog = document.createElement('vaadin-confirm-dialog');
  dialog.header = 'Remove Widget';
  dialog.message = `Are you sure you want to remove "${item.title}"?`;
  dialog.confirmText = 'Remove';
  dialog.confirmTheme = 'error primary';
  dialog.cancelButtonVisible = true;
  dialog.opened = true;

  document.body.appendChild(dialog);

  dialog.addEventListener('confirm', () => {
    const { item, section } = e.detail;
    if (section) {
      section.items = section.items.filter((i) => i !== item);
      dashboard.items = [...dashboard.items];
    } else {
      dashboard.items = dashboard.items.filter((i) => i !== item);
    }
    dialog.remove();
  });

  dialog.addEventListener('cancel', () => {
    dialog.remove();
  });
});

Part of vaadin/flow-components#8257

Type of change

  • Feature

@sonarqubecloud
Copy link

@sissbruecker sissbruecker merged commit 1b75f31 into main Dec 17, 2025
9 checks passed
@sissbruecker sissbruecker deleted the feat/dashboard-before-remove-event branch December 17, 2025 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants