We want a table where multiple rows of a terra-table can be selected. Currently, there is only a SingleSelectableRows component. A parallel MultipleSelectableRows component should be made.
isSelected propisSelectable is false. * isSelectable is false. * * - isSelectable could be renamed/ a new prop with different name could be used to something else to better convey this functionality, especially with deselect.
N/A
Adds a new component MultiSelectableRows that is accessable from terra-table.
| Prop Name | Type | Is Required | Default Value | Description |
|-|-|-|-|-|
| children| node| optional| | The children passed to the component|
| maxSelectionCount | number | optional| undefined|The maximum number of rows that can be selected.|
| onChange| func| optional| undefined| A callback function for onChange action. Has the following parameters:
import React from 'react';
import Table from 'terra-table';
<Table isStriped={false}>
<Table.Header>
<Table.HeaderCell content={'Column Heading 1'} key={'COLUMN_0'} minWidth={'small'} />
<Table.HeaderCell content={'Column Heading 2'} key={'COLUMN_1'} minWidth={'medium'} />
<Table.HeaderCell content={'Column Heading 3'} key={'COLUMN_2'} minWidth={'large'} />
</Table.Header>
<Table.MultiSelectableRows>
<Table.Row isSelected={true} key={'ROW_0'}>
<Table.Cell content={'Table Data'} key={'COLUMN_0'} />
<Table.Cell content={'Table Data'} key={'COLUMN_1'} />
<Table.Cell content={'Table Data'} key={'COLUMN_2'} />
</Table.Row>
<Table.Row key={'ROW_1'}>
<Table.Cell content={'Table Data'} key={'COLUMN_0'} />
<Table.Cell content={'Table Data'} key={'COLUMN_1'} />
<Table.Cell content={'Table Data'} key={'COLUMN_2'} />
</Table.Row>
<Table.Row key={'ROW_2'}>
<Table.Cell content={'Table Data'} key={'COLUMN_0'} />
<Table.Cell content={'Table Data'} key={'COLUMN_1'} />
<Table.Cell content={'Table Data'} key={'COLUMN_2'} />
</Table.Row>
</Table.MultiSelectableRows>
</Table>
None
Add prop maxSelectionCount to define the maximum number of rows that can be selected. This would make table API consistent with list API.
For the onChange callback, the list API only returns the event and the list of selected indexes. Again I think this should be consistent with the list's behavior. I would be curious what others think about return the last selected index. That might be a change we would want to make in multi-select list then.
* isSelectable could be renamed/ a new prop with different name could be used to something else to better convey this functionality, especially with deselect.
What do you mean by this?
Re: isSelectable. The rows should be selectable and unselectable. Tables.row only has an isSelectable prop, but saying something "isSelectable" doesn't really say anything about the fact that it can be "deselected" and could be confusing. It's just a naming nuance. Something like "isSelectionChangeable" makes more sense from that kind of standpoint, but really only makes sense when defined on a Table.row that is nested within one of these *SelectableRows components anyways.
I'd prefer to keep isSelectable prop the same. It's the same terminology used in our other components (i.e. List). I believe that it's generally understood that a component that allows multiple items to be selected also allows you to deselect those items. And I'm not a fan of making non-passive api changes for the sole purpose of renaming a prop.
@emilyrohrbough Updated tech design to include maxSelectionCount.
Re: isSelectable. I'm fine with leaving the prop the same. I also wasn't in love with making a non-passive change. I just wanted to bring light to it being possibly ambiguous.
And I can change the onChange parameters. It's just a convenience API so that users can know exactly what changed, but if other Terra components don't have this feature, perhaps it would be better to do a tech design on the need for it and introduce it consistently throughout.
May need to consider the integration of these two issues, involving selectable sub-components:
@dkasper-was-taken and @emilyrohrbough , my initial design was for a "MultipleSelectableRows" component. Given similarity to the terra-list component, and terra-list already uses the name "MultiSelectList", should I rename this component to "MultiSelectableRows", rather than multiple? I kept the "selectable"vs "select" because SingleSelectableRows already exists.
I'm also wondering about the desired behavior of the onChange. Did we ever decide on the parameters of that callback? And should we be sorting the selected indexes? I noticed that the MultiSelectList component doesn't sort, so the array given back will be just based on the order the user clicked on them. It seems like this could be surprising behavior for consumers and doesn't seem as "pure", as the UI doesn't directly translate to the state with time-based ordering involved.
MultiSelectableRows But no, I can't think of any scenario where sorting is required. But I also can't think of any scenario where the time-based ordering is required. I'm down with whatever though, just an API consideration I had.
I can see the value in returning the last updated row. I think if we have that in the table we should add it to the list as well. I'm just thinking returning the item or an object containing the index and the new selection state would be more helpful than just the index.
Right. The index will be returned as the 3rd parameter to the callback, while the new selection state will be returned as the 2nd parameter. So as far as the first 2 parameters go, it is in consistency with the terra-list API, the 3rd would just be a new feature and could be added to terra-list with passivity maintained.
Went ahead and updated the technical design to use MultiSelectableRows and removed the documentation/requirement about sorting. Let me know if there are any other concerns, as I should freeing up to start working on this again.
@dv297 This has been released in terra-table 1.16.0
Most helpful comment
I'd prefer to keep
isSelectableprop the same. It's the same terminology used in our other components (i.e. List). I believe that it's generally understood that a component that allows multiple items to be selected also allows you to deselect those items. And I'm not a fan of making non-passive api changes for the sole purpose of renaming a prop.