Next.js Discord

Discord Forum

client component for dropdown?

Answered
Naeemgg posted this in #help-forum
Open in Discord
Avatar
can anyone please tell me why I this dropdown not working??
<button id="dropdownDefaultButton" data-dropdown-toggle="dropdown" className="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" type="button">Dropdown button <svg className="w-2.5 h-2.5 ml-2.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 10 6">
    <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 4 4 4-4"/>
  </svg></button>

<div id="dropdown" className="z-10 hidden bg-white divide-y divide-gray-100 rounded-lg shadow w-44 dark:bg-gray-700">
    <ul className="py-2 text-sm text-gray-700 dark:text-gray-200" aria-labelledby="dropdownDefaultButton">
      <li>
        <a href="#" className="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Dashboard</a>
      </li>
      <li>
        <a href="#" className="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Settings</a>
      </li>
      <li>
        <a href="#" className="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Earnings</a>
      </li>
      <li>
        <a href="#" className="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Sign out</a>
      </li>
    </ul>
</div>

I copied it from here https://flowbite.com/docs/components/dropdowns/
Answered by Julienng
Hi, without a reproduction link (something like codesandbox), I would say it is not working because there is no JS associated with the markup you paste. See point 4. on the quick-start of flowbite

As a recommendation, I would not build a Dropdown like that because it is horrible on the accessibility side. I can't even use it with the keyboard at all in their example.

I would look at:
- https://www.radix-ui.com/primitives/docs/components/dropdown-menu
- https://react-spectrum.adobe.com/react-aria/Menu.html

Those components are doing the behavior without the style, so you can customize the visual of your component with tailwind and having a great accessibility and functionality already backed up.
View full answer

2 Replies

Avatar
Please ignore the <a> tags I'll swap it with <Link> once I get my answer.
Avatar
Hi, without a reproduction link (something like codesandbox), I would say it is not working because there is no JS associated with the markup you paste. See point 4. on the quick-start of flowbite

As a recommendation, I would not build a Dropdown like that because it is horrible on the accessibility side. I can't even use it with the keyboard at all in their example.

I would look at:
- https://www.radix-ui.com/primitives/docs/components/dropdown-menu
- https://react-spectrum.adobe.com/react-aria/Menu.html

Those components are doing the behavior without the style, so you can customize the visual of your component with tailwind and having a great accessibility and functionality already backed up.
Answer