Enhance a disabled button by incorporating a ripple effect

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.

Vue playground code

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>
  

Answer №1

When you use the disabled HTML attribute, your button will not be focused, which means the .btn-ripple:focus state will never be triggered.

To achieve a similar effect without actually disabling the button, you can add a condition like if (disableSubmit.value) return in your click handler. This way, the button will appear enabled but function as though it is disabled.

If you also want to style the disabled button differently, you can change the class dynamically using something like

:class="{ 'btn-ripple': true, 'btn-ripple-disabled': disableSubmit }"
.

Answer №2

My recommendation is to refrain from using excessive design styles and stick with the default provided by Quasar. Instead, consider utilizing the solution below which involves avoiding the use of the click event when the button is in a disabled state.

<q-btn round color="primary" @click="null" icon="card_giftcard"></q-btn>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for incorporating a scrolling feature into my HTML page?

I need to display the following content on my website: What code do I need to add in order to achieve this? I tried using the code snippet below but it did not work as expected: <td nowrap align="left" style="word-wrap: break-word"><pre style="w ...

Is it possible to connect ng-model with a style tag?

Is it feasible to create a basic template editor using angularjs where an input field with an ng-model can be connected to a style tag to control the css on an entire page rather than applying it to a specific element with inline styling? Could something ...

The spacing between images on mobile devices is excessive

My images on mobile have too much space between them: mobile version They appear fine in Dev Tools: dev tools version This is my HTML: <div class="container-fluid"> <!-- <br> --> <div class="row"> ...

What is the best way to center a div horizontally when the width is unknown?

Check out the full screen result here: http://jsfiddle.net/anik786/UYkSf/4/embedded/result/ Here's where you can find the HTML/CSS: http://jsfiddle.net/anik786/UYkSf/4/ This is the HTML code: <div class="gallery_container"> <div class="pic ...

What is the significance of utilizing `.value` within a template when working with a function that produces a computed ref?

One of my functions returns a ComputedRef as shown below: // The computed ref function const publishedBooksMessage = () => computed(() => { return books.length > 0 ? 'Yes' : 'No' }) In order to access the value returned by t ...

Firebug displays the class name and location twice in the right panel

When examining a div labeled with .mlm-clearfix, I noticed that Firebug was displaying this class name and its URL twice in the right panel. The style declarations given for the Easy Clear Method in relation to this class are as follows: .mlm-clearfix:bef ...

The CSS3 Animation remains stationary

I've been attempting to animate my block element moving to the left using CSS animation shorthand property, but unfortunately, it's not working as expected. Here is my HTML: <div id="game"> <div id="block">&l ...

Switching Vue.js from the standalone build to the runtime-only build midway through a project?

Opted for the runtime-only version of Vue.js for a new project. I came across in the documentation that to switch to the standalone version, one must include an alias in webpack like this: resolve: { alias: { 'vue$': 'vue/dist/vue.js& ...

References are not found in Vue.js

I am attempting to programmatically trigger a button click in vuejs using a javascript method. I am utilizing the following line of code to reference it via the ref tag. Here is my javascript snippet: this.$refs.action.click(); Here is the corresponding ...

Enhance each category changing with jQuery page transitions

Is there a way to add page transitions based on category names and quantities in PHP? For example, when clicking on the "office" category, can a popup overlay be displayed with the category name and quantity while the content loads? The focus is on creat ...

Change occurring within a cell of a table that has a width of 1 pixel

In the code snippet below, there is a transition inside a table cell with a width of 1px to allow it to wrap its content. However, the table layout changes only at the end or beginning of the transition: var animator = document.getElementById("animator" ...

I am interested in adding a personalized icon to the progress bar in Material-UI

I am currently using the MUI linerProgressBar design. I would like to incorporate a custom UI Icon that moves along with the progress. Are there any examples of this available? I have searched for one in MUI but haven't found anything. If you know of ...

Adjust the top margin of a div to match the height of the screen within an iframe, ensuring cross-browser

Trying to adjust the margin-top of a div to 100% of screen height within an iframe seems to be causing issues with jQuery, as it either returns 0 or inaccurate values. While CSS3's 100vh can work as an alternative, it may not be supported in older an ...

The slides on my Bootstrap carousel are failing to display

I attempted to study a Bootstrap carousel code for better understanding, but unfortunately, the slides are not functioning correctly. The first slide remains static without any movement. Any suggestions on how to resolve this issue? Below are the HTML and ...

Editing data in Handsontable may lead to triggering errors in Vuex mutations

I am currently facing an issue with a big data grid that I'm building using Handsontable and Vue. The data is stored in Vuex, but when I try to edit a cell, I encounter mutation errors related to Vuex. In ag-grid, I could use valueSetters and getters ...

Utilize HTML to resize image to fit within container

I've encountered an issue while working with Adobe Dreamweaver CS5. I added a swap behavior to an image in an html document, expecting it to pop up at its original size and restore on mouse out. However, the swapped image ends up filling the entire sc ...

Enabling the value to be set as true for radio buttons generated using v-for

Utilizing a v-for loop over an array of objects in graphicState, the rows of a table are dynamically generated. My goal is to implement a column of radio buttons that, when checked, will set graphicState[index].selected to true. I came across this insight ...

Guide to utilizing axios.request(config) in Vue.js

I have been attempting to use Axios in my vue.js project to make HTTP requests. Despite reviewing the Axios documentation on GitHub and exploring various examples online, I have yet to find a solution. My goal is to create a configuration file where I can ...

What is the best way to load the contents of an HTML file into a <div> element without it behaving as an object?

Currently, I am importing an HTML file into a <div> in this manner: function load_content() { document.getElementById('content').innerHTML = '<object type="text/html" width="100%" height="100%" data="./content.html"></obj ...

Implementing automatic activation of a tab upon page load using Angular

I am currently working with a set of Bootstrap nav pills in my navigation bar. The 'ng-init' code in my Angular script sets the 'dateState' to 'past' on page load. However, I have noticed that the 'Past Events' nav p ...