Skip to content

Commit

Permalink
chore: change to force consumers to override
Browse files Browse the repository at this point in the history
  • Loading branch information
oze4 committed Aug 1, 2021
1 parent 3b6c63d commit 48a08aa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 6 additions & 1 deletion __tests__/demo/demo-components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,6 @@ export function EventTargetErrorOnRowClick(props) {
props.onSelectionChange(rows);
};
const onRowClicked = (evt, rowData) => {
evt.persist();
console.log(evt.target);
};

Expand Down Expand Up @@ -550,6 +549,12 @@ export function EventTargetErrorOnRowClick(props) {
data={datas}
onSelectionChange={onRowSelectionChanged}
onRowClick={onRowClicked}
components={{
MTableBodyRow: (props, p2) => {
console.log({ props, p2 });
return <MTableBodyRow {...props} persistEvents={true} />;
}
}}
options={{
selection: true
}}
Expand Down
9 changes: 6 additions & 3 deletions src/components/m-table-body-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default function MTableBodyRow(props) {
onDoubleRowClick,
...rowProps
} = props;

const onClick = (event, callback) =>
callback(event, data, (panelIndex) => {
let panel = detailPanel;
Expand All @@ -52,11 +53,13 @@ export default function MTableBodyRow(props) {
}
onToggleDetailPanel(path, panel);
});

const onRowClickListener = useDoubleClick(
onRowClick ? (e) => onClick(e, onRowClick) : undefined,
onDoubleRowClick ? (e) => onClick(e, onDoubleRowClick) : undefined,
persistEvents
);

const getRenderColumns = () => {
const size = CommonValues.elementSize(props);
const mapArr = props.columns
Expand Down Expand Up @@ -509,9 +512,9 @@ MTableBodyRow.defaultProps = {
index: 0,
data: {},
options: {},
path: [],
// onRowClick, onRowDoubleClick events will be persisted
persistEvents: true
path: []
/** if this is not set, it's like it ignores this prop when overriding? */
// persistEvents: true
};

MTableBodyRow.propTypes = {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/hooks/useDoubleClick.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

function useDoubleClick(singleCallback, dbCallback, persistEvents = false) {
function useDoubleClick(singleCallback, dbCallback, persistEvents) {
const countRef = React.useRef(0);
/** Refs for the timer **/
const timerRef = React.useRef(null);
Expand Down

0 comments on commit 48a08aa

Please sign in to comment.