Skip to content

Instantly share code, notes, and snippets.

@osbre
Last active March 24, 2025 16:46
Show Gist options
  • Save osbre/222bbc7bf09d30813e52e5f4ad2be5d6 to your computer and use it in GitHub Desktop.
Save osbre/222bbc7bf09d30813e52e5f4ad2be5d6 to your computer and use it in GitHub Desktop.
Laravel Breeze HTML5 native dropdown component (no JavaScript). Remove any inner <button>'s when using.
@props(['align' => 'right', 'width' => '48', 'contentClasses' => 'py-1 bg-white'])
@php
$alignmentClasses = match ($align) {
'left' => 'ltr:origin-top-left rtl:origin-top-right start-0',
'top' => 'origin-top',
default => 'ltr:origin-top-right rtl:origin-top-left end-0',
};
$width = match ($width) {
'48' => 'w-48',
default => $width,
};
@endphp
<details class="relative">
<summary class="list-none cursor-pointer inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-gray-500 bg-white hover:text-gray-700 focus:outline-hidden transition ease-in-out duration-150">
{{ $trigger }}
</summary>
<div class="absolute z-50 mt-2 {{ $width }} rounded-md shadow-lg {{ $alignmentClasses }}">
<div class="rounded-md ring-1 ring-black ring-opacity-5 {{ $contentClasses }}">
{{ $content }}
</div>
</div>
</details>
@osbre
Copy link
Author

osbre commented Mar 24, 2025

To close it when clicked outside, ad this to your app.css

/*... rest of your Tailwind CSS 4 file */

@layer components {
    details[open] summary::before {
        content: "";
        width: 100vw;
        height: 100vh;
        position: fixed;
        top: 0;
        left: 0;
        cursor: auto;
    }
}

and add .dropdown to <details>

<details class="dropdown relative">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment