Skip to content

Table and Dropdown are used together, Dropdown cannot disappear automatically #1451

Closed
@ltybenet

Description

@ltybenet

Summary

After the data list changes, the Dropdown does not disappear

Basic example

<script>
	import {
		Table,
		TableBody,
		TableBodyCell,
		TableBodyRow,
		TableHead,
		TableHeadCell,
		Button,
		Dropdown,
		DropdownItem,
		ToolbarButton,
		DropdownDivider
	} from 'flowbite-svelte';
	import { DotsHorizontalOutline, DotsVerticalOutline } from 'flowbite-svelte-icons';
	let alldata = [
		{ name: 'a', value: '1' },
		{ name: 'b', value: '2' },
		{ name: 'c', value: '3' }
	];
	function deletedata() {
		alldata = [
			{ name: 'a', value: '1' },
			{ name: 'b', value: '2' }
		];
	}
</script>

<Table divClass="overflow-x-auto">
	<TableHead>
		<TableHeadCell>name</TableHeadCell>
		<TableHeadCell>value</TableHeadCell>
		<TableHeadCell>edit</TableHeadCell>
	</TableHead>
	<TableBody tableBodyClass="divide-y">
		{#each alldata as d}
			<TableBodyRow>
				<TableBodyCell>{d.name}</TableBodyCell>
				<TableBodyCell>{d.value}</TableBodyCell>
				<TableBodyCell>
					<DotsHorizontalOutline class="dark:text-white" />
					<Dropdown>
						<DropdownItem
							on:click={() => {
								deletedata();
							}}>delete</DropdownItem
						>
					</Dropdown>
				</TableBodyCell>
			</TableBodyRow>
		{/each}
	</TableBody>
</Table>

20240926121533

Motivation

How to make Dropdown disappear after data changes in Table?

There is also a table problem

When divClass="overflow-x-auto" is not used, the table will have a scroll bar
1533

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions