Skip to content

Commit

Permalink
Add: Command click to select item on table view.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Mar 5, 2024
1 parent 371a3ec commit dd7c7e7
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions packages/dataviews/src/view-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,39 @@ function TableRow( {
data,
} ) {
const hasPossibleBulkAction = useHasAPossibleBulkAction( actions, item );
const isSelected = selection.includes( id );
return (
<tr
className={ classnames( 'dataviews-view-table__row', {
'is-selected':
hasPossibleBulkAction && selection.includes( id ),
'is-selected': hasPossibleBulkAction && isSelected,
} ) }
onClickCapture={ ( event ) => {
if ( event.ctrlKey || event.metaKey ) {
event.stopPropagation();
event.preventDefault();
if ( ! isSelected ) {
onSelectionChange(
data.filter( ( _item ) => {
const itemId = getItemId?.( _item );
return (
itemId === id ||
selection.includes( itemId )
);
} )
);
} else {
onSelectionChange(
data.filter( ( _item ) => {
const itemId = getItemId?.( _item );
return (
itemId !== id &&
selection.includes( itemId )
);
} )
);
}
}
} }
>
{ hasBulkActions && (
<td
Expand Down

0 comments on commit dd7c7e7

Please sign in to comment.