mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
fix(data-table): cancelling selection should uncheck batch selection checkbox
This commit is contained in:
parent
a2b375f32e
commit
a0caa12a27
3 changed files with 148 additions and 136 deletions
|
@ -22,9 +22,16 @@
|
|||
* @type {string} [id]
|
||||
*/
|
||||
export let id = "ccs-" + Math.random().toString(36);
|
||||
|
||||
/**
|
||||
* Obtain a reference to the input HTML element
|
||||
* @type {null | HTMLInputElement} [ref=null]
|
||||
*/
|
||||
export let ref = null;
|
||||
</script>
|
||||
|
||||
<input
|
||||
bind:this="{ref}"
|
||||
type="checkbox"
|
||||
class:bx--checkbox="{true}"
|
||||
checked="{indeterminate ? false : checked}"
|
||||
|
|
|
@ -131,7 +131,9 @@
|
|||
tableSortable,
|
||||
batchSelectedIds,
|
||||
resetSelectedRowIds: () => {
|
||||
selectAll = false;
|
||||
selectedRowIds = [];
|
||||
if (refSelectAll) refSelectAll.checked = false;
|
||||
},
|
||||
add: (id) => {
|
||||
headerItems.update((_) => [..._, id]);
|
||||
|
@ -147,6 +149,8 @@
|
|||
);
|
||||
|
||||
let selectAll = false;
|
||||
let refSelectAll = null;
|
||||
|
||||
$: batchSelectedIds.set(selectedRowIds);
|
||||
$: indeterminate =
|
||||
selectedRowIds.length > 0 && selectedRowIds.length < rows.length;
|
||||
|
@ -221,6 +225,7 @@
|
|||
{#if batchSelection && !radio}
|
||||
<th scope="col" class:bx--table-column-checkbox="{true}">
|
||||
<InlineCheckbox
|
||||
bind:ref="{refSelectAll}"
|
||||
aria-label="Select all rows"
|
||||
checked="{selectAll}"
|
||||
indeterminate="{indeterminate}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue