Skip to content

Commit c01b45f

Browse files
committed
fix: remove carousel navigation buttons from having anchor wrappers
1 parent 10dc17d commit c01b45f

2 files changed

Lines changed: 28 additions & 12 deletions

File tree

app/(home)/components/SponsorsDesktop.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ const SponsorsDesktop = ({ sponsors }: { sponsors: SponsorshipProps[] }) => {
176176
}}
177177
>
178178
{/* Previous Button */}
179-
<a onClick={autoPlayInteraction}>
180-
<CarouselPrevious className="absolute left-[-64px] z-10 h-16 w-16 sm:w-20 sm:h-20" />
181-
</a>
179+
<CarouselPrevious
180+
className="absolute left-[-64px] z-10 h-16 w-16 sm:w-20 sm:h-20"
181+
customOnClick={autoPlayInteraction}
182+
/>
182183

183184
{/* Carousel Content */}
184185
<CarouselContent>
@@ -220,9 +221,10 @@ const SponsorsDesktop = ({ sponsors }: { sponsors: SponsorshipProps[] }) => {
220221
</CarouselContent>
221222

222223
{/* Next Button */}
223-
<a onClick={autoPlayInteraction}>
224-
<CarouselNext className="absolute right-[-64px] z-10 h-16 w-16 sm:w-20 sm:h-20" />
225-
</a>
224+
<CarouselNext
225+
className="absolute right-[-64px] z-10 h-16 w-16 sm:w-20 sm:h-20"
226+
customOnClick={autoPlayInteraction}
227+
/>
226228
</Carousel>
227229
</div>
228230
{/* Dots Navigation */}

components/ui/carousel.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ type CarouselContextProps = {
3232
canScrollNext: boolean;
3333
} & CarouselProps;
3434

35+
type CarouselNavProps = {
36+
customOnClick?: () => void;
37+
};
38+
3539
const CarouselContext = React.createContext<CarouselContextProps | null>(null);
3640

3741
function useCarousel() {
@@ -235,10 +239,15 @@ CarouselItem.displayName = 'CarouselItem';
235239

236240
const CarouselPrevious = React.forwardRef<
237241
HTMLButtonElement,
238-
React.ComponentProps<typeof Button>
239-
>(({ className, variant = 'transparent', size = 'icon', ...props }, ref) => {
242+
React.ComponentProps<typeof Button> & CarouselNavProps
243+
>(({ className, variant = 'transparent', size = 'icon', customOnClick, ...props }, ref) => {
240244
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
241245

246+
const handleClick = () => {
247+
scrollPrev();
248+
if (customOnClick) customOnClick();
249+
};
250+
242251
return (
243252
<Button
244253
ref={ref}
@@ -252,7 +261,7 @@ const CarouselPrevious = React.forwardRef<
252261
className
253262
)}
254263
disabled={!canScrollPrev}
255-
onClick={scrollPrev}
264+
onClick={handleClick}
256265
{...props}
257266
>
258267
<ChevronLeft className="!h-full !w-full text-primary" />
@@ -264,10 +273,15 @@ CarouselPrevious.displayName = 'CarouselPrevious';
264273

265274
const CarouselNext = React.forwardRef<
266275
HTMLButtonElement,
267-
React.ComponentProps<typeof Button>
268-
>(({ className, variant = 'transparent', size = 'icon', ...props }, ref) => {
276+
React.ComponentProps<typeof Button> & CarouselNavProps
277+
>(({ className, variant = 'transparent', size = 'icon', customOnClick, ...props }, ref) => {
269278
const { orientation, scrollNext, canScrollNext } = useCarousel();
270279

280+
const handleClick = () => {
281+
scrollNext();
282+
if (customOnClick) customOnClick();
283+
}
284+
271285
return (
272286
<Button
273287
ref={ref}
@@ -281,7 +295,7 @@ const CarouselNext = React.forwardRef<
281295
className
282296
)}
283297
disabled={!canScrollNext}
284-
onClick={scrollNext}
298+
onClick={handleClick}
285299
{...props}
286300
>
287301
<ChevronRight className="!h-full !w-full text-primary" />

0 commit comments

Comments
 (0)