Open ollyde opened 1 year ago
For anyone else who gets this bug, here is a temporary drop-down that works perfect.
<script lang="ts">
import { browser } from "$app/environment";
import { onDestroy } from "svelte";
import { fade } from "svelte/transition";
export let isOpen = false;
let dropdown: any;
function toggleDropdown() {
isOpen = !isOpen;
}
function handleClickOutside(event: any) {
if (dropdown && !dropdown.contains(event.target)) {
isOpen = false;
}
}
onDestroy(() => {
if (browser) {
document.removeEventListener("click", handleClickOutside);
}
});
if (browser) {
document.addEventListener("click", handleClickOutside);
}
</script>
<div class="dropdown" bind:this={dropdown}>
<button on:click={toggleDropdown} class="dropdown-toggle"> <slot name="button">Dropdown</slot> </button>
{#if isOpen}
<div class="dropdown-menu bg-white rounded-sm shadow-md drop-shadow-sm" transition:fade|local={{ duration: 100 }}>
<slot />
</div>
{/if}
</div>
<style>
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-toggle {
cursor: pointer;
}
.dropdown-menu {
margin-top: 8px;
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
transform: translateX(-50%); /* Adjust positioning */
left: 50%; /* Adjust positioning */
}
</style>
Describe the bug
When using a bind with open the drop-down doesn't work on Safari (mobile and desktop)
Reproduction
Works on everything
Does not work on Safari mobile or desktop
Flowbite version and System Info