Skip to content

Commit 07abc7a

Browse files
committed
Refactor testimonial slider dots and handlers
Wrap each slider-dot in a button to increase the clickable area and move cursor/padding classes to the button. Update the dot element classnames to include 'block' for the inner span. Add a TypeScript NodeListOf<HTMLElement> cast for dots and change event listener registration to query [data-dot] (the buttons) instead of the inner span. These changes align markup and JS so clicks target the button and the visual dot remains a span.
1 parent 15fdf2c commit 07abc7a

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/components/Testimonials.astro

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ if (!testimonials) {
5757
</button>
5858
<div class="flex items-center gap-1.5">
5959
{items.map((_, i) => (
60-
<button class={`slider-dot h-1.5 rounded-full transition-all duration-300 cursor-pointer ${i === 0 ? 'w-5 bg-ink' : 'w-1.5 bg-ink/20'}`} data-dot={i} aria-label={`Ir a testimonio ${i + 1}`} />
60+
<button class="relative p-3 cursor-pointer group" data-dot={i} aria-label={`Ir a testimonio ${i + 1}`}>
61+
<span class={`slider-dot block h-1.5 rounded-full transition-all duration-300 ${i === 0 ? 'w-5 bg-ink' : 'w-1.5 bg-ink/20'}`} />
62+
</button>
6163
))}
6264
</div>
6365
<button data-dir="1" aria-label="Siguiente" class="slider-nav group rounded-full border border-border bg-surface p-2.5 shadow-sm transition-all duration-200 hover:border-ink/25 hover:shadow-md active:scale-95 cursor-pointer">
@@ -72,7 +74,7 @@ import { gsap } from 'gsap';
7274
const section = document.querySelector('.testimonial-section');
7375
if (section) {
7476
const slides = gsap.utils.toArray<HTMLElement>('.slide', section);
75-
const dots = section.querySelectorAll<HTMLElement>('.slider-dot');
77+
const dots = section.querySelectorAll<HTMLElement>('.slider-dot') as NodeListOf<HTMLElement>;
7678
const total = slides.length;
7779
let current = 0;
7880
let tweening = false;
@@ -89,8 +91,8 @@ if (section) {
8991
gsap.to(slides[current], { xPercent: dir * -100, onComplete: () => (tweening = false) });
9092
gsap.to(slides[next], { xPercent: 0 });
9193

92-
dots[current].className = 'slider-dot h-1.5 rounded-full transition-all duration-300 cursor-pointer w-1.5 bg-ink/20';
93-
dots[next].className = 'slider-dot h-1.5 rounded-full transition-all duration-300 cursor-pointer w-5 bg-ink';
94+
dots[current].className = 'slider-dot block h-1.5 rounded-full transition-all duration-300 w-1.5 bg-ink/20';
95+
dots[next].className = 'slider-dot block h-1.5 rounded-full transition-all duration-300 w-5 bg-ink';
9496

9597
current = next;
9698
};
@@ -102,8 +104,8 @@ if (section) {
102104
btn.addEventListener('click', () => advance(Number(btn.dataset.dir)))
103105
);
104106

105-
dots.forEach((dot) =>
106-
dot.addEventListener('click', () => goTo(Number(dot.dataset.dot)))
107+
section.querySelectorAll<HTMLElement>('[data-dot]').forEach((btn) =>
108+
btn.addEventListener('click', () => goTo(Number(btn.dataset.dot)))
107109
);
108110

109111
// Auto-play con pausa en hover

0 commit comments

Comments
 (0)