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

Prevent the underlining of the :before content of a link from being affected by a rule applied to the link

I have a hyperlink that becomes underlined when hovered over. I want to add a > symbol before the link, but I don't want it to be underlined when the link is hovered. Here's the code I'm using: .box.blueb a { color: #0098aa; } .box.blueb ...

What are the steps to ensure that this iframe adjusts perfectly to the page in terms of both vertical and horizontal dimensions

I have a sandbox from Material UI that you can view at this link: https://codesandbox.io/s/material-demo-forked-c8e39?file=/demo.js Upon loading the page, an iframe displays some HTML content. Although the width fits perfectly, there are two vertical scro ...

How can one transform a web-based application into a seamless full-screen desktop experience on a Mac?

"Which software can be utilized to enable a web application to display an icon on the desktop of a Mac computer, while also opening up the web application in a fully immersive full-screen mode that supports all the touch and gesture functionalities provi ...

Can a placeholder dropzone be created at the bottom of Vue Draggable lists?

Currently, I am utilizing Vue.Draggable (accessible at https://github.com/SortableJS/Vue.Draggable) to develop a kanban board that enables me to drag items from one list to another. A challenge I face is that when dragging a list item to the bottom of anot ...

Unable to trigger jQuery onclick event on nested div elements

I'm experiencing an issue with my web-page where two buttons at the top are not responding to a sorting function on the nested #byFilter. Despite trying to apply the onclick(function()) method, it doesn't seem to work. Javascript $(document).re ...

Unlocking the Mysterious Realm of HTML

I recently stumbled upon a mysterious combination of HTML attributes: <div vanisheffect="true" blinkcolor="red" fadeopacity="0.8"> Have you ever encountered something like this? And more importantly, does it have any impact on specific browsers? Is ...

Updating HTML in Vue.js with data at a specific index value can be done by targeting

Experimenting with a combination of vue.js and vanilla to create a blackjack game. The card data is stored in the vue data() like this: data(){ return { cards: [ {id: 1, cardName: 'Ace of Spades', cardPic: ' ...

Is there a method to track the progress of webpage loading?

I am working on a website built with static HTML pages. My goal is to implement a full-screen loading status complete with a progress bar that indicates the page's load progress, including all images and external assets. Once the page has fully loaded ...

Creating separate chunks for individual files in Vue CLI3JsonPropertyTitleFileType

I am working on a project using vue-cli3 and need to separate out a specific file for chunking due to IIS requirements. Currently, webpack chunks files based on default settings and also automatically creates chunks from dynamic imports in vue-router. How ...

Guide on how to use a tooltip for a switch component in Material-UI with React

I am attempting to incorporate a tooltip around an interactive MUI switch button that changes dynamically with user input. Here is the code snippet I have implemented so far: import * as React from 'react'; import { styled } from '@mui/mater ...

Wait for AngularJS to load when the background image of a div becomes visible

Currently, I am utilizing the ng-repeat feature to fetch data from a $http.post request and then save it to the $scope.data variable. <div ng-repeat="key in [] | range:data.pages"> <div class="pageBackground" id="page_{{ (key+1) }}" ng-style= ...

Inserting a border both above and below an element may result in the parent overflowing

I am facing an issue similar to the following: div.parent { height: 100px; padding: 20px; box-sizing: border-box; overflow: auto; } div.parent div.thing { height: 20px; width: 90%; border: 1px solid black; } <div class="parent"> ...

An unusual 1px variance appears in the background-image on Internet Explorer

Having trouble with a sprite of two images showing a 1px difference in ALL versions of Internet Explorer, yet working perfectly in Firefox. Check out the demonstration here: http://jsfiddle.net/bHUs3/6/ I'm feeling frustrated. What could be causing ...

What is the best way to distinguish between relative blocks and convert them to absolute positioning?

What is the best way to locate relative blocks and convert them to absolute position while keeping them in the same place? Is this something that can be achieved using JavaScript or jQuery, or is it simply not possible? Thank you very much. ...

Design an arrangement using div elements and CSS styling

Creating a layout for a website can be challenging. I am using three div tags - container, left, and right. My goal is to have the left side fixed-width for navigation, while the right side displays dynamic content loaded from a database. However, I'm ...

Displaying content on the <div> element

Looking for recommendations for a jQuery plugin or JavaScript solution that allows me to load a full "view" into a <div> when a user clicks on a link. The challenge I'm facing is that I have 8 pages, with the Homepage consisting of 3 divisions: ...

Customize the asset path location in Webpack

I am currently working on a Vue application that utilizes Webpack for code minimization. Is there a method to dissect the chunks and adjust the base path from which webpack retrieves the assets? For example, by default webpack fetches assets from "/js" o ...

Displaying information in a table format

How do I capture the titles of 'th' and 'td' elements in Vue.js when the save button is clicked? Here's my HTML code snippet: <tr> <th>Himalayan Salajit (Pakistan Onl ...

Showcasing a singular characteristic of a set of arranged items in md-autocomplete :md-options

Just starting to explore Vuejs here. I recently installed vue material and decided to give the md-autocomplete component a try. The data structure in my script is as follows: selectedFruit: null, fruits: [ {name: "Orange", available: ...

Looking to utilize the <pre> tag without any external CSS styles defined in a separate stylesheet?

In my current project, I am using bootstreap v3.2. I am facing an issue where I need to display fetched content from the database on a page using the <pre></pre> tags. However, the problem is that the content is being displayed with the default ...