Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions demo/e2e/screenshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const routes = [
...typesPath({ path: '/main/index/action-sheet', name: 'action-sheet' }, actionSheetTypes),
...typesPath({ path: '/main/index/alert', name: 'alert' }, alertTypes),
{ path: '/main/index/button', name: 'button' },
{ path: '/main/index/toolbar-badge', name: 'toolbar-badge' },
{ path: '/main/index/checkbox', name: 'checkbox' },
{ path: '/main/index/range', name: 'range' },
...typesPath({ path: '/main/index/toast', name: 'toast' }, toastTypes),
Expand Down Expand Up @@ -61,6 +62,16 @@ const prepareScreenShot = async (page: Page, routeName: string) => {
)
.toBe(true);

if (routeName === 'toolbar-badge') {
// Keep both directions and the unaffected-control examples in one image.
await page.setViewportSize({ width: 1200, height: 1000 });
// LTR holds an actual glass-group press; RTL retains the resting group.
const pressed = page.locator('app-toolbar-badge [data-badge-group] ion-button').first();
await pressed.hover();
await page.mouse.down();
await pressed.evaluate((button) => button.classList.add('ion-activated'));
return;
}
if (!routeName.includes(':')) {
const scrollHeight = await page.locator('ion-content[role="main"]').evaluate(async (el: any) => {
const scrollEl = await el.getScrollElement();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion demo/src/app/docs/docs-content.generated.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demo/src/app/docs/docs-page.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('DocsPage', () => {
expect(element.querySelector('article.docs-content h1')?.textContent).toContain('Special markup and classes');
expect(element.querySelectorAll('.code-block-container pre.shiki code').length).toBeGreaterThan(0);
expect(element.querySelector('.code-block-container code span[style*="color"]')).not.toBeNull();
expect(element.querySelectorAll('figure.docs-example').length).toBe(7);
expect(element.querySelectorAll('figure.docs-example').length).toBe(9);
const classicSearchPreview = element.querySelector('figure.docs-example > .ion-page');
expect(classicSearchPreview?.querySelector('ion-content ion-list[inset="true"] > ion-item-group > ion-item')).not.toBeNull();
expect(classicSearchPreview?.textContent).toContain('Recent item 10');
Expand Down
1 change: 1 addition & 0 deletions demo/src/app/index/index-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class IndexPageComponent {
{ name: 'toast', enable: true },
{ name: 'toggle', enable: true },
{ name: 'toolbar', enable: true },
{ name: 'toolbar-badge', enable: true },
]);
readonly enableComponents = computed(() => this.components().filter((c) => c.enable));
readonly disableComponents = computed(() => this.components().filter((c) => !c.enable));
Expand Down
4 changes: 4 additions & 0 deletions demo/src/app/index/index.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const routes: Routes = [
path: 'alert',
loadComponent: () => import('./pages/alert/alert.page').then((m) => m.AlertPage),
},
{
path: 'toolbar-badge',
loadComponent: () => import('./pages/toolbar-badge/toolbar-badge.page').then((m) => m.ToolbarBadgePage),
},
{
path: 'button',
loadComponent: () => import('./pages/button/button.page').then((m) => m.ButtonPage),
Expand Down
95 changes: 95 additions & 0 deletions demo/src/app/index/pages/toolbar-badge/toolbar-badge.page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<ion-header>
<ion-toolbar
><ion-buttons slot="start"><ion-back-button defaultHref="/main/index"></ion-back-button></ion-buttons
><ion-title>Toolbar badges</ion-title></ion-toolbar
>
</ion-header>
<ion-content>
<div class="badge-examples">
@for (direction of directions; track direction) {
<section [attr.dir]="direction">
<h2>{{ direction.toUpperCase() }}</h2>
<p>Empty / 3 / 99+ / no badge</p>
<h3>Standalone buttons</h3>
<ion-toolbar>
@for (value of badges; track value) {
<ion-button slot="end" aria-label="Notifications"
><ion-icon slot="icon-only" [icon]="more"></ion-icon><ion-badge>{{ value }}</ion-badge></ion-button
>
}
<ion-button slot="end" aria-label="More"><ion-icon slot="icon-only" [icon]="more"></ion-icon></ion-button>
</ion-toolbar>
<h3>Grouped buttons</h3>
<ion-toolbar>
<ion-buttons slot="end" data-badge-group>
@for (value of badges; track value) {
<ion-button aria-label="Notifications"
><ion-icon slot="icon-only" [icon]="more"></ion-icon><ion-badge>{{ value }}</ion-badge></ion-button
>
}
<ion-button aria-label="More"><ion-icon slot="icon-only" [icon]="more"></ion-icon></ion-button>
</ion-buttons>
</ion-toolbar>
<h3>Single group / menu group</h3>
<ion-toolbar>
<ion-buttons slot="start"
><ion-button aria-label="Notifications"
><ion-icon slot="icon-only" [icon]="more"></ion-icon><ion-badge>3</ion-badge></ion-button
></ion-buttons
>
<ion-buttons slot="end"
><ion-menu-button [autoHide]="false"></ion-menu-button
><ion-button aria-label="Notifications"
><ion-icon slot="icon-only" [icon]="more"></ion-icon><ion-badge>3</ion-badge></ion-button
></ion-buttons
>
</ion-toolbar>
<h3>Custom color / hidden / CSS class / opt-out</h3>
<ion-toolbar>
<ion-buttons slot="start"
><ion-button aria-label="Notifications"
><ion-icon slot="icon-only" [icon]="more"></ion-icon><ion-badge color="success">3</ion-badge></ion-button
><ion-button aria-label="Notifications"
><ion-icon slot="icon-only" [icon]="more"></ion-icon><ion-badge hidden>3</ion-badge></ion-button
>
<ion-button aria-label="Notifications hidden by CSS"
><ion-icon slot="icon-only" [icon]="more"></ion-icon><ion-badge class="badge-off">3</ion-badge></ion-button
>
<ion-button aria-label="Unread indicator hidden by CSS"
><ion-icon slot="icon-only" [icon]="more"></ion-icon><ion-badge class="badge-off"></ion-badge
></ion-button>
</ion-buttons>
<ion-buttons slot="end" class="ios-theme-disabled"
><ion-button aria-label="Notifications"
><ion-icon slot="icon-only" [icon]="more"></ion-icon><ion-badge>3</ion-badge></ion-button
></ion-buttons
>
</ion-toolbar>
<h3>Web rail clones (outside toolbar)</h3>
<div class="badge-clone-row">
@for (value of badges; track value) {
<ion-button class="ios-theme-vertical-bars-toolbar-projection ion-cloned-element" aria-label="Projected notifications"
><ion-icon slot="icon-only" [icon]="more"></ion-icon
><ion-badge data-native-ui-badge-overlay>{{ value }}</ion-badge></ion-button
>
}
<ion-buttons class="ios-theme-vertical-bars-toolbar-projection ion-cloned-element">
@for (value of badges; track value) {
<ion-button class="ios-theme-vertical-bars-toolbar-action ion-cloned-element" aria-label="Projected notifications"
><ion-icon slot="icon-only" [icon]="more"></ion-icon
><ion-badge data-native-ui-badge-overlay>{{ value }}</ion-badge></ion-button
>
}
</ion-buttons>
</div>
<h3>Outside toolbar / nested badge</h3>
<ion-button aria-label="Notifications"><ion-icon slot="icon-only" [icon]="more"></ion-icon><ion-badge>3</ion-badge></ion-button>
<ion-toolbar
><ion-button
><span>Nested <ion-badge>3</ion-badge></span></ion-button
></ion-toolbar
>
</section>
}
</div>
</ion-content>
33 changes: 33 additions & 0 deletions demo/src/app/index/pages/toolbar-badge/toolbar-badge.page.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.badge-examples {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 24px;
padding: 24px;
}

h2 {
margin: 0 0 12px;
font-size: 20px;
}

h3 {
margin: 20px 0 8px;
font-size: 14px;
}

@media (max-width: 700px) {
.badge-examples {
grid-template-columns: 1fr;
}
}

.badge-off {
display: none;
}

.badge-clone-row {
display: flex;
align-items: center;
gap: 8px;
min-height: 68px;
}
28 changes: 28 additions & 0 deletions demo/src/app/index/pages/toolbar-badge/toolbar-badge.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import {
IonBadge,
IonBackButton,
IonButton,
IonButtons,
IonContent,
IonHeader,
IonIcon,
IonMenuButton,
IonTitle,
IonToolbar,
} from '@demo/ionic';
import { ellipsisHorizontal } from 'ionicons/icons';

@Component({
selector: 'app-toolbar-badge',
standalone: true,
imports: [IonBadge, IonBackButton, IonButton, IonButtons, IonContent, IonHeader, IonIcon, IonMenuButton, IonTitle, IonToolbar],
templateUrl: './toolbar-badge.page.html',
styleUrls: ['./toolbar-badge.page.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ToolbarBadgePage {
readonly more = ellipsisHorizontal;
readonly directions = ['ltr', 'rtl'] as const;
readonly badges = ['', '3', '99+'];
}
48 changes: 48 additions & 0 deletions docs/special-markup.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,54 @@ Solid primary submit buttons use `--ion-color-primary-brightness` for their fore

Use `.button-submit` when the button needs the same treatment but cannot use `type="submit"`.

## Toolbar button badges

Place `ion-badge` directly inside an `ion-button` in an `ion-toolbar`. Both
standalone buttons and buttons inside `ion-buttons` support this markup.
An empty badge shows an unread indicator; text such as `3` or `99+` shows a count.
For an indicator, keep the contents completely empty (`<ion-badge></ion-badge>`),
without spaces or line breaks between the tags.

Standalone toolbar button:

```html preview
<ion-toolbar>
<ion-button slot="end" aria-label="Notifications">
<ion-icon name="ellipsis-horizontal" slot="icon-only"></ion-icon>
<ion-badge>3</ion-badge>
</ion-button>
</ion-toolbar>
```

Grouped toolbar buttons, with empty, numeric and wide badges:

```html preview
<ion-toolbar>
<ion-buttons slot="end">
<ion-button aria-label="Unread notifications">
<ion-icon name="ellipsis-horizontal" slot="icon-only"></ion-icon>
<ion-badge></ion-badge>
</ion-button>
<ion-button aria-label="3 notifications">
<ion-icon name="ellipsis-horizontal" slot="icon-only"></ion-icon>
<ion-badge>3</ion-badge>
</ion-button>
<ion-button aria-label="99 or more notifications">
<ion-icon name="ellipsis-horizontal" slot="icon-only"></ion-icon>
<ion-badge>99+</ion-badge>
</ion-button>
</ion-buttons>
</ion-toolbar>
```

Use the badge's `color` property to choose an Ionic color. Setting `hidden` or
`display: none`, or removing the badge, hides it without changing the action's
layout. Include the notification state in the action's accessible label.

The treatment is limited to direct-child badges in toolbar buttons. Badges in
tabs, outside toolbars, or nested in another child keep their existing styling.
Theme opt-outs on the toolbar, group, button or badge remain supported.

## Preferred overlay actions

For iOS alerts and action sheets, set `role: 'preferred'` on a button to give it a filled `--ion-color-primary` background and `--ion-color-primary-contrast` text and icons. While pressed, the background uses `--ion-color-primary-shade`. This is a theme convention using Ionic's custom button roles; it does not automatically select or invoke the action. Dismissal reports the role as `preferred`.
Expand Down
68 changes: 68 additions & 0 deletions src/styles/components/ion-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,71 @@ ion-button.ios:not(.ios-theme-disabled, .ios26-disabled) {
ion-back-button.ios:not(.ios-theme-disabled, .ios26-disabled) {
@include theme-button($is-back-button: true);
}

// Only toolbar buttons and their owned Web rail clones share badge layout.
:is(
ion-toolbar.ios:not(.ios-theme-disabled, .ios26-disabled) ion-button.ios,
ion-button.ios:where(.ios-theme-vertical-bars-toolbar-projection.ion-cloned-element):has(> ion-badge[data-native-ui-badge-overlay]),
:where(ion-buttons.ios.ios-theme-vertical-bars-toolbar-projection.ion-cloned-element)
> ion-button.ios:has(> ion-badge[data-native-ui-badge-overlay])
):has(> ion-badge:not(.ios-theme-disabled, .ios26-disabled)):not(.ios-theme-disabled, .ios26-disabled):not(
:where(ion-buttons:is(.ios-theme-disabled, .ios26-disabled) *)
) {
// Keep the action's layout and hit area; only the badge paints outside it.
overflow: visible;

&::part(native) {
overflow: visible;
contain: none;
}

> ion-badge:not(.ios-theme-disabled, .ios26-disabled) {
position: absolute;
box-sizing: border-box;
margin: 0;
pointer-events: none;
z-index: 1;
--padding-top: 0px;
--padding-bottom: 0px;
--padding-start: 3.5px;
--padding-end: 3.5px;
min-width: 18px;
height: 18px;
border-radius: 9px;
font-size: 13px;
font-weight: 400;
line-height: 18px;
letter-spacing: 0;
text-transform: none;
unicode-bidi: plaintext;
// System toolbar badges keep their trailing edge as the label grows.
inset-block-start: calc(50% - 25px);
inset-inline-end: calc(50% - 22px);

&[hidden] {
display: none;
}

// Override Ionic's empty-badge default without outranking application classes.
:where(&:empty) {
display: inline-block;
}

&:empty {
width: 18px;
}
}
}

// Only overlaid source badges release clipping in a projected group.
:is(
ion-toolbar.ios:not(.ios-theme-disabled, .ios26-disabled) ion-buttons.ios,
ion-buttons.ios:where(.ios-theme-vertical-bars-toolbar-projection.ion-cloned-element):has(
> ion-button > ion-badge[data-native-ui-badge-overlay]
)
):has(> ion-button:not(.ios-theme-disabled, .ios26-disabled) > ion-badge:not(.ios-theme-disabled, .ios26-disabled)):not(
.ios-theme-disabled,
.ios26-disabled
) {
overflow: visible;
}
Loading