diff --git a/BREAKING.md b/BREAKING.md
index 1aff7b4e6cf..3bc4b61b328 100644
--- a/BREAKING.md
+++ b/BREAKING.md
@@ -18,6 +18,7 @@ This is a comprehensive list of the breaking changes introduced in the major ver
- [Browser and Platform Support](#version-10x-browser-platform-support)
- [Global Styles](#version-10x-global-styles)
- [Components](#version-10x-components)
+ - [Accordion](#version-10x-accordion)
- [Backdrop](#version-10x-backdrop)
- [Button](#version-10x-button)
- [Card](#version-10x-card)
@@ -29,6 +30,7 @@ This is a comprehensive list of the breaking changes introduced in the major ver
- [Grid](#version-10x-grid)
- [Image](#version-10x-image)
- [Input Otp](#version-10x-input-otp)
+ - [Item](#version-10x-item)
- [Item Divider](#version-10x-item-divider)
- [Label](#version-10x-label)
- [Menu Toggle](#version-10x-menu-toggle)
@@ -77,6 +79,10 @@ This section details the desktop browser and mobile platform versions that are s
Components
+
Accordion
+
+- In the ios theme, the line above the header of an accordion that follows an expanded one is drawn by the accordion instead of a border on the header item. It uses `--ion-item-border-color`, or `--ion-border-color` when that isn't set, and the shade of the header item's `color` when it has one. `--border-color` on the header item no longer changes its color.
+
Backdrop
The following breaking changes apply to `ion-backdrop`:
@@ -652,6 +658,21 @@ Converted `ion-input-otp` to use [Shadow DOM](https://developer.mozilla.org/en-U
If you were targeting the internals of `ion-input-otp` in your CSS, you will need to target the `group`, `container`, `native`, `separator` or `description` [Shadow Parts](https://ionicframework.com/docs/theming/css-shadow-parts) instead, or use the provided CSS Variables.
+
Item
+
+The lines between items are drawn with an element instead of a border, so `--border-width` and `--inner-border-width` no longer show, hide or resize them, and `--border-style` no longer changes their style. `--border-color` still sets their color.
+
+`--border-width` and `--inner-border-width` still draw a border on the item, so an app that set them to thicken a line now gets that border on top of the line. Remove those overrides and style the `line` (full width) or `inner-line` (inset) [Shadow Part](https://ionicframework.com/docs/theming/css-shadow-parts) instead. The line fills only its default thickness, so set `background` along with `height` to thicken it. The item keeps space for the default thickness only, so a thicker line covers the bottom of the item's content.
+
+```css
+ion-item::part(line) {
+ height: 2px;
+ background: currentColor;
+}
+```
+
+To hide a line, set `lines="none"` on the item or the list. Hiding the part with `display: none` keeps the space below the line. To show a line, set `lines="full"` or `lines="inset"`, since showing the part with `display: block` leaves out that space.
+
Item Divider
- Component CSS variables have been removed. The component now utilizes the centralized Ionic Theming system. Global updates should be managed via the theme tokens file, while component-specific overrides are handled through localized CSS variables.
diff --git a/core/api.txt b/core/api.txt
index a81555f120d..6d2801e49d3 100644
--- a/core/api.txt
+++ b/core/api.txt
@@ -1839,6 +1839,8 @@ ion-item,css-prop,--transition,md
ion-item,part,container
ion-item,part,detail-icon
ion-item,part,inner
+ion-item,part,inner-line
+ion-item,part,line
ion-item,part,native
ion-item-divider,shadow
diff --git a/core/scripts/testing/scripts.js b/core/scripts/testing/scripts.js
index a2aef48ab3f..fccb451cdcb 100644
--- a/core/scripts/testing/scripts.js
+++ b/core/scripts/testing/scripts.js
@@ -139,8 +139,11 @@ const DEFAULT_PALETTE = 'light';
// Store existing theme set from the app initialization
const customTheme = window.Ionic?.config?.customTheme;
// Load the default tokens for the theme
- const themeLoaded = import(`/themes/${themeName}/default.tokens.js`).then((defaultTokens) =>
- buildTheme(defaultTokens.defaultTheme, customTheme, paletteName)
+ const themeLoaded = Promise.all([
+ import(`/themes/${themeName}/default.tokens.js`),
+ import('/themes/utils/theme.js'),
+ ]).then(([defaultTokens, themeUtils]) =>
+ buildTheme(defaultTokens.defaultTheme, customTheme, paletteName, themeUtils)
);
/*
@@ -184,26 +187,6 @@ const DEFAULT_PALETTE = 'light';
window.__ionicTestThemeReady = true;
}
- /**
- * Deep merges two objects, with source properties overriding target properties
- * @param target The target object to merge into
- * @param source The source object to merge from
- * @returns The merged object
- */
- // TODO(FW-6750): Remove this once the theme tokens can be imported directly into the test pages
- const deepMerge = (target, source) => {
- const result = { ...target };
-
- for (const key in source) {
- if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
- result[key] = deepMerge(result[key] ?? {}, source[key]);
- } else {
- result[key] = source[key];
- }
- }
- return result;
- };
-
/*
* Resolves once the Ionic Config instance (created by `initialize()` in
* ionic-global.ts) is available. If the app has already loaded we resolve
@@ -224,11 +207,13 @@ const DEFAULT_PALETTE = 'light';
}
// TODO(FW-6750): Determine if this function can be removed once the theme tokens can be imported directly into the test pages
- function buildTheme(tokensTheme, customTheme, paletteName) {
+ function buildTheme(tokensTheme, customTheme, paletteName, themeUtils) {
let theme = tokensTheme;
- // Merge with existing theme to preserve any customizations
+ // Merge with existing theme to preserve any customizations. A custom
+ // value replaces the theme's media query values for the same key, as
+ // it does in the app (refer to `mergeTheme`).
if (customTheme) {
- theme = deepMerge(theme, customTheme);
+ theme = themeUtils.mergeTheme(theme, customTheme);
}
// If a specific palette is requested, modify the palette structure
diff --git a/core/src/components/accordion/accordion.common.scss b/core/src/components/accordion/accordion.common.scss
index 0d3610f2aca..56362247f5e 100644
--- a/core/src/components/accordion/accordion.common.scss
+++ b/core/src/components/accordion/accordion.common.scss
@@ -21,9 +21,9 @@
z-index: 0;
}
-:host(.accordion-expanding) ::slotted(ion-item[slot="header"]),
-:host(.accordion-expanded) ::slotted(ion-item[slot="header"]) {
- --border-width: 0px;
+// Hidden unless the theme's stylesheet shows it
+.accordion-next-line {
+ display: none;
}
#content {
diff --git a/core/src/components/accordion/accordion.ionic.scss b/core/src/components/accordion/accordion.ionic.scss
index ff9052034db..430acbb3445 100644
--- a/core/src/components/accordion/accordion.ionic.scss
+++ b/core/src/components/accordion/accordion.ionic.scss
@@ -44,13 +44,11 @@
// Accordion Header
// --------------------------------------------------
-// The border is removed from the item in the header because
-// we are adding a border to the ::after element of the accordion.
+// The header item's lines are hidden in core.ionic.scss because the
+// accordion draws its own line with the ::after element.
::slotted(ion-item[slot="header"]) {
--border-radius: inherit;
--color: #{globals.$ion-text-default};
- --border-width: #{globals.$ion-border-size-0};
- --inner-border-width: #{globals.$ion-scale-0};
--min-height: #{globals.$ion-scale-700};
--padding-top: #{globals.$ion-space-300};
--padding-end: #{globals.$ion-space-400};
diff --git a/core/src/components/accordion/accordion.ios.scss b/core/src/components/accordion/accordion.ios.scss
index db92476ad53..3596b5e33cc 100644
--- a/core/src/components/accordion/accordion.ios.scss
+++ b/core/src/components/accordion/accordion.ios.scss
@@ -4,6 +4,22 @@
// iOS Accordion
// --------------------------------------------------
-:host(.accordion-next) ::slotted(ion-item[slot="header"]) {
- --border-width: #{$item-ios-border-bottom-width 0px $item-ios-border-bottom-width 0px};
+// Drawn as a filled box so it stays visible at sub-pixel positions in WebKit
+.accordion-next-line {
+ @include hairline(top);
+
+ color: $item-ios-border-bottom-color;
+
+ // Above the header item's background
+ z-index: 1;
+}
+
+// The last accordion's header has no lines (refer to core.scss), so it has no top line either
+:host(.accordion-next.accordion-has-header-item:not(.accordion-last)) .accordion-next-line {
+ display: block;
+}
+
+// Keeps the space a border took, so the header item doesn't sit under the line
+:host(.accordion-next.accordion-has-header-item:not(.accordion-last)) #header {
+ @include hairline-thickness(padding-top);
}
diff --git a/core/src/components/accordion/accordion.tsx b/core/src/components/accordion/accordion.tsx
index 87a475d9afe..ecb707ba33f 100644
--- a/core/src/components/accordion/accordion.tsx
+++ b/core/src/components/accordion/accordion.tsx
@@ -1,7 +1,7 @@
import type { ComponentInterface } from '@stencil/core';
-import { Component, Element, Host, Prop, State, Watch, h } from '@stencil/core';
+import { Build, Component, Element, Host, Prop, State, Watch, h } from '@stencil/core';
import { addEventListener, getElementRoot, raf, removeEventListener, transitionEndAsync } from '@utils/helpers';
-import { hostContext } from '@utils/theme';
+import { hostContext, ionColor } from '@utils/theme';
import { chevronDown } from 'ionicons/icons';
import { config } from '../../global/config';
@@ -78,6 +78,8 @@ export class Accordion implements ComponentInterface {
private contentEl: HTMLDivElement | undefined;
private contentElWrapper: HTMLDivElement | undefined;
private headerEl: HTMLDivElement | undefined;
+ private nextLineEl: HTMLDivElement | undefined;
+ private headerItemColorObserver?: MutationObserver;
private currentRaf: number | undefined;
@@ -87,6 +89,11 @@ export class Accordion implements ComponentInterface {
@State() isNext = false;
@State() isPrevious = false;
@State() isLast = false;
+ /**
+ * Whether an `ion-item` is slotted as the header. Only an item header has
+ * lines, so the top line is only drawn for one.
+ */
+ @State() hasHeaderItem = false;
/**
* Tracks whether a user-initiated interaction has occurred.
* Animations are disabled until the first interaction happens.
@@ -147,6 +154,10 @@ export class Accordion implements ComponentInterface {
this.updateState();
addEventListener(accordionGroupEl, 'ionValueChange', this.accordionGroupUpdateHandler);
}
+
+ // The header only exists after the first render, so this only runs here
+ // when the accordion is moved
+ this.watchHeaderItemColor();
}
disconnectedCallback() {
@@ -154,11 +165,17 @@ export class Accordion implements ComponentInterface {
if (accordionGroupEl) {
removeEventListener(accordionGroupEl, 'ionValueChange', this.accordionGroupUpdateHandler);
}
+
+ this.headerItemColorObserver?.disconnect();
+ this.headerItemColorObserver = undefined;
}
componentDidLoad() {
this.setItemDefaults();
this.slotToggleIcon();
+ this.hasHeaderItem = this.getSlottedHeaderIonItem() !== undefined;
+ this.updateNextLineColor();
+ this.watchHeaderItemColor();
/**
* We need to wait a tick because we
@@ -201,6 +218,41 @@ export class Accordion implements ComponentInterface {
}
};
+ /**
+ * Colors the top line with the shade of the header item's color, matching
+ * the item's own lines. The accordion's styles can't read the item's color,
+ * so the shade is set here.
+ */
+ private updateNextLineColor = () => {
+ const { nextLineEl } = this;
+ if (!nextLineEl) {
+ return;
+ }
+
+ const color = this.getSlottedHeaderIonItem()?.color;
+ if (color === undefined) {
+ nextLineEl.style.removeProperty('color');
+ return;
+ }
+
+ nextLineEl.style.color = ionColor(color, 'shade');
+ };
+
+ /**
+ * Recolors the top line when the header item's `color` changes. The line is
+ * drawn by the accordion, so it doesn't follow the item's color on its own.
+ */
+ private watchHeaderItemColor = () => {
+ const ionItem = this.getSlottedHeaderIonItem();
+ if (!ionItem || !Build.isBrowser || typeof MutationObserver === 'undefined') {
+ return;
+ }
+
+ this.headerItemColorObserver?.disconnect();
+ this.headerItemColorObserver = new MutationObserver(() => this.updateNextLineColor());
+ this.headerItemColorObserver.observe(ionItem, { attributes: true, attributeFilter: ['color'] });
+ };
+
private getSlottedHeaderIonItem = () => {
const { headerEl } = this;
if (!headerEl) {
@@ -522,6 +574,7 @@ export class Accordion implements ComponentInterface {
'accordion-next': this.isNext,
'accordion-previous': this.isPrevious,
'accordion-last': this.isLast,
+ 'accordion-has-header-item': this.hasHeaderItem,
'accordion-disabled': disabled,
'accordion-readonly': readonly,
@@ -542,6 +595,8 @@ export class Accordion implements ComponentInterface {
+
(this.nextLineEl = nextLineEl)}>
+
{
});
});
});
+
+/**
+ * Other ios tests draw at 1x (refer to the `deviceScaleFactor` fixture in
+ * `playwright-page.ts`), so they never show a line at its real thickness.
+ * This test draws at each browser's own density and keeps every pixel,
+ * so a missing, thicker or misplaced line above a header fails. Only the ios
+ * theme draws that line.
+ * This behavior does not vary across directions.
+ */
+configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ config, screenshot, title }) => {
+ test.describe(title('accordion: line at device resolution'), () => {
+ // Resets the 1x that ios tests get to the browser's own density
+ test.use({ deviceScaleFactor: undefined });
+
+ test('should not have visual regressions', async ({ page }) => {
+ // The groups start 0, 1/3 and 2/3 of a pixel down the page
+ const group = (offset: string, color = '') => `
+
+
+ First
+