Skip to content
Focsd homeFocsd homeFocsd
Forms

Notification center

A bell with an unread count that opens a panel of notifications, which the app keeps in its own list.

  • Tag: focsd-notification-center
  • Pattern: Non-modal popover dialog + list
  • Category: Overlays

Example

Add a notification

HTML
<div class="row">
<focsd-notification-center id="notify-demo"></focsd-notification-center>
<focsd-button id="notify-demo-add">Add a notification</focsd-button>
</div>
<p id="notify-demo-log" aria-live="off"></p>
<script type="module">
const center = document.getElementById('notify-demo');
const log = document.getElementById('notify-demo-log');
const ago = (minutes) => new Date(Date.now() - minutes * 60000).toISOString();
center.notifications = [
{ id: 'build', title: 'Build 482 passed', body: 'main is green again.', time: ago(2), href: '#builds', tone: 'positive' },
{ id: 'comment', title: 'Ana commented on Pricing', body: 'Can we ship the annual plan first?', time: ago(45) },
{ id: 'payment', title: 'Payment failed', body: 'Card ending 4242 was declined.', time: ago(180), tone: 'critical' },
{ id: 'report', title: 'Weekly report ready', time: ago(1560), read: true },
];
center.addEventListener('focsd-read', (event) => {
const ids = new Set(event.detail.ids);
center.notifications = center.notifications.map((n) => (ids.has(n.id) ? { ...n, read: true } : n));
log.textContent = 'Read: ' + event.detail.ids.join(', ');
});
center.addEventListener('focsd-dismiss', (event) => {
center.notifications = center.notifications.filter((n) => n.id !== event.detail.id);
log.textContent = 'Dismissed: ' + event.detail.id;
});
let added = 0;
document.getElementById('notify-demo-add').addEventListener('click', () => {
added += 1;
center.notifications = [{ id: 'new-' + added, title: 'New sign-up ' + added, time: new Date().toISOString() }, ...center.notifications];
});
</script>

From markup

Slotted focsd-notification elements are read as data, for a list that is written in HTML.

HTML
<focsd-notification-center label="Alerts" max="9">
<focsd-notification
id="alert-disk"
title="Disk almost full"
body="92% of 500 GB used."
tone="caution"
time="2026-11-25T08:00:00Z"></focsd-notification>
<focsd-notification
id="alert-backup"
title="Backup finished"
tone="positive"
time="2026-11-24T22:15:00Z"
read></focsd-notification>
</focsd-notification-center>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-notification-center.js';
</script>
<focsd-notification-center></focsd-notification-center>

API

Attributes

AttributePropertyTypeDefault
labellabelstring—
openopenbooleanfalse
maxmaxnumber99
loadedloadedbooleanfalse

Methods

MethodDescription
show()Open the panel and move focus to its heading.
hide()Close the panel.

Events

EventDescription
toggleFired when the panel opens or closes; read open. Does not bubble.

Slots

SlotDescription
(default)focsd-notification elements, read as data.

CSS parts

Style the inside of the component with ::part(), for example focsd-notification-center::part(trigger).

PartDescription
triggerThe bell button.
iconThe bell icon.
badgeThe unread count on the bell; hidden from assistive technology (the button's name has it).
panelThe dialog.
headingThe dialog's heading.
mark-allThe "Mark all as read" button, shown while any notification is unread.
listThe list of notifications.
itemOne notification.
item-unreadAn unread notification (with `item`).
dotThe unread mark of an unread notification.
toneThe icon that shows a critical, caution or positive notification's tone (a shape, so it is never only a color).
titleA notification's title (a link when it has `href`).
bodyA notification's text.
timeA notification's relative time.
dismissA notification's Dismiss button.
emptyThe text shown when there are no notifications.

Accessibility

  • The bell is a button named "Notifications, 3 unread" (the count is in its name, and the visible badge is hidden from assistive technology). With label="Alerts" it reads "Alerts, 3 unread".
  • It opens a non-modal panel: the page stays usable, Escape closes it and returns focus to the bell, and a click outside closes it too.
  • The list is a real list. An unread item has a visible dot and a visually hidden "unread" before its title, so unread is never only a color. The time reads as relative text ("2 minutes ago") and the exact time is in a time element.
  • New notifications that arrive while the page is open are announced politely, together, after a 2 second window ("2 new notifications"), so a burst does not interrupt a screen reader. The first list is never announced; if the center starts empty and fills from a fetch, set loaded once that list is in, so the first notification to arrive after it is announced too.
  • The app owns the data. The center fires focsd-read (with ids) and focsd-dismiss (with id); answer by setting notifications again. Nothing changes on its own.
  • A notification with href makes its title a link, and following it marks it read. "Mark all as read" covers the rest. Without notifications the panel says so.
  • Only http:, https:, mailto:, relative and #fragment hrefs become links. Any other (such as javascript: or data:) is dropped and the title shows as plain text, so a list from a server or from users cannot run script. Titles and bodies are always text, never markup.
  • A tone is also a shape and a word: critical, caution and positive notifications show an icon and are read as "Error", "Warning" or "Success" before the title. The color bar is only a bonus.
  • The first list the center shows is never announced as new: set the notifications once they load, and only later arrivals are announced (one message per two seconds).
  • On narrow screens the panel is fixed to the bottom of the viewport so it never runs off the edge. It is not a draggable sheet.

Keyboard

KeyAction
Enter / SpaceOpen or close the panel from the bell
TabMove through Mark all as read, links and Dismiss buttons
EscapeClose the panel and return focus to the bell

From markup

  • focsd-notification draws nothing itself: its attributes (title, body, time, tone, href, read) are the data the center reads.
  • max caps the badge: with max="9" ten or more unread show as "9+", and the button name still says the real count.