Skip to content

Commit 097783b

Browse files
authored
fix: single row deselection in Table (#2323)
1 parent 5a85d11 commit 097783b

File tree

7 files changed

+225
-223
lines changed

7 files changed

+225
-223
lines changed

.changeset/cyan-tools-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"xmlui": patch
3+
---
4+
5+
Fixed Table row deselection if multiple row selections are disabled.

docs/content/components/Table.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,26 @@ Select a column header and set it to descending ordering.
697697
</App>
698698
```
699699

700+
### `idKey` (default: "id") [#idkey-default-id]
701+
702+
This property is used to specify the unique ID property in the data array. If the idKey points to a property that does not exist in the data items, that will result in incorrect behavior when using selectable rows.
703+
704+
```xmlui copy /idKey="key"/
705+
<App>
706+
<Table
707+
idKey="key"
708+
rowsSelectable="true"
709+
data="{[
710+
{ 'key': 0, 'name': 'John' },
711+
{ 'key': 1, 'name': 'Jane' },
712+
{ 'key': 2, 'name': 'Bill' },
713+
]}"
714+
>
715+
<Column bindTo="name"/>
716+
</Table>
717+
</App>
718+
```
719+
700720
### `initiallySelected` [#initiallyselected]
701721

702722
An array of IDs that should be initially selected when the table is rendered. This property only has an effect when the rowsSelectable property is set to `true`.

xmlui/src/components/SelectionStore/SelectionStoreNative.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ type SelectionStoreProps = {
2828
const EMPTY_SELECTION_STATE = {
2929
value: EMPTY_ARRAY,
3030
};
31-
export const StandaloneSelectionStore = ({ children }) => {
31+
export const StandaloneSelectionStore = ({
32+
children,
33+
idKey,
34+
}: {
35+
children: ReactNode;
36+
idKey?: string;
37+
}) => {
3238
const [selection, setSelection] = useState(EMPTY_SELECTION_STATE);
3339
return (
34-
<SelectionStore updateState={setSelection} selectedItems={selection.value}>
40+
<SelectionStore updateState={setSelection} selectedItems={selection.value} idKey={idKey}>
3541
{children}
3642
</SelectionStore>
3743
);

xmlui/src/components/Table/Table.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,12 +1609,12 @@ Click on any of the column headers to trigger a new sorting:
16091609

16101610
%-API-END
16111611

1612-
%-API-START dataIdProperty
1612+
%-PROP-START idKey
16131613

1614-
```xmlui copy /dataIdProperty="key"/
1614+
```xmlui copy /idKey="key"/
16151615
<App>
16161616
<Table
1617-
dataIdProperty="key"
1617+
idKey="key"
16181618
rowsSelectable="true"
16191619
data="{[
16201620
{ 'key': 0, 'name': 'John' },
@@ -1627,4 +1627,4 @@ Click on any of the column headers to trigger a new sorting:
16271627
</App>
16281628
```
16291629

1630-
%-API-END
1630+
%-PROP-END

xmlui/src/components/Table/Table.spec.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -903,34 +903,11 @@ test.describe("Edge Cases", () => {
903903
}
904904
);
905905

906-
test("row checkboxes work when 'dataIdProperty' property is specified",
907-
async ({ initTestBed, page }) => {
908-
await initTestBed(`
909-
<Table testId="table" rowsSelectable="true"
910-
dataIdProperty="account_id"
911-
data="{[
912-
{ account_id: 1, name: 'Item 1' },
913-
{ account_id: 2, name: 'Item 2' }
914-
]}">
915-
<Column bindTo="account_id" width="80px">
916-
<Text>{$item.account_id}</Text>
917-
</Column>
918-
<Column bindTo="name">
919-
<Text>{$item.name}</Text>
920-
</Column>
921-
</Table>
922-
`);
923-
const checkboxes = page.locator("input[type='checkbox']");
924-
await checkboxes.nth(1).check({ force: true }); // First data row
925-
await expect(checkboxes.nth(1)).toBeChecked();
926-
await expect(checkboxes.nth(2)).not.toBeChecked(); // Second data row
927-
}
928-
);
929-
930-
test("row checkboxes work when no 'dataIdProperty' prop and no 'id' in data items",
906+
test("row checkboxes work when 'idKey' property is specified",
931907
async ({ initTestBed, page }) => {
932908
await initTestBed(`
933909
<Table testId="table" rowsSelectable="true"
910+
idKey="account_id"
934911
data="{[
935912
{ account_id: 1, name: 'Item 1' },
936913
{ account_id: 2, name: 'Item 2' }

0 commit comments

Comments
 (0)