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

Make x-transition delay syntax consistent with duration syntax #3476

Merged
merged 3 commits into from
May 11, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/alpinejs/src/directives/x-transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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]
Expand Down
34 changes: 33 additions & 1 deletion tests/cypress/integration/directives/x-transition.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,38 @@ test('transition:enter in nested x-show visually runs',
}
)

test('transition duration and delay with and without ms syntax',
html`
<div x-data="{ showMs: false, showBlank: false }">

<span class="ms"
x-show="showMs"
x-transition.delay.80ms.duration.120ms>ms syntax</span>
<span class="blank"
x-show="showBlank"
x-transition.delay.80.duration.120>blank syntax</span>

<button class="ms" x-on:click="showMs = true"></button>
<button class="blank" x-on:click="showBlank = true"></button>
</div>
`,
({ 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`
Expand All @@ -107,4 +139,4 @@ test(
get('span').should(beVisible())
}

);
);