Skip to content

Commit 27cf559

Browse files
committed
Top menu button touch transition
Tap highlight will be disabled in upcoming Tailwind release by default: tailwindlabs/tailwindcss#12299
1 parent f7741bb commit 27cf559

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed
Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<template>
22
<button
3-
class="hoverClass relative h-12 w-12 duration-300 before:absolute before:inset-0 before:-z-10 before:scale-0 before:rounded-full before:bg-silver-500 before:opacity-0 before:transition-all before:ease-in themeSkyDark:before:bg-silver-500/25"
3+
class="buttonClass relative h-12 w-12 before:absolute before:inset-0 before:-z-10 before:scale-0 before:rounded-full before:bg-silver-500 before:opacity-0 before:transition-all before:ease-in themeSkyDark:before:bg-silver-500/25"
44
:class="{
55
activeClass: active,
6+
// Mobile touch transition class is only applied for buttons that are not
7+
// toggled via `active`
8+
[transitionClass]: active === null,
69
}"
10+
@click="onClickButton"
11+
@transitionend="transitionClass = 'transitionOut'"
712
>
813
<slot></slot>
914
</button>
@@ -12,17 +17,50 @@
1217
<script setup lang="ts">
1318
withDefaults(
1419
defineProps<{
15-
active?: boolean;
20+
active?: boolean | null;
1621
}>(),
1722
{
18-
active: false,
23+
active: null,
1924
},
2025
);
26+
27+
//#region Mobile touch transition
28+
const transitionClass = ref<"transitionIn" | "transitionOut">("transitionOut");
29+
function onClickButton(e: MouseEvent) {
30+
const el = e.currentTarget;
31+
if (el instanceof HTMLElement) {
32+
// Trigger DOM reflow to reset animation before finished.
33+
el.style.animation = "none";
34+
el.offsetHeight;
35+
el.style.animation = "";
36+
transitionClass.value = "transitionIn";
37+
}
38+
}
39+
//#endregion
2140
</script>
2241

2342
<style lang="postcss" scoped>
24-
.activeClass,
25-
.hoverClass:hover {
43+
/** Applied when button is active */
44+
.activeClass {
2645
@apply before:scale-100 before:opacity-100 before:ease-out;
2746
}
47+
48+
/** Use normal :hover behaviour on desktop */
49+
@media (hover: hover) and (pointer: fine) {
50+
.buttonClass:hover {
51+
@apply before:scale-100 before:opacity-100 before:ease-out;
52+
}
53+
}
54+
55+
/** Target devices that don't support hover */
56+
@media not (hover: hover) {
57+
.buttonClass.transitionIn {
58+
@apply before:scale-100 before:opacity-100 before:ease-in;
59+
}
60+
61+
.buttonClass.transitionOut {
62+
/** Add delay before transitioning out */
63+
@apply before:scale-0 before:opacity-0 before:delay-75 before:ease-out;
64+
}
65+
}
2866
</style>

apps/frontend-nuxt/components/SelectLanguageButton.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="relative">
33
<HeadlessMenu>
4-
<HeadlessMenuButton v-slot="{ open }: { open: boolean }">
4+
<HeadlessMenuButton as="template" v-slot="{ open }: { open: boolean }">
55
<BaseTopMenuButton class="h-12 w-12" :active="open">
66
<Icon class="h-6 w-6" name="ion:language" />
77
</BaseTopMenuButton>

0 commit comments

Comments
 (0)