Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ltybenet opened this issue Sep 26, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@ltybenet
Copy link

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

@ltybenet ltybenet added the enhancement New feature or request label Sep 26, 2024
@shinokada
Copy link
Collaborator

Try this:

let dropdownStatus = false
function deletedata() {
  alldata = [
      { name: 'a', value: '1' },
      { name: 'b', value: '2' }
  ];
}

// more code
{#if dropdownStatus}
<DotsHorizontalOutline class="dark:text-white" />
  <Dropdown>
    <DropdownItem
       on:click={() => {
       deletedata();
      }}>delete</DropdownItem
  >
 </Dropdown>
{/if)

@ltybenet
Copy link
Author

ltybenet commented Sep 27, 2024

Thanks for reply.
If dropdownStatus is false initially, the user will not be able to see the button, so it must be true initially.
According to the above reply, I changed the code.
But the problem still exists.

It would be best if the Dropdown disappears automatically after clicking the DropdownItem option
I tried using Programatic_open/close, but it is not very friendly to table

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

<Table>
	<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>
					{#if dropdownStatus}
						<DotsHorizontalOutline class="dark:text-white" />
						<Dropdown>
							<DropdownItem
								on:click={() => {
									deletedata();
								}}>delete</DropdownItem
							>
						</Dropdown>
					{/if}
				</TableBodyCell>
			</TableBodyRow>
		{/each}
	</TableBody>
</Table>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants