Skip to content

Commit 6996759

Browse files
committed
Ensure buttons are never hidden by the hovercards - enhancing the pressability of the buttons
1 parent 45c8116 commit 6996759

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

app/components/hovercard/component.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
>
66
<%= content %>
77

8-
<%# static card %>
9-
<%# should make text optional and setup the @path with turbo see: https://boringrails.com/articles/hovercards-stimulus/ %>
10-
<div class="relative opacity-0 transition delay-500 duration-300" data-hovercard-target="card">
11-
<div data-tooltip-arrow class="absolute top-0 <%= placement_class %> z-50 shadow-lg rounded-lg p-3 min-w-max bg-midnight-300 text-midnight-800">
8+
<%# static card %>
9+
<%# should make text optional and setup the @path with turbo see: https://boringrails.com/articles/hovercards-stimulus/ %>
10+
<div class="relative hidden opacity-0 pointer-events-none transition delay-500 duration-300" data-hovercard-target="card">
11+
<div data-tooltip-arrow class="absolute top-0 <%= placement_class %> z-10 shadow-lg rounded-lg p-3 min-w-max bg-midnight-300 text-midnight-800">
1212
<div class="flex space-x-3 items-center max-w-s text-sm">
1313
<%= @text %>
1414
</div>

app/javascript/controllers/hovercard_controller.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ export default class extends Controller {
66

77
show() {
88
if (this.hasCardTarget) {
9-
this.cardTarget.classList.add("delay-500");
10-
this.cardTarget.classList.remove("hidden");
11-
this.cardTarget.classList.add("opacity-100");
12-
this.cardTarget.classList.remove("opacity-0");
9+
setTimeout(() => {
10+
this.cardTarget.classList.remove("hidden", "pointer-events-none");
11+
this.cardTarget.classList.add("opacity-100");
12+
this.cardTarget.classList.remove("opacity-0");
13+
}, 150);
1314
} else {
1415
fetch(this.urlValue)
1516
.then((r) => r.text())
@@ -25,10 +26,11 @@ export default class extends Controller {
2526

2627
hide() {
2728
if (this.hasCardTarget) {
28-
this.cardTarget.classList.add("opacity-0");
29-
this.cardTarget.classList.remove("delay-500");
29+
this.cardTarget.classList.add("opacity-0", "pointer-events-none");
3030
this.cardTarget.classList.remove("opacity-100");
31-
this.cardTarget.classList.add("hidden");
31+
setTimeout(() => {
32+
this.cardTarget.classList.add("hidden");
33+
}, 300);
3234
}
3335
}
3436

@@ -38,4 +40,3 @@ export default class extends Controller {
3840
}
3941
}
4042
}
41-

0 commit comments

Comments
 (0)