Logo

dev-resources.site

for different kinds of informations.

DevTips โ€“ DaisyUi (Rating, Carousel)

Published at
9/20/2023
Categories
webdev
daisyui
tailwindcss
Author
oscaryiudev
Categories
3 categories in total
webdev
open
daisyui
open
tailwindcss
open
Author
11 person written this
oscaryiudev
open
DevTips โ€“ DaisyUi (Rating, Carousel)

I found daisyui to be a great tool for its simplicity and wide range of components. However, I encountered some issues while using the rating and carousel components. In this article, I will provide tips on how to effectively use these components in daisyui, along with examples and codebase.

When working with the rating component, I came across an issue where clicking on the first row affected the value of the second row. This happened because I was using the same name for the input tags in different rating components. To resolve this, it is important to use different names for the input tags.

<div className="rating">
      <input
        type="radio"
        name={name}
        className="mask mask-star-2 bg-orange-400"
      />
      <input
        type="radio"
        name={name}
        className="mask mask-star-2 bg-orange-400"
      />
      <input
        type="radio"
        name={name}
        className="mask mask-star-2 bg-orange-400"
        checked
      />
      <input
        type="radio"
        name={name}
        className="mask mask-star-2 bg-orange-400"
      />
      <input
        type="radio"
        name={name}
        className="mask mask-star-2 bg-orange-400"
      />
    </div>
Enter fullscreen mode Exit fullscreen mode


As for the carousel component, I noticed that when navigating through the carousel using the provided buttons, the page would scroll to the selected photo. This behavior wasnโ€™t what I expected. To address this, I implemented a solution which involved preventing the default behavior on click and then manually scrolling left within the carousel component to display the desired target.

const handleClickBtn = (
    event: React.MouseEvent<HTMLAnchorElement, MouseEvent>,
    i: number
  ) => {
    event.preventDefault();
    const btn = event.currentTarget;
    const carousel = document.getElementById(carouselId);
    if (carousel) {
      const href = btn.getAttribute("href")!;
      const target = carousel.querySelector<HTMLDivElement>(href)!;
      const left = target.offsetLeft;
      setActiveIndex(i);
      carousel.scrollTo({ left: left });
    }
  };
Enter fullscreen mode Exit fullscreen mode

You can find a demo website and the corresponding code below. Feel free to check it out!
Github repo: https://github.com/15077693d/demo-for-my-blog/blob/main/src/pages/rating.tsx

Rating demo: https://demo-for-my-blog.vercel.app/rating
Carousel demo: https://demo-for-my-blog.vercel.app/carousel

daisyui Article's
22 articles in total
Favicon
Creating a To-Do app with HTMX and Django - Part 3: Creating the frontend and adding HTMX
Favicon
What is DaisyUI? Advantages, Disadvantages, and FAQโ€™s
Favicon
DaisyUI: CSS Components for Tailwind
Favicon
Discover the beauty of simplicity with ๐——๐—ฎ๐—ถ๐˜€๐˜†๐—จ๐—œ! ๐Ÿš€
Favicon
daisyUI adoption guide: Overview, examples, and alternatives
Favicon
Getting started with Tailwind + Daisy UI in Angular 18
Favicon
๐ŸŽ‰ My First Shot at a Vue Library: Introducing masc-vue!๐ŸŒŸ
Favicon
Binary Duel, front-end in 2 weeks with Svelte and DaisyUI
Favicon
My Journey with Svelte: From Vue to Svelte and the Joy of Pure JS Libraries
Favicon
Stop flickering theme after page refresh in Sveltekit and Daisy UI
Favicon
DevTips โ€“ DaisyUi (Rating, Carousel)
Favicon
Building Contact Form in React with DaisyUI and Tailwind CSS
Favicon
Create an Emoji Selector for Next.js Forms using Tailwind + DaisyUI
Favicon
Install TailwindCSS and DaisyUI CSS Plugin with Angular
Favicon
Configurar DaisyUI con Vue3
Favicon
Setting up DaisyUI, Tailwind, Vue and Vite
Favicon
How to build a multi step form in Vue
Favicon
DaisyUIใงใƒ‡ใ‚ณใฃใŸPhoenixใ‚ขใƒ—ใƒชใ‚’Fly.ioใซใƒ‡ใƒ—ใƒญใ‚คใ—ใฆๆฅฝใ—ใ‚€(2022ๅนด)
Favicon
Get started creating beautiful designs with daisyUI
Favicon
Quick Prototyping with Tailwind and DaisyUI
Favicon
Adding Tailwind and Daisy UI to SvelteKit
Favicon
Sveltekit web gallery app

Featured ones: