-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
25 additions
and
4 deletions.
There are no files selected for viewing
25 changes: 23 additions & 2 deletions
25
src/lib/components/generics/table/TableCellCheckbox.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,29 @@ | ||
<script lang="ts"> | ||
import type { ChangeEventHandler } from "svelte/elements"; | ||
import TableCell from "./TableCell.svelte"; | ||
export let group: Array<string>; | ||
export let group: string[]; | ||
export let value: string; | ||
/** | ||
* @description Function to handle the checkbox change event | ||
* @warning Using an onChange function to bypass https://github.com/sveltejs/svelte/issues/2308 | ||
* @warning The previous implementation should work out of the box if this issue was solved. | ||
**/ | ||
const onChange: ChangeEventHandler<HTMLInputElement> = (e) => { | ||
if(e.target === null) return; | ||
const { value, checked } = e.target as any; // prevent ts to be angry because he dont know that the element is a checkbox input | ||
if(checked) | ||
group = [...group, value]; | ||
else | ||
group = group.filter((item) => item !== value); | ||
} | ||
</script> | ||
|
||
<TableCell class="items-center"><input type="checkbox" bind:group {value} /></TableCell> | ||
<TableCell class="items-center"> | ||
<input type="checkbox" {value} checked={group.includes(value)} on:change={onChange} /> | ||
</TableCell> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters