Notification center
A bell with an unread count that opens a panel of notifications, which the app keeps in its own list.
Example
<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.
<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>import { NotificationCenter } from '@focsd-dev/react';
export function Example() { return <NotificationCenter onToggle={(e) => console.log(e.target)}></NotificationCenter>;}<script setup>import '@focsd-dev/components/focsd-notification-center.js';</script>
<template> <focsd-notification-center @toggle="onChange"></focsd-notification-center></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-notification-center.js';
// template<focsd-notification-center (toggle)="onChange($event)"></focsd-notification-center><script> import '@focsd-dev/components/focsd-notification-center.js';</script>
<focsd-notification-center ontoggle={(e) => console.log(e.target)}></focsd-notification-center>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
label | label | string | — |
open | open | boolean | false |
max | max | number | 99 |
loaded | loaded | boolean | false |
Methods
| Method | Description |
|---|---|
show() | Open the panel and move focus to its heading. |
hide() | Close the panel. |
Events
| Event | Description |
|---|---|
toggle | Fired when the panel opens or closes; read open. Does not bubble. |
Slots
| Slot | Description |
|---|---|
(default) | focsd-notification elements, read as data. |
CSS parts
Style the inside of the component with ::part(), for example focsd-notification-center::part(trigger).
| Part | Description |
|---|---|
trigger | The bell button. |
icon | The bell icon. |
badge | The unread count on the bell; hidden from assistive technology (the button's name has it). |
panel | The dialog. |
heading | The dialog's heading. |
mark-all | The "Mark all as read" button, shown while any notification is unread. |
list | The list of notifications. |
item | One notification. |
item-unread | An unread notification (with `item`). |
dot | The unread mark of an unread notification. |
tone | The icon that shows a critical, caution or positive notification's tone (a shape, so it is never only a color). |
title | A notification's title (a link when it has `href`). |
body | A notification's text. |
time | A notification's relative time. |
dismiss | A notification's Dismiss button. |
empty | The 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
timeelement. - 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
loadedonce 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(withids) andfocsd-dismiss(withid); answer by settingnotificationsagain. Nothing changes on its own. - A notification with
hrefmakes 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#fragmenthrefs become links. Any other (such asjavascript:ordata:) 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
toneis 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
| Key | Action |
|---|---|
| Enter / Space | Open or close the panel from the bell |
| Tab | Move through Mark all as read, links and Dismiss buttons |
| Escape | Close the panel and return focus to the bell |
From markup
focsd-notificationdraws nothing itself: its attributes (title,body,time,tone,href,read) are the data the center reads.maxcaps the badge: withmax="9"ten or more unread show as "9+", and the button name still says the real count.
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.