I've got a button that toggles on and off depending on the required form fields. When it's enabled, clicking it activates a ripple effect.
Now I'd like to have the ripple effect even when the button is disabled. I attempted something similar to the code snippet below in Vue Playground. Currently, I'm working with Vue3 using the Composition API.
How can I trigger the click event and incorporate the ripple effect even when the button is disabled?
<script setup>
import { computed, ref } from 'vue'
//This depends on the completion of the form fields
const disableSubmit = ref(true)
//const rippleEffect = computed(() => (disableSubmit.value ? "btn-ripple" : ""))
</script>
<template>
<button :disabled="disableSubmit" class="btn-ripple">
<span>Submit</span>
</button>
</template>
<style>
.btn-ripple {
box-sizing: border-box;
border: none;
cursor: pointer !important;
color: white;
padding: 15px 40px;
border-radius: 8px;
font-size: 22px;
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4);
background: #00a1d4;
transition: all 0.1s;
outline: none;
}
.btn-onoff .btn-ripple {
position: relative;
overflow: hidden;
}
.btn-onoff .btn-ripple:after {
content: "";
position: absolute;
top: 50%;
left: 50%;
width: 5px;
height: 5px;
background-color: #ffffff;
opacity: 0;
border-radius: 100%;
transform: scale(1, 1) translate(-50%);
transform-origin: 50% 50%;
}
@keyframes ripple {
0% {
transform: scale(0, 0);
opacity: 1;
}
20% {
transform: scale(25, 25);
opacity: 1;
}
100% {
opacity: 0;
transform: scale(40, 40);
}
}
.btn-onoff .btn-ripple:focus:not(:active)::after {
animation: ripple 1s ease-out;
}
.btn-onoff .btn-ripple:after {
visibility: hidden;
}
.btn-onoff .btn-ripple:focus:after {
visibility: visible;
}
</style>