Skip to content

Commit

Permalink
Merge pull request #181 from pouryapb/master
Browse files Browse the repository at this point in the history
Added onMouseEnter and onMouseLeave listeners to action
  • Loading branch information
matthewoestreich authored May 1, 2021
2 parents 3aa6640 + 0ce10ad commit e028749
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
35 changes: 35 additions & 0 deletions __tests__/demo/demo-components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,41 @@ export function HidingColumns(props) {
);
}

export function TestingNewActionHandlersProp(props) {
return (
<MaterialTable
actions={[
{
icon: 'save',
tooltip: 'Save User',
//onClick: (event, rowData) => alert('You saved ' + rowData.name),
handlers: {
onMouseEnter: (event, props) => {
console.log({ from: 'handlers.onMouseEnter', event, props });
},
onMouseLeave: (event, props) => {
console.log({ from: 'handlers.onMouseLeave', event, props });
},
onClick: (event, props) => console.log('onclick', { event, props })
}
}
]}
data={[
{ name: 'jack', id: 1 },
{ name: 'nancy', id: 2 }
]}
columns={[
{
field: 'name',
title: 'Name',
hiddenByColumnsButton: true
},
{ field: 'id', title: 'Identifier', type: 'numeric' }
]}
/>
);
}

/*
const global_cols = [
{ title: 'Name', field: 'name' },
Expand Down
4 changes: 4 additions & 0 deletions __tests__/demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { render } from 'react-dom';
import {
Basic,
OneDetailPanel,
TestingNewActionHandlersProp,
BulkEdit,
BulkEditWithDetailPanel,
ExportData,
Expand Down Expand Up @@ -59,6 +60,9 @@ render(
<h1>Hiding Columns</h1>
<HidingColumns />

<h1>TestingNewActionHandlersProp</h1>
<TestingNewActionHandlersProp />

<h1>Editable Rows</h1>
<EditableRow />

Expand Down
9 changes: 9 additions & 0 deletions src/components/MTableAction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ function MTableAction(props) {
}
};

// You may provide events via the "action.handers" prop. It is an object.
// The event name is the key, and the value is the handler func.
const handlers = action.handlers || {};
const eventHandlers = Object.entries(handlers).reduce((o, [k, v]) => {
o[k] = (e) => v(e, props.data);
return o;
}, {});

const icon =
typeof action.icon === 'string' ? (
<Icon {...action.iconProps}>{action.icon}</Icon>
Expand All @@ -52,6 +60,7 @@ function MTableAction(props) {
color="inherit"
disabled={disabled}
onClick={handleOnClick}
{...eventHandlers}
>
{icon}
</IconButton>
Expand Down
2 changes: 2 additions & 0 deletions src/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const propTypes = {
]),
tooltip: PropTypes.string,
onClick: PropTypes.func.isRequired,
onMouseEnter: PropTypes.func,
onMouseLeave: PropTypes.func,
iconProps: PropTypes.object,
disabled: PropTypes.bool,
hidden: PropTypes.bool
Expand Down

0 comments on commit e028749

Please sign in to comment.