The base idea is to disable mouse interaction on a submit button with pointer-events: none;
when it’s focused. It’s easy but there’s a catch: doing so will prevent the submit event to fire because in the moment of clicking the button gets "disabled”.
To overcome this I’m using CSS animation with a tiny delay. This way there’s enough time for the click event but not enough time for consecutive clicks.
[data-temp-disable="1"]:focus {
animation: 10s tempdisable 0.2s steps(1, end);
}
@keyframes tempdisable {
from { opacity: 0.5; pointer-events: none; filter: saturate(0); }
to { opacity: 1; pointer-events: all; }
}
To use this, add a data-temp-disable="1"
attribute to the submit button in question. 0.2 seconds after clicking on it the CSS pointer-events: none;
will kick in so you can’t submit it again.
I added a 10-second timeout to this fake disabled state to make sure it won’t be disabled forever.
I’ve made the button half opaque and fully desaturated to indicate the pressed state but you can be more creative. The animation is using "steps” to make the "enabled” state appear only at the end of the animation.
Remember that this lightweight solution is for simple cases, otherwise use JavaScript instead (for example when you need to set a submit button disabled without click event, eg. via form submit event).
0 comments Comments