Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return to previous state after hovered event variant #183

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/features/eventListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function registerEventListeners<T extends string, V extends MotionVariant
const focused = ref(false)

const mutableKeys = computed(() => {
let result: string[] = []
let result: string[] = [...Object.keys(state.value || {})]

if (!_variants) return result

Expand All @@ -26,7 +26,7 @@ export function registerEventListeners<T extends string, V extends MotionVariant
})

const computedProperties = computed(() => {
const result = {}
const result: Partial<V> = {}

Object.assign(result, state.value)

Expand All @@ -37,7 +37,6 @@ export function registerEventListeners<T extends string, V extends MotionVariant
if (focused.value && _variants.focused) Object.assign(result, _variants.focused)

for (const key in result) {
// @ts-expect-error - Fix errors later for typescript 5
if (!mutableKeys.value.includes(key)) delete result[key]
}

Expand Down
9 changes: 8 additions & 1 deletion src/features/lifeCycleHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ export function registerLifeCycleHooks<T extends string, V extends MotionVariant
if (!_variants) return

// Set initial before the element is mounted
if (_variants.initial) set('initial')
if (_variants.initial) {
// Set initial variant properties immediately, skipping transitions
set('initial')

// Set variant to sync `state` which is used to undo event variant transitions
// NOTE: This triggers an (instant) animation even though properties have already been applied
variant.value = 'initial'
}

// Lifecycle hooks bindings
if (_variants.enter) variant.value = 'enter'
Expand Down
Loading