File tree Expand file tree Collapse file tree 4 files changed +42
-52
lines changed
packages/motion/src/state
playground/vite/src/views Expand file tree Collapse file tree 4 files changed +42
-52
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import type { MotionStateContext, Options } from '@/types'
22import { invariant } from 'hey-listen'
33import type { DOMKeyframesDefinition , VisualElement } from 'framer-motion'
44import { cancelFrame , frame , noop } from 'framer-motion/dom'
5- import { isAnimateChanged , isSVGElement , resolveVariant } from '@/state/utils'
5+ import { isSVGElement , resolveVariant } from '@/state/utils'
66import type { Feature , StateType } from '@/features'
77import { FeatureManager } from '@/features'
88import type { PresenceContext } from '@/components/animate-presence/presence'
@@ -211,14 +211,11 @@ export class MotionState {
211211
212212 // Update motion state with new options
213213 update ( options : Options ) {
214- const hasAnimateChange = isAnimateChanged ( this . options , options )
215214 this . updateOptions ( options )
216215 // Update features in parent-to-child order
217216 this . featureManager . update ( )
218217
219- if ( hasAnimateChange ) {
220- this . startAnimation ( )
221- }
218+ this . startAnimation ( )
222219 }
223220
224221 // Set animation state active status and propagate to children
Original file line number Diff line number Diff line change @@ -133,30 +133,3 @@ const svgElementSet = new Set(svgElements)
133133export function isSVGElement ( as : AsTag ) : as is SVGElements {
134134 return svgElementSet . has ( as as SVGElements )
135135}
136-
137- export function isAnimateChanged ( oldOptions : Options , newOptions : Options ) : boolean {
138- const oldAnimate = oldOptions . animate
139- const newAnimate = newOptions . animate
140- if ( oldAnimate === newAnimate )
141- return false
142- if ( ! oldAnimate || ! newAnimate ) {
143- return true
144- }
145-
146- if ( typeof oldAnimate === 'object' || typeof newAnimate === 'object' ) {
147- // Compare object keys and values
148- const oldKeys = Object . keys ( oldAnimate )
149- const newKeys = Object . keys ( newAnimate )
150-
151- if ( oldKeys . length !== newKeys . length )
152- return true
153- return oldKeys . some ( ( key ) => {
154- if ( key === 'transition' )
155- return false
156- const oldVal = oldAnimate [ key ]
157- const newVal = newAnimate [ key ]
158- return oldVal !== newVal
159- } )
160- }
161- return oldAnimate !== newAnimate
162- }
Original file line number Diff line number Diff line change 11<script setup lang="ts">
22import { ref } from ' vue'
3- import { MotionConfig , motion } from ' @/components'
3+ // Use local alias for dev, not 'motion-vue'
4+ import { motion } from ' motion-v'
45
56const show = ref (true )
67const toggle = () => (show .value = ! show .value )
@@ -12,23 +13,21 @@ const variants = {
1213 </script >
1314
1415<template >
15- <MotionConfig reduced-motion =" always" >
16- <div style =" padding : 40px " >
17- <button
18- data-testid =" toggle-btn"
19- @click =" toggle"
20- >
21- Toggle
22- </button >
23- <motion .button
24- data-testid =" motion-btn"
25- initial =" initial"
26- :variants =" variants"
27- :while-in-view =" show ? 'visible' : 'hidden'"
28- style =" width : 120px ; height : 40px ; margin-top : 20px "
29- >
30- CLICK ME
31- </motion .button >
32- </div >
33- </MotionConfig >
16+ <div style =" padding : 40px " >
17+ <button
18+ data-testid =" toggle-btn"
19+ @click =" toggle"
20+ >
21+ Toggle
22+ </button >
23+ <motion .button
24+ data-testid =" motion-btn"
25+ initial =" initial"
26+ :variants =" variants"
27+ :while-in-view =" show ? 'visible' : 'hidden'"
28+ style =" width : 120px ; height : 40px ; margin-top : 20px "
29+ >
30+ CLICK ME
31+ </motion .button >
32+ </div >
3433</template >
Original file line number Diff line number Diff line change 1+ import { expect , test } from '@playwright/test'
2+
3+ // This test assumes the Vite dev server is running and the route is /dynamic-variant
4+
5+ test . describe ( 'Variant' , ( ) => {
6+ test ( 'should animate opacity when variant changes' , async ( { page } ) => {
7+ await page . goto ( '/dynamic-variant' )
8+ const motionBtn = page . locator ( '[data-testid="motion-btn"]' )
9+ // Initial: visible
10+ await expect ( motionBtn ) . toHaveCSS ( 'opacity' , '1' )
11+ // Click toggle
12+ await page . click ( '[data-testid="toggle-btn"]' )
13+ // After: hidden
14+ await page . waitForTimeout ( 250 )
15+ await expect ( motionBtn ) . toHaveCSS ( 'opacity' , '0.25' )
16+ // Click toggle again
17+ await page . click ( '[data-testid="toggle-btn"]' )
18+ await page . waitForTimeout ( 250 )
19+ await expect ( motionBtn ) . toHaveCSS ( 'opacity' , '1' )
20+ } )
21+ } )
You can’t perform that action at this time.
0 commit comments