From 53010d32bce5cf9b2f45b11300d30e5a4e3fc223 Mon Sep 17 00:00:00 2001 From: Alex Krush Date: Mon, 17 Jun 2019 23:03:06 -0400 Subject: [PATCH] added option for `rowSelect` which enables a highlight when pressing with mouse as well as activates cursor: pointer --- README.md | 1 + src/MUIDataTable.js | 2 ++ src/components/TableBodyRow.js | 12 ++++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b7e9c9c79..06436dd22 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,7 @@ The component accepts the following props: |**`rowsPerPage`**|number|10|Number of rows allowed per page |**`rowsPerPageOptions`**|array|[10,15,20]|Options to provide in pagination for number of rows a user can select |**`rowHover`**|boolean|true|Enable/disable hover style over rows +|**`rowSelect`**|boolean|false|Enable/disable select style over rows (mouse pointer / highlight on press) |**`fixedHeader`**|boolean|true|Enable/disable fixed header columns |**`sortFilterList`**|boolean|true|Enable/disable alphanumeric sorting of filter lists |**`sort`**|boolean|true|Enable/disable sort on all columns diff --git a/src/MUIDataTable.js b/src/MUIDataTable.js index cbc424a6b..53a2bf478 100644 --- a/src/MUIDataTable.js +++ b/src/MUIDataTable.js @@ -129,6 +129,7 @@ class MUIDataTable extends React.Component { onTableInit: PropTypes.func, caseSensitive: PropTypes.bool, rowHover: PropTypes.bool, + rowSelect: PropTypes.bool, fixedHeader: PropTypes.bool, page: PropTypes.number, count: PropTypes.number, @@ -247,6 +248,7 @@ class MUIDataTable extends React.Component { caseSensitive: false, serverSide: false, rowHover: true, + rowSelect: false, fixedHeader: true, elevation: 4, rowsPerPage: 10, diff --git a/src/components/TableBodyRow.js b/src/components/TableBodyRow.js index 044e419f0..5ada37ddc 100644 --- a/src/components/TableBodyRow.js +++ b/src/components/TableBodyRow.js @@ -6,7 +6,15 @@ import { withStyles } from '@material-ui/core/styles'; const defaultBodyRowStyles = theme => ({ root: {}, - hover: {}, + hover: { + cursor: 'pointer', + '&$root': { + '&:hover:active': { + background: 'rgb(0,106,195, 0.2)', + color: 'white' + } + } + }, hoverCursor: { cursor: 'pointer' }, responsiveStacked: { [theme.breakpoints.down('sm')]: { @@ -37,7 +45,7 @@ class TableBodyRow extends React.Component { className={classNames( { [classes.root]: true, - [classes.hover]: options.rowHover, + [classes.hover]: !!options.rowSelect, [classes.hoverCursor]: options.selectableRowsOnClick || options.expandableRowsOnClick, [classes.responsiveStacked]: options.responsive === 'stacked', },