Skip to content

Commit

Permalink
Add: Command click to select item on table view. (#59563)
Browse files Browse the repository at this point in the history
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
  • Loading branch information
jorgefilipecosta and jorgefilipecosta authored Mar 6, 2024
1 parent 24421f7 commit 267b358
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 267b358

Please sign in to comment.