diff --git a/.github/CODING_GUIDELINES.md b/.github/CODING_GUIDELINES.md index 635e9b302..58082ee80 100644 --- a/.github/CODING_GUIDELINES.md +++ b/.github/CODING_GUIDELINES.md @@ -286,7 +286,7 @@ Before you write lifecycle code, look for a controller that already does it: | `addContextProvider` / `addAsyncContextConsumer` | `#internals/controllers/context-provider.js`, `async-consumer.js` | Sharing state between a parent and its children through Lit context | | `createGroupRegistry` | `#internals/controllers/group.js` | Grouping peers by key, such as radios by `name` | | `addI18nController` | `#internals/i18n/i18n-controller.js` | Localized resource strings | -| `addValueStateMotion` | `#animations/value-state.js` | Showing a change of value state from code at once, and animating only a change by the user | +| `addValueStateMotion` / `markInstant` | `#animations/value-state.js` | Showing a change of value state from code at once, and animating only a change by the user; `markInstant` shows the changes of one frame at once | | `markUserChange` / `isUserChange` | `#internals/user-change.js` | Marking the update that a user action causes | For pointer resizing and dragging, use the `resizable()` and `draggable()` directives from diff --git a/CHANGELOG.md b/CHANGELOG.md index f90d3e177..13f680b4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - `createWifiPayload()`, `createVCardPayload()`, `createEpcPayload()` and `createEventPayload()` from `igniteui-webcomponents/extras/qr-payloads` build the value of a code that a phone turns into a Wi-Fi login, a contact card, a SEPA payment or a calendar event. They escape the text and throw a `RangeError` for input that the format does not allow. ### Changed +- #### Accordion, Expansion panel + - A change of `open` on a panel shows at once. This includes the spacing that an accordion gives it, and the transitions that the app puts on the panel. Before, the spacing animated while the content showed at once. `show()`, `hide()`, `toggle()` and the user still animate both. - #### Button group, Checkbox, Chip, Color picker, Combo, Date picker, Date range picker, Date time input, File input, Input, List, Mask input, Navigation drawer, Radio, Select, Switch, Textarea, Tree - Only a change by the user animates a checkbox, a switch, a radio, a toggle button, and the label of an input or a textarea (also the inputs of the pickers, the select and the combo), as for the chip. A change from code and the first render show at once, so a virtualized list does not animate them while it scrolls. A list item shows a change of `selected` at once, because only code sets it. A change that a component makes for a user action animates too: the radio that a group unchecks, the toggle button that a single selection deselects, the items of a tree cascade and the options of a combo. A change from app code, also in an event handler, such as a "Select all" checkbox, shows at once. Hover, focus and the invalid state still fade. With `prefers-reduced-motion: reduce`, these controls, the list item and the navigation drawer item have no transitions of their own, and a transition that the app adds to a part still applies. - While a change from code shows at once, these controls and the chip turn off all their transitions, also the ones that the app sets on parts and slotted elements. Before, the chip turned off only the transitions of its base and its indicator. @@ -40,10 +42,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - The two inputs and the `value` attribute keep the time of the dates. Before, they set the time to midnight. - A change of `useTwoInputs` drops an edit in an input that the change removes, also when the input loses the focus before the next render. Before, that input could still commit its edit. - Without `activeDate`, a range with one end set from code brings that end into view, as a full range brings its start. +- #### Dialog + - `open = true` and a first render with `open` show the backdrop at once, as they do the dialog. So do an append of an open dialog and a reopen after a close that the dialog cannot cancel. Before, the backdrop faded in. `show()` still fades both in. - #### Dropdown - Enter closes the open list also when no item is active, as in the select. Before, the list stayed open. - #### Library - The library supports the last 2 major versions of Chrome, Edge, Firefox, Opera and Safari. The fallbacks for older browsers are removed, and the styles no longer have vendor prefixes for them. +- #### Navigation drawer + - A drawer that is `open` on its first render shows at once, with no slide and no backdrop fade. This also applies when a framework renders the drawer open after a user action. To slide it in, call `show()`, or set `open` after the first render. - #### QR code - The code splits its value into numeric, alphanumeric and byte segments with the fewest bits. A value that mixes long runs of digits or uppercase letters with other text, such as an order number in a URL, can get a smaller version. A scanner reads the same text. - The cutout under the logo holds whole modules, so it cuts no module in part. @@ -56,6 +62,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - `checkValidity()` and `reportValidity()` emit `invalid` on the radios of the group in DOM order. Before, the other radios emitted it first, and the called radio last. - #### Select - Tab and Escape on the select act also when other code already called `preventDefault()` on the key, as in the dropdown. Content in the `header` and `footer` slots still keeps a key that it handled. +- #### Tabs + - The first render shows at once. The selected indicator does not slide in from the start of the strip, and the selected header does not fade in. This also applies when the tabs show later than they render. A selection change after that still animates. ### Fixed - #### Calendar, Date picker, Date range picker, Date time input diff --git a/src/animations/css-transitions.ts b/src/animations/css-transitions.ts index 3ece557b9..9db59d395 100644 --- a/src/animations/css-transitions.ts +++ b/src/animations/css-transitions.ts @@ -15,6 +15,16 @@ export function getCSSTransitions( return animations.filter((animation) => animation instanceof CSSTransition); } +/** Ends the CSS transitions that `getCSSTransitions()` returns, so their end styles show at once. */ +export function finishCSSTransitions( + element: Element | ShadowRoot, + options?: GetAnimationsOptions +): void { + for (const transition of getCSSTransitions(element, options)) { + transition.finish(); + } +} + /** Returns a promise that settles when each transition finishes or is canceled. */ export function transitionsSettled( transitions: readonly Animation[] diff --git a/src/animations/value-state.ts b/src/animations/value-state.ts index 74b375a00..2e7f74384 100644 --- a/src/animations/value-state.ts +++ b/src/animations/value-state.ts @@ -65,6 +65,11 @@ class InstantElements { // Created on first use, so a control that only marks user changes does not bundle it. let instantElements: InstantElements | undefined; +/** Shows the changes of `element` in this frame at once, until a frame with no change from code. */ +export function markInstant(element: Element): void { + (instantElements ??= new InstantElements()).add(element); +} + /** * A host waits for its shadow root, not for itself: the hosts that the user * changes have no transitions of their own, and `Element.getAnimations()` @@ -161,7 +166,7 @@ export class ValueStateMotionController implements ReactiveController { this._trackUserAnimation(element); } else if (element) { this._instantElement = element; - (instantElements ??= new InstantElements()).add(element); + markInstant(element); } } diff --git a/src/components/accordion/accordion.spec.ts b/src/components/accordion/accordion.spec.ts index b12752f23..46c5defb8 100644 --- a/src/components/accordion/accordion.spec.ts +++ b/src/components/accordion/accordion.spec.ts @@ -12,8 +12,10 @@ import { defineComponents } from '#internals/definitions/defineComponents.js'; import { allowMotion, clickWithMouse, + painted, resetLocation, } from '#internals/testing/helpers.spec.js'; +import { transitionsIn } from '#internals/testing/motion.spec.js'; import { simulateClick, simulateKeyboard, @@ -331,6 +333,37 @@ describe('Accordion', () => { }); }); + describe('Open motion', () => { + allowMotion(); + + beforeEach(async () => { + accordion = await fixture(createAccordion()); + panels = accordion.panels; + await painted(); + }); + + for (const [index, open] of [ + [2, true], + [1, false], + ] as const) { + it(`changes the spacing at once when \`open\` ${open ? 'opens' : 'closes'} a panel`, async () => { + panels[index].open = open; + await elementUpdated(panels[index]); + + expect(transitionsIn(accordion)).to.eql([]); + }); + } + + it('animates the spacing when a panel opens with `show()`', async () => { + panels[2].show(); + await elementUpdated(panels[2]); + + expect(transitionsIn(accordion)).to.include( + 'igc-expansion-panel margin-top' + ); + }); + }); + describe('Content found by the browser', () => { allowMotion(); diff --git a/src/components/accordion/spec.md b/src/components/accordion/spec.md index 42a1f9927..6aaef95df 100644 --- a/src/components/accordion/spec.md +++ b/src/components/accordion/spec.md @@ -28,6 +28,8 @@ - [Expand and collapse](#expand-and-collapse) - [Keyboard navigation](#keyboard-navigation) - [Nested](#nested) + - [Content found by the browser](#content-found-by-the-browser) + - [Open motion](#open-motion) - [Assumptions and limitations](#assumptions-and-limitations) - [Accessibility](#accessibility) - [ARIA roles and properties](#aria-roles-and-properties) @@ -42,6 +44,7 @@ | 2 | 2026-10-01 | The navigation skips panels that do not render | | 3 | 2026-10-21 | API descriptions aligned with the JSDoc. | | 4 | 2026-11-12 | A panel that the browser opens closes the others at once | +| 5 | 2026-11-20 | A change of `open` on a panel changes its spacing at once; the toggle methods and the user still animate it | ## Overview @@ -145,6 +148,9 @@ const panels = accordion.panels; // the direct expansion panel children Both methods resolve once the animations of the panels have completed. +The accordion animates the spacing around a panel that opens or closes with these methods, the panel methods or a +user action. A change of the `open` property of a panel shows at once, as the panel content does. + #### Nesting ```html @@ -251,6 +257,11 @@ with `@open-wc/testing` fixtures and assertions. The groups below mirror the `de 12. With single expansion and motion on, a link to an element in a collapsed panel opens it and closes the expanded panel above it, and the target stays in view. +### Open motion + +13. A change of `open` to `true` or to `false` on a panel starts no transitions. +14. `show()` on a panel animates its spacing. + ## Assumptions and limitations - Only direct `igc-expansion-panel` children are members of the accordion. diff --git a/src/components/dialog/dialog.spec.ts b/src/components/dialog/dialog.spec.ts index aa5d8a255..a32ff864c 100644 --- a/src/components/dialog/dialog.spec.ts +++ b/src/components/dialog/dialog.spec.ts @@ -773,6 +773,56 @@ describe('Dialog', () => { expect(nativeDialog.matches(':modal')).to.be.true; }); + it('fades the backdrop in on `show()`', async () => { + dialog.show(); + await elementUpdated(dialog); + + expect(getBackdropAnimations(nativeDialog)).to.not.be.empty; + }); + + it('shows the backdrop at once when `open` is set', async () => { + await openThroughProperty(); + + expect(getBackdropAnimations(nativeDialog)).to.be.empty; + }); + + it('shows the backdrop at once when the dialog opens again after a close that it cannot cancel', async () => { + await openThroughProperty(); + + nativeDialog.close(); + await oneEvent(nativeDialog, 'close'); + + expect(nativeDialog.matches(':modal')).to.be.true; + expect(getBackdropAnimations(nativeDialog)).to.be.empty; + }); + + it('shows the backdrop at once when an open dialog is appended again', async () => { + await openThroughProperty(); + + const parent = dialog.parentElement!; + dialog.remove(); + parent.append(dialog); + + expect(nativeDialog.matches(':modal')).to.be.true; + expect(getBackdropAnimations(nativeDialog)).to.be.empty; + }); + + it('shows the backdrop at once on a first render with `open`', async () => { + dialog = await fixture( + html`` + ); + nativeDialog = dialog.renderRoot.querySelector('dialog')!; + + expect(getBackdropAnimations(nativeDialog)).to.be.empty; + expect(nativeDialog.matches(':modal')).to.be.true; + }); + + it('shows the backdrop at once when `open` reopens the dialog during the exit', async () => { + await reopenDuringExit(); + + expect(getBackdropAnimations(nativeDialog)).to.be.empty; + }); + it('takes the styles of `::part(base)::backdrop`', async () => { const sheet = new CSSStyleSheet(); sheet.replaceSync( diff --git a/src/components/dialog/dialog.ts b/src/components/dialog/dialog.ts index 3b205a026..8bbd402a0 100644 --- a/src/components/dialog/dialog.ts +++ b/src/components/dialog/dialog.ts @@ -2,6 +2,7 @@ import { DialogResourceStringsEN } from 'igniteui-i18n-core'; import { html, LitElement, nothing, type PropertyValues } from 'lit'; import { property, state } from 'lit/decorators.js'; import { createRef, ref } from 'lit/directives/ref.js'; +import { finishCSSTransitions } from '#animations/css-transitions.js'; import { addAnimationController } from '#animations/player.js'; import { fadeIn, fadeOut } from '#animations/presets/fade/index.js'; import { @@ -300,6 +301,11 @@ export default class IgcDialogComponent extends I18nMixin( dialog.close(); if (this.open && this.isConnected) { dialog.showModal(); + + // Only `show()` fades the backdrop in. + if (!this._toggleController.opening) { + finishCSSTransitions(dialog, { subtree: true }); + } } } diff --git a/src/components/dialog/spec.md b/src/components/dialog/spec.md index d5d254ebf..c0e1f4fe3 100644 --- a/src/components/dialog/spec.md +++ b/src/components/dialog/spec.md @@ -55,6 +55,7 @@ | 7 | 2026-10-29 | The backdrop is the native `::backdrop`; the `backdrop` and `animating` parts are removed; a change of `open` against a running transition ends it | | 8 | 2026-11-04 | A `hide()` in the task of `show()` closes the dialog at once | | 9 | 2026-11-05 | A dialog out of the document closes when `open` changes to `false`; an append makes an open dialog modal again | +| 10 | 2026-11-20 | `open = true`, also on the first render and after an append, shows the backdrop at once; only `show()` fades it in | ## Overview @@ -162,6 +163,8 @@ await dialog.toggle(); The three methods animate the transition and resolve with whether it completed - `false` when the dialog was already in that state, when a newer transition superseded this one, or when a change of `open` ended it. Setting the `open` property instead opens or closes the dialog immediately, without animation and without emitting the close events. +This includes the backdrop, also on the first render: only `show()` fades it in. An append of an open dialog and a +reopen after a close that the dialog cannot cancel also show the backdrop at once. The dialog keeps its state when it moves in the document, or when you remove it and append it again: an open dialog, also one in its exit, is modal again after the append, and a dialog that closed while it was out of the @@ -356,6 +359,11 @@ The suite lives in [`dialog.spec.ts`](./dialog.spec.ts) and runs in a real brows `open = false` during the entrance lets the next `show()` open the dialog. A `hide()` right after, also in the same task, closes the dialog, and the ended exit does not change the new one. A `hide()` in the task of `show()` shows no dialog. +19. `show()` fades the backdrop in. These show the backdrop at once: + - `open = true`, and a first render with `open`; + - an `open` that opens the dialog again during the exit; + - an append of an open dialog; + - a reopen after a close that the dialog cannot cancel. ### Not covered by the suite diff --git a/src/components/expansion-panel/expansion-panel.spec.ts b/src/components/expansion-panel/expansion-panel.spec.ts index 9035f5736..ed0b03bb7 100644 --- a/src/components/expansion-panel/expansion-panel.spec.ts +++ b/src/components/expansion-panel/expansion-panel.spec.ts @@ -8,6 +8,7 @@ import { waitUntil, } from '@open-wc/testing'; import { spy } from 'sinon'; +import { getCSSTransitions } from '#animations/css-transitions.js'; import { altKey, @@ -21,7 +22,9 @@ import { allowMotion, clickWithMouse, getAnimationsFor, + painted, resetLocation, + withDocumentSheets, } from '#internals/testing/helpers.spec.js'; import { runHostAriaTests } from '#internals/testing/host-aria.spec.js'; import { @@ -595,4 +598,46 @@ describe('Expansion Panel', () => { }); }); }); + + describe('Open motion', () => { + allowMotion(); + + const sheet = new CSSStyleSheet(); + sheet.replaceSync(` + igc-expansion-panel { transition: margin-top 1s } + igc-expansion-panel[open] { margin-top: 20px } + `); + + /** The transitions of the host, which the app declares, after `change`. */ + async function hostTransitionsAfter( + change: (panel: IgcExpansionPanelComponent) => unknown + ): Promise { + let transitions: CSSTransition[] = []; + + await withDocumentSheets([sheet], async () => { + panel = await fixture(createDefaultPanel()); + await painted(); + + change(panel); + await elementUpdated(panel); + transitions = getCSSTransitions(panel); + }); + + return transitions; + } + + it('ends the transitions of the host when `open` changes', async () => { + const transitions = await hostTransitionsAfter((panel) => { + panel.open = true; + }); + + expect(transitions).to.be.empty; + }); + + it('keeps the transitions of the host for `show()`', async () => { + const transitions = await hostTransitionsAfter((panel) => panel.show()); + + expect(transitions).to.not.be.empty; + }); + }); }); diff --git a/src/components/expansion-panel/expansion-panel.ts b/src/components/expansion-panel/expansion-panel.ts index bd78bb247..f8fd9d1a9 100644 --- a/src/components/expansion-panel/expansion-panel.ts +++ b/src/components/expansion-panel/expansion-panel.ts @@ -1,6 +1,7 @@ -import { html, LitElement, nothing } from 'lit'; +import { html, LitElement, nothing, type PropertyValues } from 'lit'; import { property } from 'lit/decorators.js'; import { createRef, ref } from 'lit/directives/ref.js'; +import { finishCSSTransitions } from '#animations/css-transitions.js'; import { addAnimationController } from '#animations/player.js'; import { growVerIn, growVerOut } from '#animations/presets/grow/index.js'; import { @@ -148,6 +149,16 @@ export default class IgcExpansionPanelComponent extends EventEmitterMixin): void { + const changed = + properties.has('open') && properties.get('open') !== undefined; + + // A direct `open` change also ends the host transitions, such as the accordion spacing. + if (changed && !this._toggleController.busy) { + finishCSSTransitions(this); + } + } + private _handleClick(): void { this._headerRef.value?.focus(); this._toggle(); diff --git a/src/components/expansion-panel/spec.md b/src/components/expansion-panel/spec.md index 7973eb8ec..25be4ed8b 100644 --- a/src/components/expansion-panel/spec.md +++ b/src/components/expansion-panel/spec.md @@ -16,6 +16,7 @@ - [The indicator](#the-indicator) - [Programmatic control](#programmatic-control) - [Disabled state](#disabled-state) + - [Content found by the browser](#content-found-by-the-browser) - [Localization](#localization) - [Keyboard interactions](#keyboard-interactions) - [API](#api) @@ -32,6 +33,8 @@ - [User interactions](#user-interactions) - [Events tests](#events-tests) - [Host ARIA](#host-aria) + - [Content found by the browser](#content-found-by-the-browser-1) + - [Open motion](#open-motion) - [Assumptions and limitations](#assumptions-and-limitations) - [Accessibility](#accessibility) - [ARIA roles and properties](#aria-roles-and-properties) @@ -47,6 +50,7 @@ | 3 | 2026-10-21 | API descriptions aligned with the JSDoc. | | 4 | 2026-10-29 | A change of `open` against a running transition ends it | | 5 | 2026-11-12 | Find-in-page and links to an element open a collapsed panel | +| 6 | 2026-11-20 | A change of `open` also ends the transitions of the host, such as the spacing in an accordion | ## Overview @@ -161,7 +165,8 @@ state, and with `false` when it did not — the panel was already in the request superseded this one. A change of `open` against a running transition also ends it: the method resolves `false`, the animation stops, and the panel sends no `igcOpened` or `igcClosed`. -Setting the `open` property changes the state as well. +Setting the `open` property changes the state at once, with no animation. This includes the transitions of the host, +such as the spacing that an [accordion](../accordion/spec.md) gives the panel. #### Disabled state @@ -293,6 +298,11 @@ The suite lives in [`expansion-panel.spec.ts`](./expansion-panel.spec.ts) and ru 21. The open animation of a user toggle starts from the height of the content. 22. The content shows during the close animation, and it is inert only then. +### Open motion + +23. A change of `open` ends the transitions that the app declares on the host. +24. `show()` keeps the transitions of the host. + ## Assumptions and limitations - The panel animates its content; the methods do not resolve on the animation, unlike the bulk methods of the diff --git a/src/components/nav-drawer/nav-drawer.spec.ts b/src/components/nav-drawer/nav-drawer.spec.ts index 834ee5266..e1f2d1a80 100644 --- a/src/components/nav-drawer/nav-drawer.spec.ts +++ b/src/components/nav-drawer/nav-drawer.spec.ts @@ -926,6 +926,50 @@ describe('Navigation Drawer', () => { }); }); + describe('First render motion', () => { + allowMotion(); + + it('shows a drawer that is open on the first render at once', async () => { + navDrawer = await createNavDrawer(html` + + + + `); + await painted(); + + expect(transitionsIn(navDrawer)).to.eql([]); + expect(navDrawer.renderRoot.querySelector('dialog')!.matches(':modal')).to + .be.true; + }); + + it('slides in on a `show()` in the task that renders the drawer', async () => { + const parent = await fixture(html`
`); + navDrawer = document.createElement(IgcNavDrawerComponent.tagName); + parent.append(navDrawer); + + navDrawer.show(); + await elementUpdated(navDrawer); + + expect(transitionsIn(navDrawer)).to.include.members([ + 'dialog[part="base"] translate', + 'dialog[part="base"]::backdrop opacity', + ]); + }); + + it('animates an open from code after the first render', async () => { + navDrawer = await createNavDrawer(); + await painted(); + + navDrawer.open = true; + await elementUpdated(navDrawer); + + expect(transitionsIn(navDrawer)).to.include.members([ + 'dialog[part="base"] translate', + 'dialog[part="base"]::backdrop opacity', + ]); + }); + }); + runInvokerCommandsTests({ tagName: IgcNavDrawerComponent.tagName, commandFor: 'invoker-nav-drawer', diff --git a/src/components/nav-drawer/nav-drawer.ts b/src/components/nav-drawer/nav-drawer.ts index 6dd745be7..2e6587896 100644 --- a/src/components/nav-drawer/nav-drawer.ts +++ b/src/components/nav-drawer/nav-drawer.ts @@ -3,6 +3,7 @@ import { property } from 'lit/decorators.js'; import { cache } from 'lit/directives/cache.js'; import { createRef, ref } from 'lit/directives/ref.js'; import { + finishCSSTransitions, getCSSTransitions, transitionsSettled, } from '#animations/css-transitions.js'; @@ -205,7 +206,7 @@ export default class IgcNavDrawerComponent extends EventEmitterMixin): void { // The opener can be in the mini variant, so hide the mini variant after the dialog opens, // and show it before the dialog closes. A slot change also requests an update. if (this.open) { @@ -215,6 +216,19 @@ export default class IgcNavDrawerComponent extends EventEmitterMixin}` in React and an `@if` block in Angular. To slide such a drawer in, call `show()`, also +in the task that renders it. Or set `open` after the first render, for example after `updateComplete`. After the first +render, a change of `open` animates. + **Motion of the items.** `active` is view state, as the `selected` of a tab: a change fades, also from code, and the first render shows at once. With `prefers-reduced-motion: reduce`, the items do not animate. @@ -357,6 +365,12 @@ In the Indigo theme, for an item in a relative drawer. The Material item does no 17. A change of `active` from code starts transitions. 18. With reduced motion, a hover starts none. +### First render motion + +19. A drawer that is open on its first render starts no transitions and is modal. +20. A `show()` in the task that renders the drawer slides the drawer in. +21. A change of `open` to `true` after the first render slides the drawer in and fades the backdrop in. + ## Assumptions and limitations - The drawer holds no routing logic: the `active` state of an item is set by the application. diff --git a/src/components/tabs/spec.md b/src/components/tabs/spec.md index b09d1c3fa..2ac7ad2b6 100644 --- a/src/components/tabs/spec.md +++ b/src/components/tabs/spec.md @@ -15,6 +15,7 @@ This directory hosts two public components: [`igc-tabs`](#igc-tabs) and [`igc-ta - [Developer experience](#developer-experience) - [Basic initialization](#basic-initialization) - [Selection](#selection) + - [Content found by the browser](#content-found-by-the-browser) - [Alignment](#alignment) - [Header position](#header-position) - [Activation mode](#activation-mode) @@ -46,6 +47,8 @@ This directory hosts two public components: [`igc-tabs`](#igc-tabs) and [`igc-ta - [Column layout](#column-layout) - [Column scrolling](#column-scrolling) - [Column themes](#column-themes) + - [Content found by the browser](#content-found-by-the-browser-1) + - [First render motion](#first-render-motion) - [Assumptions and limitations](#assumptions-and-limitations) - [Accessibility](#accessibility) - [ARIA roles and properties](#aria-roles-and-properties) @@ -70,6 +73,7 @@ This directory hosts two public components: [`igc-tabs`](#igc-tabs) and [`igc-ta | 12 | 2026-11-04 | `igcNavigate` is not composed, so it does not reach a shadow host around the tabs; `_parent` and `_top` count as `_self` in a page that is not in a frame | | 13 | 2026-11-05 | With `prefers-reduced-motion: reduce`, the scroll buttons and the selection scroll the header strip at once; the scroll buttons follow the `scroll-behavior` of the `tabs` part | | 14 | 2026-11-12 | Find-in-page and links to an element in a panel select its tab; a panel that is not selected has `hidden="until-found"` | +| 15 | 2026-11-20 | The first render shows at once: the selected indicator and the colors of the selected header do not animate, also when the tabs show later than they render | ## Overview @@ -184,6 +188,11 @@ The `selected` attribute of the tabs also sets the selection, after each change selected at once, the last one in document order wins, as in the initial markup. A selected tab that moves keeps the selection. +**Motion.** The first render shows at once: the selected indicator takes its place, and the selected header shows its +colors, with no transition. This also applies to tabs that show for the first time later than they render, for example +in a closed panel. The first render ends in the first frame after the header strip shows. After that, a selection +change slides the indicator and fades the header colors, also when it comes from code. + #### Content found by the browser A panel that is not selected has `hidden="until-found"`, or plain `hidden` when its tab is disabled. Find-in-page @@ -614,6 +623,13 @@ The groups below mirror the `describe` blocks. 64. A link tab is selected without following its link. 65. A collapsed expansion panel in a panel opens, and the tab is selected. +### First render motion + +66. The first render starts no transitions in the Material, Fluent and Indigo themes: the indicator does not slide in, + and the selected header does not fade in. This also applies to a tab that the application selects and to a column. +67. Tabs that show for the first time after they render, as under a `display: none` parent, start no transitions. +68. A selection change after the first render slides the indicator. + ## Assumptions and limitations - A tab owns both its header and its body; the two cannot be declared separately. diff --git a/src/components/tabs/tab-dom.ts b/src/components/tabs/tab-dom.ts index 784557d07..48ef4be02 100644 --- a/src/components/tabs/tab-dom.ts +++ b/src/components/tabs/tab-dom.ts @@ -1,5 +1,6 @@ import { createRef } from 'lit/directives/ref.js'; import type { StyleInfo } from 'lit/directives/style-map.js'; +import { finishCSSTransitions } from '#animations/css-transitions.js'; import { isLTR, replaceStyles, setStyles } from '#internals/utils/dom.js'; import { linkOpensElsewhere } from '#internals/utils/events.js'; import { asNumber } from '#internals/utils/math.js'; @@ -89,6 +90,9 @@ export class TabsHelpers { /** Whether the next layout scrolls the selected tab into view. */ public scrollOnLayout = false; + /** Whether the first render, which shows at once, still lasts. It ends a frame after the strip first shows. */ + public firstRender = true; + /** The height of the height probe at the last check, and whether it was definite. */ private _heightCheck = { probe: -1, definite: false }; @@ -354,7 +358,7 @@ export class TabsHelpers { this._host.requestUpdate(); } - /** Moves the indicator to the header of `active`. Without `animate`, it moves at once. */ + /** Moves the indicator to the header of `active`, at once without `animate` or on the first render. */ public async setIndicator( active?: IgcTabComponent, animate = true @@ -369,6 +373,12 @@ export class TabsHelpers { return; } + if (this.firstRender) { + requestAnimationFrame(() => { + this.firstRender = false; + }); + } + const header = getTabHeader(active); if (!header) { @@ -396,10 +406,8 @@ export class TabsHelpers { transform: `translate${column ? 'Y' : 'X'}(${offset}px)`, }); - if (!animate) { - for (const animation of indicator.getAnimations()) { - animation.finish(); - } + if (!animate || this.firstRender) { + finishCSSTransitions(indicator); } } } diff --git a/src/components/tabs/tabs.spec.ts b/src/components/tabs/tabs.spec.ts index 8ca6cc94e..dc5b79c40 100644 --- a/src/components/tabs/tabs.spec.ts +++ b/src/components/tabs/tabs.spec.ts @@ -6,6 +6,7 @@ import { nextFrame, waitUntil, } from '@open-wc/testing'; +import type { TemplateResult } from 'lit'; import { range } from 'lit/directives/range.js'; import { spy } from 'sinon'; import { internalsOf } from '#internals/controllers/internals.js'; @@ -25,10 +26,12 @@ import { clickWithMouse, finishAnimationsFor, isUnderPageLayer, + painted, resetLocation, withDocumentSheets, } from '#internals/testing/helpers.spec.js'; import { runHiddenAncestorTests } from '#internals/testing/hidden-ancestor.spec.js'; +import { transitionsIn, withTheme } from '#internals/testing/motion.spec.js'; import { simulateClick, simulateKeyboard, @@ -38,6 +41,7 @@ import { getScaleFactor } from '#internals/utils/dom.js'; import { preventDefault } from '#internals/utils/events.js'; import { asNumber } from '#internals/utils/math.js'; import { configureTheme } from '#theming/config.js'; +import type { Theme } from '#theming/types.js'; import { styles as bootstrap } from '../../styles/themes/light/bootstrap.css.js'; import { styles as fluent } from '../../styles/themes/light/fluent.css.js'; import { styles as indigo } from '../../styles/themes/light/indigo.css.js'; @@ -3888,6 +3892,91 @@ describe('Tabs component', () => { }); }); + describe('First render motion', () => { + allowMotion(); + + const twoTabs = html` + + One + Two + + `; + + /** + * The transitions that run once `template` renders and paints in `theme`, and once + * `change`, when given, paints. + */ + async function transitionsAfter( + template: TemplateResult, + theme: Theme = 'material', + change?: (root: HTMLElement) => void + ): Promise { + return withTheme(theme, async () => { + const root = await fixture(template); + await painted(); + + if (change) { + change(root); + await painted(); + } + + return transitionsIn(root); + }); + } + + for (const theme of ['material', 'fluent', 'indigo'] as const) { + it(`shows the first render at once (${theme})`, async () => { + expect(await transitionsAfter(twoTabs, theme)).to.eql([]); + }); + } + + it('shows a tab that the app selects at once on the first render', async () => { + const template = html` + + One + Two + + `; + + expect(await transitionsAfter(template)).to.eql([]); + }); + + it('shows the first render of a column at once', async () => { + const template = html` + + One + Two + + `; + + expect(await transitionsAfter(template)).to.eql([]); + }); + + it('shows the tabs at once when they show for the first time', async () => { + const transitions = await transitionsAfter( + html`
${twoTabs}
`, + 'material', + (parent) => { + parent.style.display = ''; + } + ); + + expect(transitions).to.eql([]); + }); + + it('slides the indicator for a selection change after the first render', async () => { + const transitions = await transitionsAfter( + twoTabs, + 'material', + (tabs) => { + (tabs as IgcTabsComponent).select('Two'); + } + ); + + expect(transitions).to.include('span transform'); + }); + }); + runHiddenAncestorTests(html` One diff --git a/src/components/tabs/tabs.ts b/src/components/tabs/tabs.ts index 96110ebf0..7b548cd57 100644 --- a/src/components/tabs/tabs.ts +++ b/src/components/tabs/tabs.ts @@ -13,6 +13,7 @@ import { import { cache } from 'lit/directives/cache.js'; import { ref } from 'lit/directives/ref.js'; import { styleMap } from 'lit/directives/style-map.js'; +import { markInstant } from '#animations/value-state.js'; import { tabsHeaderPositionContext } from '#internals/context.js'; import { addContextProvider } from '#internals/controllers/context-provider.js'; import { addInternalsController } from '#internals/controllers/internals.js'; @@ -539,6 +540,11 @@ export default class IgcTabsComponent extends EventEmitterMixin { expect(opening.firstCall.firstArg.detail).to.equal(instance); }); + it('should report the request in flight as opening or closing', async () => { + const { toggleController } = instance; + const state = () => [ + toggleController.busy, + toggleController.opening, + toggleController.closing, + ]; + + const opening = toggleController.show(); + expect(state()).to.eql([true, true, false]); + await opening; + + const closing = toggleController.hide(); + expect(state()).to.eql([true, false, true]); + await closing; + + expect(state()).to.eql([false, false, false]); + }); + it('should send the "-ed" event as the default transition does for a synchronous result', async () => { const host = await createInstance(syncResultTag); const opened = spy(); diff --git a/src/internals/controllers/toggle.ts b/src/internals/controllers/toggle.ts index 15333d060..8eec8c5a6 100644 --- a/src/internals/controllers/toggle.ts +++ b/src/internals/controllers/toggle.ts @@ -175,6 +175,16 @@ class ToggleController { * hops, which shift the timing of caller code against `updateComplete`. */ + /** Whether a `show()` or a `hide()` is in flight. */ + public get busy(): boolean { + return this._pending !== undefined; + } + + /** Whether a `show()` is in flight. */ + public get opening(): boolean { + return this._pending === true; + } + /** Whether a `hide()` is in flight. */ public get closing(): boolean { return this._pending === false; diff --git a/src/styles/utilities/_mixins.scss b/src/styles/utilities/_mixins.scss index d13ca5178..b676e510c 100644 --- a/src/styles/utilities/_mixins.scss +++ b/src/styles/utilities/_mixins.scss @@ -47,10 +47,12 @@ } /// Turns off all transitions under the instant mark of -/// `#animations/value-state.js`, slotted elements included. With `$on-host` -/// the mark is the host custom state, else `[data-instant]` on a shadow element. -/// The mark ends in the first frame with no change from code. `!important` -/// beats the theme and the consumer `::part()` transitions. +/// `#animations/value-state.js`, slotted elements included. A change of value +/// state from code sets the mark, and the tabs also set it on their first +/// render. With `$on-host` the mark is the host custom state, else +/// `[data-instant]` on a shadow element. The mark ends in the first frame with +/// no change from code. `!important` beats the theme and the consumer +/// `::part()` transitions. @mixin value-state-transitions($on-host: false) { $mark: '[data-instant]';