diff --git a/.github/workflows/e2e-pull_request.yml b/.github/workflows/e2e-pull_request.yml index a28157fa9..5a6c8e9c4 100644 --- a/.github/workflows/e2e-pull_request.yml +++ b/.github/workflows/e2e-pull_request.yml @@ -44,7 +44,7 @@ jobs: - run: npm ci --no-audit --no-fund working-directory: './demo' - name: Run Playwright tests - run: npm run test:e2e -- --shard=${{ matrix.shard }}/2 --reporter=blob + run: npm run test:e2e -- --shard=${{ matrix.shard }}/2 --reporter=blob,line working-directory: ./demo env: IONIC_MAJOR: 9 diff --git a/demo/e2e/native-ui.spec.ts b/demo/e2e/native-ui.spec.ts index 817bc65e8..77bf1268a 100644 --- a/demo/e2e/native-ui.spec.ts +++ b/demo/e2e/native-ui.spec.ts @@ -1841,9 +1841,10 @@ test('all demo pages keep projection consistent through consecutive navigation', await expect .poll(() => page.evaluate(() => { - const status = (document.querySelector('ion-app') as TestAppElement).nativeUI!.getStatus(); + const status = (document.querySelector('ion-app') as TestAppElement).nativeUI?.getStatus(); const snapshot = Capacitor.registerPlugin('NativeUI').updates.at(-1)!; return ( + !!status && status.state !== 'stopped' && document.documentElement.dataset.testEnteredPath === location.pathname && Array.from(document.querySelectorAll('ion-router-outlet')).every( diff --git a/demo/e2e/screenshot.spec.ts b/demo/e2e/screenshot.spec.ts index 5a36546e8..e8b3e6d95 100644 --- a/demo/e2e/screenshot.spec.ts +++ b/demo/e2e/screenshot.spec.ts @@ -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), @@ -51,6 +52,16 @@ const routes = [ const prepareScreenShot = async (page: Page, routeName: string) => { await page.waitForSelector('ion-content[role="main"]', { timeout: 10000 }); await page.evaluate(() => document.fonts.ready); + 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: HTMLIonContentElement) => { const scrollEl = await el.getScrollElement(); diff --git a/demo/e2e/screenshot.spec.ts-snapshots/toolbar-badge-dark.png b/demo/e2e/screenshot.spec.ts-snapshots/toolbar-badge-dark.png new file mode 100644 index 000000000..9b9b37167 Binary files /dev/null and b/demo/e2e/screenshot.spec.ts-snapshots/toolbar-badge-dark.png differ diff --git a/demo/e2e/screenshot.spec.ts-snapshots/toolbar-badge.png b/demo/e2e/screenshot.spec.ts-snapshots/toolbar-badge.png new file mode 100644 index 000000000..88b8de68b Binary files /dev/null and b/demo/e2e/screenshot.spec.ts-snapshots/toolbar-badge.png differ diff --git a/demo/src/app/docs/docs-content.generated.ts b/demo/src/app/docs/docs-content.generated.ts index 40446fc60..8f5b18a0a 100644 --- a/demo/src/app/docs/docs-content.generated.ts +++ b/demo/src/app/docs/docs-content.generated.ts @@ -1,3 +1,3 @@ // Generated from docs/special-markup.md. Do not edit directly. export const docsContentHtml = - '

Special markup and classes

\n

Most Ionic markup works without changes. The combinations below are explicit opt-ins provided by the theme.

\n

Primary submit buttons

\n

Solid submit buttons use the Ionic color's contrast value for their foreground. Their directional edge treatment follows the iOS 27 prominent-button appearance and does not require an additional brightness color.

\n
<ion-button type="submit" color="primary">Submit</ion-button>\n<ion-button class="button-submit" fill="solid" color="primary">Continue</ion-button>
\n\n
\n
Preview
\nSubmit\nContinue\n
\n\n

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

\n

Preferred overlay actions

\n

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.

\n
buttons: [\n  { text: \'Cancel\', role: \'cancel\' },\n  { text: \'Continue\', role: \'preferred\' },\n];
\n\n

Choose the role by action semantics:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
RoleAppearance and behavior
preferredFilled primary action; dismissal reports preferred. Does not automatically select or invoke it.
No role or defaultNormal text color.
cancelRetains Ionic's cancellation behavior.
selectedRetains selection state.
destructiveUses --ios-theme-destructive-color.
confirmNot treated as preferred. Use preferred for a recommended action, not simply any confirmation.
\n

Floating iPad sheets

\n

Choose the sheet's scrolling behavior with expandToScroll:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
SettingiPad appearanceScrolling and resizing
falseFloating lower corners and a 20px bottom gap.Content scrolls within the current breakpoint; dragging the handle resizes the sheet. Ionic sizes the visible page at each breakpoint so CSS can style it.
true (default)Ionic's bottom-attached layout.Scroll-to-expand behavior.
\n

Tab bar position

\n

Choose a class on an iOS ion-tab-bar to position the whole bar within its safe area:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
ClassPlacement
tab-bar-position-startStart of the reading direction.
tab-bar-position-centerCenter.
tab-bar-position-endEnd of the reading direction.
NoneExisting placement unchanged.
\n

All three classes support slot="top" and slot="bottom", preserve width and press animation, and resolve start/end in RTL.

\n
<ion-tab-bar slot="bottom" class="tab-bar-position-center">\n  <ion-tab-button tab="home">Home</ion-tab-button>\n  <ion-tab-button tab="settings">Settings</ion-tab-button>\n</ion-tab-bar>
\n\n

These classes do not reposition a separate ion-fab; leave room for it when choosing the bar's position.

\n

Support iPhone Duo

\n

iPhone Duo support, including standalone Vertical Bars, is stable starting with version 2.0.0.

\n

iPhone Duo support — the vertical system rail, hinge posture, and the posture-driven split-pane layout — is independent of the iOS 27 theme and the full Native UI. See Device layout and split panes for the complete setup, including device-layout monitoring without a projection runtime.

\n

See Vertical Bars for rail layout classes, control eligibility and native button appearance.

\n

For standalone setup while keeping your existing theme, see iPhone Duo with your existing theme.

\n

Two-line inset list items

\n

Place an unslotted ion-label immediately alongside an unslotted ion-note to render a two-line item. When using the iOS-style inset-list background, wrap the items in ion-item-group; keep ion-list-header outside the group.

\n
<ion-list inset="true">\n  <ion-list-header>\n    <ion-label>Connections</ion-label>\n  </ion-list-header>\n  <ion-item-group>\n    <ion-item>\n      <ion-label>Network &amp; internet</ion-label>\n      <ion-note>Mobile, Wi-Fi, hotspot</ion-note>\n    </ion-item>\n  </ion-item-group>\n</ion-list>
\n\n
\n
Preview
\n\n \n Connections\n \n \n \n Network & internet\n Mobile, Wi-Fi, hotspot\n \n \n\n
\n\n

Use slot="end" on ion-note when you want the standard trailing-note layout instead.

\n

Inset-list section headers

\n

Add .item-group-header to an ion-item-group to create the centered icon, title, and description used at the top of the component demo pages.

\n

This is an introductory group. Place regular list items in a separate ion-item-group that follows it.

\n
<ion-list inset="true">\n  <ion-item-group class="item-group-header">\n    <ion-item>\n      <ion-label>\n        <ion-icon name="list" style="background: var(--ion-color-primary)"></ion-icon>\n        <h2>Lists</h2>\n        <ion-text>Inset-list examples</ion-text>\n      </ion-label>\n    </ion-item>\n  </ion-item-group>\n  <ion-item-group>\n    <ion-item><ion-label>First item</ion-label></ion-item>\n  </ion-item-group>\n</ion-list>
\n\n
\n
Preview
\n\n \n \n \n \n

Lists

\n Inset-list examples\n
\n
\n
\n \n First item\n \n
\n
\n\n

Full-width segments

\n

Add .segment-style-glass to give a segment the same glass surface and selected indicator treatment as the tab bar. The class preserves the segment's existing dimensions and text colors, supports scrollable segments, and respects Ionic's public --background property.

\n
<ion-segment class="segment-style-glass" value="available">\n  <ion-segment-button value="available">Available</ion-segment-button>\n  <ion-segment-button value="away">Away</ion-segment-button>\n</ion-segment>
\n\n

For colored segments, use Ionic's color property (for example, color="primary" or color="secondary"). Ionic uses the palette's base color for the softly tinted track while keeping the selected surface and labels neutral. A surrounding colored toolbar only supplies colors when the segment has no color of its own. The optional moving glass inherits the selected surface color, and custom Ionic palettes work without additional registration.

\n

Add .segment-expand when segment buttons should divide the available width evenly. The class also changes the Liquid Glass effect sizing when registerSegmentEffect is used.

\n

Segment size and press behavior

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
PlacementMinimum heightContainer behavior
In content32pxCompact, flat background and indicator; outer bounds stay fixed.
Inside ion-toolbar48pxGlass container; outer container scales while pressed.
.segment-expand, including in a toolbar32pxCompact, flat background and indicator; outer bounds stay fixed.
\n

The optional moving glass lens is independent of the container's background.

\n
<ion-segment class="segment-expand" value="new">\n  <ion-segment-button value="new"><ion-label>New</ion-label></ion-segment-button>\n  <ion-segment-button value="replied"><ion-label>Replied</ion-label></ion-segment-button>\n</ion-segment>
\n\n
\n
Preview
\n\n New\n Replied\n\n
\n\n

Classic search bar in a condense header

\n

The theme gives iOS search bars the iOS 27 appearance by default. Add .searchbar-classic to the search field shown beneath a large title in an ion-header with collapse="condense". It uses the conventional filled iOS appearance and collapses with the large title instead of remaining in the fixed header.

\n

Place it in a toolbar with a color, such as color="light"; the classic background is derived from that color's contrast value.

\n

The example uses Ionic's standard collapsible large-title structure. Scroll the preview to collapse the large title and reveal the fixed header.

\n
<div class="ion-page">\n  <ion-header translucent="true">\n    <ion-toolbar color="light">\n      <ion-title>Search</ion-title>\n    </ion-toolbar>\n  </ion-header>\n  <ion-content color="light" fullscreen="true">\n    <ion-header collapse="condense">\n      <ion-toolbar color="light">\n        <ion-title size="large">Search</ion-title>\n      </ion-toolbar>\n      <ion-toolbar color="light">\n        <ion-searchbar class="searchbar-classic" placeholder="Filter results"></ion-searchbar>\n      </ion-toolbar>\n    </ion-header>\n    <ion-list inset="true">\n      <ion-item-group>\n        <ion-item><ion-label>Recent item 1</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 2</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 3</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 4</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 5</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 6</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 7</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 8</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 9</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 10</ion-label></ion-item>\n      </ion-item-group>\n    </ion-list>\n  </ion-content>\n</div>
\n\n
\n
Preview
\n
\n \n \n Search\n \n \n \n \n \n Search\n \n \n \n \n \n \n \n Recent item 1\n Recent item 2\n Recent item 3\n Recent item 4\n Recent item 5\n Recent item 6\n Recent item 7\n Recent item 8\n Recent item 9\n Recent item 10\n \n \n \n
\n
\n\n

The .ion-page wrapper makes this embedded preview behave like a complete routed page. An application using ion-router-outlet normally receives that page container automatically. The inset list and its items only provide enough content to demonstrate scrolling; they are not required by .searchbar-classic.

\n

Opting out

\n

Add .ios-theme-disabled to an individual Ionic component when it must retain Ionic's standard iOS styling.

\n

.ios26-disabled is deprecated but remains supported as an alias with the same behavior. Use .ios-theme-disabled for new code.

\n
<ion-button>iOS 27 theme</ion-button> <ion-button class="ios-theme-disabled">Standard Ionic button</ion-button>
\n\n
\n
Preview
\niOS 27 theme Standard Ionic button\n
\n\n

For the background model behind inset lists, see Using ion-item-group.

\n'; + '

Special markup and classes

\n

Most Ionic markup works without changes. The combinations below are explicit opt-ins provided by the theme.

\n

Primary submit buttons

\n

Solid submit buttons use the Ionic color's contrast value for their foreground. Their directional edge treatment follows the iOS 27 prominent-button appearance and does not require an additional brightness color.

\n
<ion-button type="submit" color="primary">Submit</ion-button>\n<ion-button class="button-submit" fill="solid" color="primary">Continue</ion-button>
\n\n
\n
Preview
\nSubmit\nContinue\n
\n\n

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

\n

Toolbar button badges

\n

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

\n

Standalone toolbar button:

\n
<ion-toolbar>\n  <ion-button slot="end" aria-label="Notifications">\n    <ion-icon name="ellipsis-horizontal" slot="icon-only"></ion-icon>\n    <ion-badge>3</ion-badge>\n  </ion-button>\n</ion-toolbar>
\n\n
\n
Preview
\n\n \n \n 3\n \n\n
\n\n

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

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

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

\n

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

\n

Preferred overlay actions

\n

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.

\n
buttons: [\n  { text: \'Cancel\', role: \'cancel\' },\n  { text: \'Continue\', role: \'preferred\' },\n];
\n\n

Choose the role by action semantics:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
RoleAppearance and behavior
preferredFilled primary action; dismissal reports preferred. Does not automatically select or invoke it.
No role or defaultNormal text color.
cancelRetains Ionic's cancellation behavior.
selectedRetains selection state.
destructiveUses --ios-theme-destructive-color.
confirmNot treated as preferred. Use preferred for a recommended action, not simply any confirmation.
\n

Floating iPad sheets

\n

Choose the sheet's scrolling behavior with expandToScroll:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
SettingiPad appearanceScrolling and resizing
falseFloating lower corners and a 20px bottom gap.Content scrolls within the current breakpoint; dragging the handle resizes the sheet. Ionic sizes the visible page at each breakpoint so CSS can style it.
true (default)Ionic's bottom-attached layout.Scroll-to-expand behavior.
\n

Tab bar position

\n

Choose a class on an iOS ion-tab-bar to position the whole bar within its safe area:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
ClassPlacement
tab-bar-position-startStart of the reading direction.
tab-bar-position-centerCenter.
tab-bar-position-endEnd of the reading direction.
NoneExisting placement unchanged.
\n

All three classes support slot="top" and slot="bottom", preserve width and press animation, and resolve start/end in RTL.

\n
<ion-tab-bar slot="bottom" class="tab-bar-position-center">\n  <ion-tab-button tab="home">Home</ion-tab-button>\n  <ion-tab-button tab="settings">Settings</ion-tab-button>\n</ion-tab-bar>
\n\n

These classes do not reposition a separate ion-fab; leave room for it when choosing the bar's position.

\n

Support iPhone Duo

\n

iPhone Duo support, including standalone Vertical Bars, is stable starting with version 2.0.0.

\n

iPhone Duo support — the vertical system rail, hinge posture, and the posture-driven split-pane layout — is independent of the iOS 27 theme and the full Native UI. See Device layout and split panes for the complete setup, including device-layout monitoring without a projection runtime.

\n

See Vertical Bars for rail layout classes, control eligibility and native button appearance.

\n

For standalone setup while keeping your existing theme, see iPhone Duo with your existing theme.

\n

Two-line inset list items

\n

Place an unslotted ion-label immediately alongside an unslotted ion-note to render a two-line item. When using the iOS-style inset-list background, wrap the items in ion-item-group; keep ion-list-header outside the group.

\n
<ion-list inset="true">\n  <ion-list-header>\n    <ion-label>Connections</ion-label>\n  </ion-list-header>\n  <ion-item-group>\n    <ion-item>\n      <ion-label>Network &amp; internet</ion-label>\n      <ion-note>Mobile, Wi-Fi, hotspot</ion-note>\n    </ion-item>\n  </ion-item-group>\n</ion-list>
\n\n
\n
Preview
\n\n \n Connections\n \n \n \n Network & internet\n Mobile, Wi-Fi, hotspot\n \n \n\n
\n\n

Use slot="end" on ion-note when you want the standard trailing-note layout instead.

\n

Inset-list section headers

\n

Add .item-group-header to an ion-item-group to create the centered icon, title, and description used at the top of the component demo pages.

\n

This is an introductory group. Place regular list items in a separate ion-item-group that follows it.

\n
<ion-list inset="true">\n  <ion-item-group class="item-group-header">\n    <ion-item>\n      <ion-label>\n        <ion-icon name="list" style="background: var(--ion-color-primary)"></ion-icon>\n        <h2>Lists</h2>\n        <ion-text>Inset-list examples</ion-text>\n      </ion-label>\n    </ion-item>\n  </ion-item-group>\n  <ion-item-group>\n    <ion-item><ion-label>First item</ion-label></ion-item>\n  </ion-item-group>\n</ion-list>
\n\n
\n
Preview
\n\n \n \n \n \n

Lists

\n Inset-list examples\n
\n
\n
\n \n First item\n \n
\n
\n\n

Full-width segments

\n

Add .segment-style-glass to give a segment the same glass surface and selected indicator treatment as the tab bar. The class preserves the segment's existing dimensions and text colors, supports scrollable segments, and respects Ionic's public --background property.

\n
<ion-segment class="segment-style-glass" value="available">\n  <ion-segment-button value="available">Available</ion-segment-button>\n  <ion-segment-button value="away">Away</ion-segment-button>\n</ion-segment>
\n\n

For colored segments, use Ionic's color property (for example, color="primary" or color="secondary"). Ionic uses the palette's base color for the softly tinted track while keeping the selected surface and labels neutral. A surrounding colored toolbar only supplies colors when the segment has no color of its own. The optional moving glass inherits the selected surface color, and custom Ionic palettes work without additional registration.

\n

Add .segment-expand when segment buttons should divide the available width evenly. The class also changes the Liquid Glass effect sizing when registerSegmentEffect is used.

\n

Segment size and press behavior

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
PlacementMinimum heightContainer behavior
In content32pxCompact, flat background and indicator; outer bounds stay fixed.
Inside ion-toolbar48pxGlass container; outer container scales while pressed.
.segment-expand, including in a toolbar32pxCompact, flat background and indicator; outer bounds stay fixed.
\n

The optional moving glass lens is independent of the container's background.

\n
<ion-segment class="segment-expand" value="new">\n  <ion-segment-button value="new"><ion-label>New</ion-label></ion-segment-button>\n  <ion-segment-button value="replied"><ion-label>Replied</ion-label></ion-segment-button>\n</ion-segment>
\n\n
\n
Preview
\n\n New\n Replied\n\n
\n\n

Classic search bar in a condense header

\n

The theme gives iOS search bars the iOS 27 appearance by default. Add .searchbar-classic to the search field shown beneath a large title in an ion-header with collapse="condense". It uses the conventional filled iOS appearance and collapses with the large title instead of remaining in the fixed header.

\n

Place it in a toolbar with a color, such as color="light"; the classic background is derived from that color's contrast value.

\n

The example uses Ionic's standard collapsible large-title structure. Scroll the preview to collapse the large title and reveal the fixed header.

\n
<div class="ion-page">\n  <ion-header translucent="true">\n    <ion-toolbar color="light">\n      <ion-title>Search</ion-title>\n    </ion-toolbar>\n  </ion-header>\n  <ion-content color="light" fullscreen="true">\n    <ion-header collapse="condense">\n      <ion-toolbar color="light">\n        <ion-title size="large">Search</ion-title>\n      </ion-toolbar>\n      <ion-toolbar color="light">\n        <ion-searchbar class="searchbar-classic" placeholder="Filter results"></ion-searchbar>\n      </ion-toolbar>\n    </ion-header>\n    <ion-list inset="true">\n      <ion-item-group>\n        <ion-item><ion-label>Recent item 1</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 2</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 3</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 4</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 5</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 6</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 7</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 8</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 9</ion-label></ion-item>\n        <ion-item><ion-label>Recent item 10</ion-label></ion-item>\n      </ion-item-group>\n    </ion-list>\n  </ion-content>\n</div>
\n\n
\n
Preview
\n
\n \n \n Search\n \n \n \n \n \n Search\n \n \n \n \n \n \n \n Recent item 1\n Recent item 2\n Recent item 3\n Recent item 4\n Recent item 5\n Recent item 6\n Recent item 7\n Recent item 8\n Recent item 9\n Recent item 10\n \n \n \n
\n
\n\n

The .ion-page wrapper makes this embedded preview behave like a complete routed page. An application using ion-router-outlet normally receives that page container automatically. The inset list and its items only provide enough content to demonstrate scrolling; they are not required by .searchbar-classic.

\n

Opting out

\n

Add .ios-theme-disabled to an individual Ionic component when it must retain Ionic's standard iOS styling.

\n

.ios26-disabled is deprecated but remains supported as an alias with the same behavior. Use .ios-theme-disabled for new code.

\n
<ion-button>iOS 27 theme</ion-button> <ion-button class="ios-theme-disabled">Standard Ionic button</ion-button>
\n\n
\n
Preview
\niOS 27 theme Standard Ionic button\n
\n\n

For the background model behind inset lists, see Using ion-item-group.

\n'; diff --git a/demo/src/app/index/index-page.component.ts b/demo/src/app/index/index-page.component.ts index d05e502d1..7eae28a3e 100644 --- a/demo/src/app/index/index-page.component.ts +++ b/demo/src/app/index/index-page.component.ts @@ -78,6 +78,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)); diff --git a/demo/src/app/index/index.routes.ts b/demo/src/app/index/index.routes.ts index f2bcebf05..7cb9505b9 100644 --- a/demo/src/app/index/index.routes.ts +++ b/demo/src/app/index/index.routes.ts @@ -26,6 +26,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), diff --git a/demo/src/app/index/pages/toolbar-badge/toolbar-badge.page.html b/demo/src/app/index/pages/toolbar-badge/toolbar-badge.page.html new file mode 100644 index 000000000..b99191482 --- /dev/null +++ b/demo/src/app/index/pages/toolbar-badge/toolbar-badge.page.html @@ -0,0 +1,95 @@ + + Toolbar badges + + +
+ @for (direction of directions; track direction) { +
+

{{ direction.toUpperCase() }}

+

Empty / 3 / 99+ / no badge

+

Standalone buttons

+ + @for (value of badges; track value) { + {{ value }} + } + + +

Grouped buttons

+ + + @for (value of badges; track value) { + {{ value }} + } + + + +

Single group / menu group

+ + 3 + 3 + +

Custom color / hidden / CSS class / opt-out

+ + 3 + 3 + + + 3 + +

Web rail clones (outside toolbar)

+
+ @for (value of badges; track value) { + {{ value }} + } + + @for (value of badges; track value) { + {{ value }} + } + +
+

Outside toolbar / nested badge

+ 3 + Nested 3 +
+ } +
+
diff --git a/demo/src/app/index/pages/toolbar-badge/toolbar-badge.page.scss b/demo/src/app/index/pages/toolbar-badge/toolbar-badge.page.scss new file mode 100644 index 000000000..b433b3f27 --- /dev/null +++ b/demo/src/app/index/pages/toolbar-badge/toolbar-badge.page.scss @@ -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; +} diff --git a/demo/src/app/index/pages/toolbar-badge/toolbar-badge.page.ts b/demo/src/app/index/pages/toolbar-badge/toolbar-badge.page.ts new file mode 100644 index 000000000..54f9208fd --- /dev/null +++ b/demo/src/app/index/pages/toolbar-badge/toolbar-badge.page.ts @@ -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+']; +} diff --git a/docs/special-markup.md b/docs/special-markup.md index 7ea08f0a3..9deefebdf 100644 --- a/docs/special-markup.md +++ b/docs/special-markup.md @@ -17,6 +17,54 @@ Solid submit buttons use the Ionic color's contrast value for their foreground. 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 (``), +without spaces or line breaks between the tags. + +Standalone toolbar button: + +```html preview + + + + 3 + + +``` + +Grouped toolbar buttons, with empty, numeric and wide badges: + +```html preview + + + + + + + + + 3 + + + + 99+ + + + +``` + +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`. diff --git a/src/styles/components/ion-button.scss b/src/styles/components/ion-button.scss index 0a3022954..d24aa72c1 100644 --- a/src/styles/components/ion-button.scss +++ b/src/styles/components/ion-button.scss @@ -492,3 +492,71 @@ ion-toolbar.ios:not(.ios-theme-disabled, .ios26-disabled) { } } } + +// 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; +}