Skip to content

feat(forms): animate checked and selected states only for a user change - #2639

Open
rkaraivanov wants to merge 3 commits into
masterfrom
rkaraivanov/value-state-motion
Open

rkaraivanov wants to merge 3 commits into
masterfrom
rkaraivanov/value-state-motion

Conversation

@rkaraivanov

Copy link
Copy Markdown
Member

Description

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.

Type of Change

  • New feature (non-breaking change that adds functionality)

Checklist

  • My code follows the project's coding standards
  • I have tested my changes locally
  • I have updated documentation if needed
  • I have added a CHANGELOG.md entry under [Unreleased]

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.

@simeonoff simeonoff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core design is solid: one-frame user marks, instant marks that clear in a quiet frame, and joining for framework re-renders. The inline notes are mostly edge cases and trimming surface area:

  • Behavior:
    • the list item and nav drawer item lose their selection fade
    • radio arrow-key navigation isn't a user write
    • a possible gap in the combo's igcChange handler case
  • Tests: the indeterminate and arrow-key motion tests can pass without exercising what they name.
  • Styles: keep the !important, but drop the per-component $descendants list.
  • Code:
    • the checkbox and radio could mark the host
    • user-value bookkeeping could move from the form mixin into value-state.ts
    • byUser instead of the tree's beforeChange hook
    • two names

Comment thread src/components/radio/radio.ts Resolved
Comment thread src/components/combo/combo.ts Resolved
Comment thread src/styles/utilities/_mixins.scss Resolved
Comment thread src/components/tree/tree.selection.ts Resolved
Comment thread src/animations/value-state.ts Resolved
- The nav drawer item leaves the value state rule. Its `active` is view
  state, as the `selected` of a tab, so it fades as on master. It keeps
  its reduced-motion wrap.
- A user mark can carry a check (`keepUserChangeWhile`); the first check
  wins. The form mixin attaches it before `igcChange` when a user write
  reports, else after the write, so a value that a handler sets shows at
  once, also in the pickers. The registry moves to
  `#internals/user-change.js`.
- The combo keeps the user change only while the list shows the
  selection of the user, also after a key or the clear icon.
- Radio arrow keys write through `_writeFrom('user')`.
- The checkbox, switch and radio mark the host. The instant rule covers
  the whole shadow subtree under the mark and its slotted elements. A
  host waits only for the transitions of its shadow root, so a large
  tree cascade no longer costs O(n2).
- Tests for the pickers, the color picker, the tree and the combo keys;
  the motion tests check specific transitions. Specs record the gaps and
  the precedence rule.
rkaraivanov added a commit that referenced this pull request Nov 20, 2026
…into rkaraivanov/view-state-motion

- The tabs call `value-state-transitions($on-host: true)`. The rule from
  #2639 covers the header and its slotted icon.
- `markInstant` stays in `#animations/value-state.js`, next to
  `addValueStateMotion` in the guidelines.
- The tabs and accordion specs import `transitionsIn` and `withTheme`
  from `#internals/testing/motion.spec.js`.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants