From 082fcc2dab80ad5e190d6be571d0745f9daf7eab Mon Sep 17 00:00:00 2001 From: Radoslav Karaivanov Date: Fri, 20 Nov 2026 11:38:48 +0200 Subject: [PATCH 1/3] feat(forms): animate checked and selected states only for a user change A checkbox, switch, radio, toggle button, list item and navigation drawer item now animate only a change that the user makes, as the chip does since #2629. So does the label of an input, textarea or date input. A change from code and the first render show at once, so a virtualized list no longer animates its rows while it scrolls. In a fast scroll of 5000 rows with a checkbox, a switch and a radio, style recalc dropped from 979 ms to 187 ms. A change that a component makes for the user also animates: the radio that a group unchecks, the toggle that a single selection deselects, the items of a tree cascade, and the options and input of a combo or select. A value that app code sets, also in an igcChange handler, shows at once. Hover, focus and the invalid state still fade. With prefers-reduced-motion: reduce, these controls have no transitions of their own. The Material switch no longer plays its thumb keyframes. The shared logic is in src/animations/value-state.ts, and the chip now uses it. --- .github/CODING_GUIDELINES.md | 2 + CHANGELOG.md | 3 + src/animations/css-transitions.ts | 14 +- src/animations/value-state.spec.ts | 304 ++++++++++++++++++ src/animations/value-state.ts | 252 +++++++++++++++ .../button-group/button-group.spec.ts | 51 +++ src/components/button-group/button-group.ts | 2 + src/components/button-group/spec.md | 22 ++ .../button-group/themes/button.base.scss | 12 +- .../button-group/toggle-button.spec.ts | 8 +- src/components/button-group/toggle-button.ts | 9 + src/components/checkbox/checkbox-base.ts | 14 + src/components/checkbox/checkbox.spec.ts | 24 ++ src/components/checkbox/checkbox.ts | 4 + src/components/checkbox/spec.md | 30 ++ src/components/checkbox/switch.spec.ts | 12 + .../checkbox/themes/checkbox.base.scss | 33 +- .../shared/checkbox/checkbox.bootstrap.scss | 11 +- .../shared/checkbox/checkbox.fluent.scss | 11 +- .../shared/checkbox/checkbox.indigo.scss | 4 +- .../shared/checkbox/checkbox.material.scss | 5 +- .../themes/shared/switch/switch.common.scss | 5 +- .../themes/shared/switch/switch.material.scss | 8 +- .../checkbox/themes/switch.base.scss | 39 +-- src/components/chip/chip.spec.ts | 25 +- src/components/chip/chip.ts | 142 +------- src/components/chip/themes/chip.base.scss | 9 +- src/components/color-picker/spec.md | 5 + src/components/combo/combo-selection.spec.ts | 79 +++++ src/components/combo/combo.ts | 7 + src/components/combo/spec.md | 15 + src/components/date-picker/spec.md | 5 + src/components/date-range-picker/spec.md | 5 + .../date-time-input/date-time-input.base.ts | 4 + .../date-time-input/date-time-input.spec.ts | 18 ++ src/components/date-time-input/spec.md | 16 + src/components/file-input/spec.md | 7 + src/components/input/input-base.ts | 6 + src/components/input/input.spec.ts | 43 +++ src/components/input/spec.md | 23 ++ src/components/input/themes/input.base.scss | 6 + .../input/themes/shared/input.bootstrap.scss | 20 +- .../input/themes/shared/input.indigo.scss | 27 +- .../input/themes/shared/input.material.scss | 27 +- src/components/list/list-item.ts | 3 + src/components/list/list.spec.ts | 15 + src/components/list/spec.md | 15 + src/components/list/themes/item.base.scss | 7 +- src/components/mask-input/spec.md | 10 + src/components/nav-drawer/nav-drawer-item.ts | 5 + src/components/nav-drawer/nav-drawer.spec.ts | 29 ++ src/components/nav-drawer/spec.md | 16 + .../nav-drawer/themes/item.base.scss | 6 +- .../radio-group/radio-group.spec.ts | 70 +++- src/components/radio-group/spec.md | 13 + src/components/radio/radio.spec.ts | 11 + src/components/radio/radio.ts | 18 +- src/components/radio/spec.md | 17 + src/components/radio/themes/radio.base.scss | 27 +- .../radio/themes/shared/radio.fluent.scss | 11 +- src/components/select/select.spec.ts | 30 ++ src/components/select/spec.md | 10 + src/components/textarea/spec.md | 16 + src/components/textarea/textarea.spec.ts | 18 ++ src/components/textarea/textarea.ts | 3 + .../themes/shared/textarea.bootstrap.scss | 5 +- .../themes/shared/textarea.indigo.scss | 11 +- .../themes/shared/textarea.material.scss | 21 +- .../textarea/themes/textarea.base.scss | 11 +- src/components/tree/spec.md | 14 + src/components/tree/tree-selection.spec.ts | 63 +++- src/components/tree/tree.selection.ts | 33 +- src/internals/mixins/forms/associated.ts | 19 ++ src/internals/testing/helpers.spec.ts | 22 +- src/internals/testing/hidden-ancestor.spec.ts | 8 +- src/internals/testing/value-state.spec.ts | 121 +++++++ src/styles/utilities/_mixins.scss | 33 ++ stories/date-range-picker.stories.ts | 4 +- 78 files changed, 1807 insertions(+), 276 deletions(-) create mode 100644 src/animations/value-state.spec.ts create mode 100644 src/animations/value-state.ts create mode 100644 src/internals/testing/value-state.spec.ts diff --git a/.github/CODING_GUIDELINES.md b/.github/CODING_GUIDELINES.md index d11afb104..a4e4c7741 100644 --- a/.github/CODING_GUIDELINES.md +++ b/.github/CODING_GUIDELINES.md @@ -286,6 +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` / `markUserChange` | `#animations/value-state.js` | Showing a change of value state from code at once, and animating only a change by the user | For pointer resizing and dragging, use the `resizable()` and `draggable()` directives from `#internals/directives/`. @@ -631,6 +632,7 @@ Each component has tests in `[component].spec.ts`. They cover: | `validity-helpers.spec.js` | Validity assertions and `runValidationContainerTests`. Await it. | | `invoker-commands.spec.js` | `runInvokerCommandsTests` | | `helpers.spec.js` | Animation, focus, scroll and style helpers, and `axeReflectedRelationsOptions` | + | `value-state.spec.js` | `runValueStateMotionTests`, `transitionsIn` and `withTheme` | | `fast-check-setup.spec.js` | `fc` with the seed, `SLOW_PROPERTY_RUNS`, `orderedPair` and `withFixture` | | `date-arbitraries.spec.js` | Date arbitraries, wall clocks and `assumeWallClock` for date properties | diff --git a/CHANGELOG.md b/CHANGELOG.md index 549f5c23c..79d2a25a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - `dot-scale` sets the size of the data modules, from 0.7 to 1 of their cell, to leave a gap between them. The corners keep their full size. ### Changed +- #### Button group, Checkbox, Combo, Date time input, File input, Input, List, Mask input, Navigation drawer, Radio, Switch, Textarea, Tree + - Only a change by the user animates a checkbox, a switch, a radio, a toggle button, the label of an input or a textarea (also the inputs of the pickers, the select and the combo), a list item and a navigation drawer item, 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 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 have no transitions of their own, and a transition that the app adds to a part still applies. + - The Material switch moves its thumb with a transition only. Before, it also played a keyframe animation, also on the first render. - #### Chip - A selection change by the user animates the chip, as in Ignite UI for Angular. The colors fade, and the selection indicator opens and fades in, or fades out and closes. A change from code and the first render show at once, so a virtualized list does not animate its chips while it scrolls. With `prefers-reduced-motion: reduce`, the chip does not animate. [#2621](https://github.com/IgniteUI/igniteui-webcomponents/issues/2621) - #### Combo diff --git a/src/animations/css-transitions.ts b/src/animations/css-transitions.ts index edaba8718..7403750d9 100644 --- a/src/animations/css-transitions.ts +++ b/src/animations/css-transitions.ts @@ -1,14 +1,18 @@ /** * Returns the CSS transitions of `element`, and of its descendants with - * `{ subtree: true }`. Author animations, which can run forever, are left out. + * `{ subtree: true }`, or of all the tree of a shadow root. Author animations, + * which can run forever, are left out. */ export function getCSSTransitions( - element: Element, + element: Element | ShadowRoot, options?: GetAnimationsOptions ): CSSTransition[] { - return element - .getAnimations(options) - .filter((animation) => animation instanceof CSSTransition); + const animations = + element instanceof ShadowRoot + ? element.getAnimations() + : element.getAnimations(options); + + return animations.filter((animation) => animation instanceof CSSTransition); } /** Returns a promise that settles when each transition finishes or is canceled. */ diff --git a/src/animations/value-state.spec.ts b/src/animations/value-state.spec.ts new file mode 100644 index 000000000..cc7331c3c --- /dev/null +++ b/src/animations/value-state.spec.ts @@ -0,0 +1,304 @@ +import { + defineCE, + elementUpdated, + expect, + fixture, + nextFrame, + unsafeStatic, +} from '@open-wc/testing'; +import { css, html, LitElement } from 'lit'; +import { property } from 'lit/decorators.js'; +import { html as staticHtml } from 'lit/static-html.js'; +import { addInternalsController } from '#internals/controllers/internals.js'; +import { + allowMotion, + finishAnimationsFor, + painted, +} from '#internals/testing/helpers.spec.js'; +import { transitionsIn } from '#internals/testing/value-state.spec.js'; +import { + addValueStateMotion, + isUserChange, + markUserChange, +} from './value-state.js'; + +/** A control whose base fades its color on a change of `on`. */ +class TestControl extends LitElement { + public static override styles = css` + [part='base'] { + transition: background-color 1s linear; + background-color: rgb(0, 0, 0); + } + + :host([on]) [part='base'] { + background-color: rgb(255, 255, 255); + } + + [data-instant] { + transition: none !important; + } + `; + + @property({ type: Boolean, reflect: true }) + public on = false; + + /** A value whose change always shows at once. */ + @property({ type: Boolean }) + public locked = false; + + public settledCount = 0; + + public readonly motion = addValueStateMotion(this, { + target: () => this.base, + watch: () => [this.on], + instant: () => [this.locked], + settled: () => this.settledCount++, + }); + + public get base(): HTMLElement { + return this.renderRoot.querySelector('[part="base"]')!; + } + + /** Toggles `on` as the user does. */ + public toggle(): void { + markUserChange(this); + this.on = !this.on; + } + + protected override render() { + return html`
`; + } +} + +/** A control whose host fades its color, so the mark is on the host. */ +class TestHostControl extends LitElement { + public static override styles = css` + :host { + display: block; + transition: background-color 1s linear; + background-color: rgb(0, 0, 0); + } + + :host([on]) { + background-color: rgb(255, 255, 255); + } + + :host(:state(ig-instant)) { + transition: none !important; + } + `; + + @property({ type: Boolean, reflect: true }) + public on = false; + + constructor() { + super(); + addInternalsController(this); + addValueStateMotion(this, { + target: () => this, + watch: () => [this.on], + }); + } +} + +/** An owner that renders a control in its shadow root. */ +class TestOwner extends LitElement { + @property({ type: Boolean }) + public on = false; + + public get control(): TestControl { + return this.renderRoot.querySelector(controlTag)!; + } + + /** Changes the control as the result of a user action on the owner. */ + public toggle(): void { + markUserChange(this); + this.on = !this.on; + } + + protected override render() { + return staticHtml`<${unsafeStatic(controlTag)} ?on=${this.on}>`; + } +} + +const controlTag = defineCE(TestControl); +const hostControlTag = defineCE(TestHostControl); +const ownerTag = defineCE(TestOwner); + +async function createControl(): Promise { + const control = await fixture( + staticHtml`<${unsafeStatic(controlTag)}>` + ); + await painted(); + return control; +} + +describe('Value state motion', () => { + allowMotion(); + + describe('User changes', () => { + it('ends a mark that no update takes with the frame', async () => { + const control = await createControl(); + + markUserChange(control); + expect(isUserChange(control)).to.be.true; + + await nextFrame(); + expect(isUserChange(control)).to.be.false; + }); + + it('takes the mark in the next update', async () => { + const control = await createControl(); + + control.toggle(); + await elementUpdated(control); + + expect(isUserChange(control)).to.be.false; + }); + + it('counts a change inside the shadow root of a marked owner', async () => { + const owner = await fixture( + staticHtml`<${unsafeStatic(ownerTag)}>` + ); + await painted(); + + markUserChange(owner); + expect(isUserChange(owner.control)).to.be.true; + }); + }); + + describe('Animation', () => { + it('animates a change by the user', async () => { + const control = await createControl(); + + control.toggle(); + await elementUpdated(control); + + expect(control.base.hasAttribute('data-instant')).to.be.false; + expect(control.motion.userAnimating).to.be.true; + expect(transitionsIn(control)).to.not.be.empty; + }); + + it('animates a change that a marked owner applies', async () => { + const owner = await fixture( + staticHtml`<${unsafeStatic(ownerTag)}>` + ); + await painted(); + + owner.toggle(); + await elementUpdated(owner); + await elementUpdated(owner.control); + + expect(transitionsIn(owner.control)).to.not.be.empty; + }); + + it('calls settled when the transitions of a user change end', async () => { + const control = await createControl(); + + control.toggle(); + await elementUpdated(control); + finishAnimationsFor(control.shadowRoot!); + await nextFrame(); + + expect(control.motion.userAnimating).to.be.false; + expect(control.settledCount).to.equal(1); + }); + + it('joins a change from code that comes during a user change', async () => { + const control = await createControl(); + + control.toggle(); + await elementUpdated(control); + await painted(); + + // An app that reverts the change. + control.on = false; + await elementUpdated(control); + + expect(control.base.hasAttribute('data-instant')).to.be.false; + expect(transitionsIn(control)).to.not.be.empty; + }); + + it('shows a change of an instant value at once, also during a user change', async () => { + const control = await createControl(); + + control.toggle(); + await elementUpdated(control); + + control.locked = true; + control.on = false; + await elementUpdated(control); + + expect(control.motion.userAnimating).to.be.false; + + expect(control.base.hasAttribute('data-instant')).to.be.true; + expect(transitionsIn(control)).to.eql([]); + }); + }); + + describe('Changes from code', () => { + it('shows the first render at once', async () => { + const control = await fixture( + staticHtml`<${unsafeStatic(controlTag)} on>` + ); + await painted(); + + expect(control.base.hasAttribute('data-instant')).to.be.false; + expect(transitionsIn(control)).to.eql([]); + }); + + it('shows a change from code at once', async () => { + const control = await createControl(); + + control.on = true; + await elementUpdated(control); + + expect(control.base.hasAttribute('data-instant')).to.be.true; + expect(transitionsIn(control)).to.eql([]); + }); + + it('turns the transitions on again in the first frame without a change from code', async () => { + const control = await createControl(); + + // A virtualized list that changes the control in each frame. + for (let i = 0; i < 3; i++) { + control.on = !control.on; + await elementUpdated(control); + await nextFrame(); + expect(control.base.hasAttribute('data-instant'), `frame ${i}`).to.be + .true; + } + + await painted(); + expect(control.base.hasAttribute('data-instant')).to.be.false; + }); + + it('marks a host with the custom state', async () => { + const control = await fixture( + staticHtml`<${unsafeStatic(hostControlTag)}>` + ); + await painted(); + + control.on = true; + await elementUpdated(control); + + expect(control.matches(':state(ig-instant)')).to.be.true; + expect(control.hasAttribute('data-instant')).to.be.false; + expect(transitionsIn(control)).to.eql([]); + + await painted(); + expect(control.matches(':state(ig-instant)')).to.be.false; + }); + + it('clears the mark of a control that leaves the document', async () => { + const control = await createControl(); + const base = control.base; + + control.on = true; + await elementUpdated(control); + control.remove(); + + expect(base.hasAttribute('data-instant')).to.be.false; + }); + }); +}); diff --git a/src/animations/value-state.ts b/src/animations/value-state.ts new file mode 100644 index 000000000..ad695fdac --- /dev/null +++ b/src/animations/value-state.ts @@ -0,0 +1,252 @@ +import type { ReactiveController, ReactiveControllerHost } from 'lit'; +import { internalsOf } from '#internals/controllers/internals.js'; +import { sameItems } from '#internals/utils/arrays.js'; +import { getCSSTransitions, transitionsSettled } from './css-transitions.js'; + +type ValueStateHost = ReactiveControllerHost & HTMLElement; + +const NO_VALUES: readonly unknown[] = []; + +/** + * The elements whose next update is a user change. The marks end with the + * frame, so a mark that no update takes does not animate a later change. + */ +const userChanges = new Set(); +let userChangesFrame = 0; + +/** + * Marks the next update of `element` as a user change. A control marks itself; + * an owner marks itself, or the controls of its light DOM that it changes. + */ +export function markUserChange(element: Element): void { + userChanges.add(element); + userChangesFrame ||= requestAnimationFrame(() => { + userChanges.clear(); + userChangesFrame = 0; + }); +} + +/** Ends the user change of `element`, as when code overrides it. */ +export function unmarkUserChange(element: Element): void { + userChanges.delete(element); +} + +/** Whether `element`, or the host of a shadow root around it, is marked. */ +export function isUserChange(element: Element): boolean { + if (userChanges.size === 0) { + return false; + } + + for (let node: Element | undefined = element; node; node = hostOf(node)) { + if (userChanges.has(node)) { + return true; + } + } + + return false; +} + +function hostOf(element: Element): Element | undefined { + const root = element.getRootNode(); + return root instanceof ShadowRoot ? root.host : undefined; +} + +/** A host takes the `ig-instant` custom state; a shadow element, `data-instant`. */ +function setInstant(element: Element, instant: boolean): void { + const internals = internalsOf(element); + + if (internals) { + internals.setState('ig-instant', instant); + } else { + element.toggleAttribute('data-instant', instant); + } +} + +/** + * The marked elements. They lose the mark in the first frame with no change + * from code, so a scroll that changes controls in each frame keeps it. + */ +class InstantElements { + private readonly _elements = new Set(); + private _changedInFrame = false; + private _quietFrameCheckScheduled = false; + + public add(element: Element): void { + setInstant(element, true); + this._elements.add(element); + this._changedInFrame = true; + + if (!this._quietFrameCheckScheduled) { + this._quietFrameCheckScheduled = true; + requestAnimationFrame(this._clearInQuietFrame); + } + } + + public delete(element: Element): void { + if (this._elements.delete(element)) { + setInstant(element, false); + } + } + + private readonly _clearInQuietFrame = (): void => { + this._quietFrameCheckScheduled = this._changedInFrame; + this._changedInFrame = false; + + if (this._quietFrameCheckScheduled) { + requestAnimationFrame(this._clearInQuietFrame); + return; + } + + for (const element of this._elements) { + setInstant(element, false); + } + this._elements.clear(); + }; +} + +// Created on first use, so a control that only marks user changes does not bundle it. +let instantElements: InstantElements | undefined; + +/** A host transitions itself and its shadow root, not its slotted content. */ +function transitionsOfTarget(target: Element): CSSTransition[] { + const { shadowRoot } = target; + + return shadowRoot + ? [...getCSSTransitions(target), ...getCSSTransitions(shadowRoot)] + : getCSSTransitions(target, { subtree: true }); +} + +export interface ValueStateMotionOptions { + /** The values whose change restyles the control, in a fixed order. */ + watch: () => readonly unknown[]; + /** The values whose change shows at once, also during a user change. */ + instant?: () => readonly unknown[]; + /** The shadow element to mark. Without it, the host, which needs ElementInternals. */ + target?: () => Element | null | undefined; + /** Called when the transitions of a user change end. */ + settled?: () => void; +} + +/** + * Shows a change of the value state of a control at once, unless the user made + * it. A change from code while the transitions of a user change run joins them, + * so a framework that renders again after the event keeps the animation. + */ +export class ValueStateMotionController implements ReactiveController { + private readonly _host: ValueStateHost; + private readonly _options: ValueStateMotionOptions; + + private _values?: readonly unknown[]; + private _instantValues = NO_VALUES; + private _mode?: 'animated' | 'at-once'; + private _marked?: Element; + + /** Identifies the running user change; a newer change replaces it. */ + private _userAnimation?: object; + + public get userAnimating(): boolean { + return this._userAnimation !== undefined; + } + + constructor(host: ValueStateHost, options: ValueStateMotionOptions) { + this._host = host; + this._options = options; + host.addController(this); + } + + /** @internal */ + public hostUpdate(): void { + const values = this._options.watch(); + const instantValues = this._options.instant?.() ?? NO_VALUES; + const previous = this._values; + const cut = !sameItems(this._instantValues, instantValues); + const marked = userChanges.delete(this._host); + + this._values = values; + this._instantValues = instantValues; + + // The first render has no styles to transition from. + if (!previous || (!cut && sameItems(previous, values))) { + return; + } + + if (!cut && (marked || this._userAnimation || isUserChange(this._host))) { + this._userAnimation = {}; + this._mode = 'animated'; + } else { + this._userAnimation = undefined; + this._mode = 'at-once'; + } + } + + /** @internal */ + public hostUpdated(): void { + const mode = this._mode; + + if (!mode) { + return; + } + + const { target } = this._options; + const element = target ? target() : this._host; + this._mode = undefined; + + if (mode === 'animated') { + this._trackUserAnimation(element); + } else if (element) { + this._marked = element; + (instantElements ??= new InstantElements()).add(element); + } + } + + /** @internal */ + public hostDisconnected(): void { + if (this._marked) { + instantElements?.delete(this._marked); + this._marked = undefined; + } + } + + /** A disconnected control has no target and no transitions. */ + private async _trackUserAnimation(target?: Element | null): Promise { + const token = this._userAnimation; + let transitions: CSSTransition[] = []; + + if (target) { + instantElements?.delete(target); + transitions = transitionsOfTarget(target); + } + + await transitionsSettled(transitions); + + if (this._userAnimation === token) { + this._userAnimation = undefined; + this._options.settled?.(); + } + } +} + +export function addValueStateMotion( + host: ValueStateHost, + options: ValueStateMotionOptions +): ValueStateMotionController { + return new ValueStateMotionController(host, options); +} + +type FieldHost = ValueStateHost & { + disabled: boolean; + outlined: boolean; +}; + +/** + * Shows a change from code of a text field at once. `valueState` is the part of + * the value that restyles the field, such as its filled state. + */ +export function addFieldValueStateMotion( + host: FieldHost, + valueState: () => unknown +): void { + addValueStateMotion(host, { + watch: () => [valueState(), host.disabled, host.outlined], + }); +} diff --git a/src/components/button-group/button-group.spec.ts b/src/components/button-group/button-group.spec.ts index f76a213e1..f5f75aaff 100644 --- a/src/components/button-group/button-group.spec.ts +++ b/src/components/button-group/button-group.spec.ts @@ -10,15 +10,22 @@ import { } from '#internals/controllers/key-bindings.js'; import { defineComponents } from '#internals/definitions/defineComponents.js'; import { + allowMotion, finishAnimationsFor, isFocused, isUnderPageLayer, + painted, } from '#internals/testing/helpers.spec.js'; import { runHiddenAncestorTests } from '#internals/testing/hidden-ancestor.spec.js'; import { simulateClick, simulateKeyboard, } from '#internals/testing/simulate.spec.js'; +import { + runValueStateMotionTests, + transitionsIn, + withTheme, +} from '#internals/testing/value-state.spec.js'; import IgcButtonGroupComponent from './button-group.js'; import IgcToggleButtonComponent from './toggle-button.js'; @@ -1546,4 +1553,48 @@ describe('Button Group', () => { Right `); + + runValueStateMotionTests({ + template: html` + + Left + + `, + changedTemplate: html` + + Left + + `, + changeFromCode: (group) => { + group.selectedItems = ['left']; + }, + changeByUser: (group) => + simulateClick(group.querySelector('igc-toggle-button')!), + }); + + describe('Value state motion in single selection', () => { + allowMotion(); + + it('animates the button that the group deselects for a click', async () => { + await withTheme('material', async () => { + const group = await fixture(html` + + Left + Right + + `); + const [left, right] = group.querySelectorAll( + IgcToggleButtonComponent.tagName + ); + await painted(); + + simulateClick(right); + await painted(); + + expect(left.selected).to.be.false; + expect(transitionsIn(left)).to.not.be.empty; + expect(transitionsIn(right)).to.not.be.empty; + }); + }); + }); }); diff --git a/src/components/button-group/button-group.ts b/src/components/button-group/button-group.ts index 0fa1deadd..a859c7188 100644 --- a/src/components/button-group/button-group.ts +++ b/src/components/button-group/button-group.ts @@ -5,6 +5,7 @@ import { type TemplateResult, } from 'lit'; import { property } from 'lit/decorators.js'; +import { markUserChange } from '#animations/value-state.js'; import { type ButtonGroupContext, buttonGroupContext, @@ -356,6 +357,7 @@ export default class IgcButtonGroupComponent extends EventEmitterMixin