diff --git a/packages/alpinejs/src/directives/x-transition.js b/packages/alpinejs/src/directives/x-transition.js index 7838ee956..1313f50a9 100644 --- a/packages/alpinejs/src/directives/x-transition.js +++ b/packages/alpinejs/src/directives/x-transition.js @@ -50,7 +50,7 @@ function registerTransitionsFromHelper(el, modifiers, stage) { let wantsScale = wantsAll || modifiers.includes('scale') let opacityValue = wantsOpacity ? 0 : 1 let scaleValue = wantsScale ? modifierValue(modifiers, 'scale', 95) / 100 : 1 - let delay = modifierValue(modifiers, 'delay', 0) + let delay = modifierValue(modifiers, 'delay', 0) / 1000 let origin = modifierValue(modifiers, 'origin', 'center') let property = 'opacity, transform' let durationIn = modifierValue(modifiers, 'duration', 150) / 1000 @@ -60,7 +60,7 @@ function registerTransitionsFromHelper(el, modifiers, stage) { if (transitioningIn) { el._x_transition.enter.during = { transformOrigin: origin, - transitionDelay: delay, + transitionDelay: `${delay}s`, transitionProperty: property, transitionDuration: `${durationIn}s`, transitionTimingFunction: easing, @@ -80,7 +80,7 @@ function registerTransitionsFromHelper(el, modifiers, stage) { if (transitioningOut) { el._x_transition.leave.during = { transformOrigin: origin, - transitionDelay: delay, + transitionDelay: `${delay}s`, transitionProperty: property, transitionDuration: `${durationOut}s`, transitionTimingFunction: easing, @@ -318,7 +318,7 @@ export function modifierValue(modifiers, key, fallback) { if (isNaN(rawValue)) return fallback } - if (key === 'duration') { + if (key === 'duration' || key === 'delay') { // Support x-transition.duration.500ms && duration.500 let match = rawValue.match(/([0-9]+)ms/) if (match) return match[1] diff --git a/tests/cypress/integration/directives/x-transition.spec.js b/tests/cypress/integration/directives/x-transition.spec.js index 65da817b4..717d4ea7e 100644 --- a/tests/cypress/integration/directives/x-transition.spec.js +++ b/tests/cypress/integration/directives/x-transition.spec.js @@ -81,6 +81,38 @@ test('transition:enter in nested x-show visually runs', } ) +test('transition duration and delay with and without ms syntax', + html` +
+ + ms syntax + blank syntax + + + +
+ `, + ({ get }) => { + get('span.ms').should(notBeVisible()) + get('button.ms').click() + get('span.ms').should(notBeVisible()) // Not visible due to delay + get('span.ms').should(beVisible()) + get('span.ms').should(notHaveComputedStyle('opacity', '1')) // We expect a value between 0 and 1 + get('span.ms').should(haveComputedStyle('opacity', '1')) // Eventually opacity will be 1 + + get('span.blank').should(notBeVisible()) + get('button.blank').click() + get('span.blank').should(notBeVisible()) // Not visible due to delay + get('span.blank').should(beVisible()) + get('span.blank').should(notHaveComputedStyle('opacity', '1')) // We expect a value between 0 and 1 + get('span.blank').should(haveComputedStyle('opacity', '1')) // Eventually opacity will be 1 + } +) + test( 'bound x-transition can handle empty string and true values', html` @@ -107,4 +139,4 @@ test( get('span').should(beVisible()) } -); \ No newline at end of file +);