Skip to content

Commit 8bd6f21

Browse files
authored
Fix 684 (#717)
* expose data-tag="allowRowEvents"
1 parent d8ca9b7 commit 8bd6f21

File tree

9 files changed

+36
-32
lines changed

9 files changed

+36
-32
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ Nothing new here - we are using an array of object literals and properties to de
111111
|----------|--------|----------|---------------------------------------------------------------------------------------------------------------|
112112
| name | string, component or number | no | the display name of our Column e.g. 'Name' |
113113
| selector | string or (row, index) => {} | no | a data set property in dot notation. e.g. <br /> `property1.nested1.nested2` <br /> `property1.items[0].nested2` <br /> or as a function e.g. <br /> `row => row.timestamp`. A `selector` is required anytime you want to display data but can be ommitted if your column does not require showing data (e.g. an actions column) |
114-
| sortable | bool | no | if the column is sortable. note that `selector` is required for the column to sort |
114+
| sortable | bool | no | if the column is sortable. <br /><br />**Note:** `selector` is required for the column to sort |
115115
| sortFunction | function | no | custom sorting function e.g. `(rowA, rowB) => rowA.myIndex - rowB.myIndex` (see [Array.prototype.sort()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)) |
116116
| format | (row, index) => {} | no | apply formatting to the selector e.g. `row => moment(row.timestamp).format('lll')` without changing the actual selector value. |
117-
| cell | (row, index, column, id) => {} | no | for ultimate control use `cell` to render your own custom component! e.g `row => <h2>{row.title}</h2>` <br /> **negates `format`** |
117+
| cell | (row, index, column, id) => {} | no | for ultimate control use `cell` to render your own custom component!<br />e.g `row => <h2>{row.title}</h2>`. <br /> <br />if you are using properties such as `onRowClicked` or `onRowDoubleClicked` those click events will be ignored when clicking on your custom cell. If your component is more complex and has nested elements you want to add `data-tag="allowRowEvents"` to the innermost element or on the elements you want to propagate the click event to. <br />e.g `row => <h2 data-tag="allowRowEvents">{row.title}</h2>` <br /><br />**Note:** that using `cell` **negates `format`**. |
118118
| grow | number | no | [flex-grow](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow) of the column. This is useful if you want a column to take up more width than its relatives (without having to set widths explicitly). this will be affected by other columns where you have explicitly set widths |
119119
| width | string | no | give the column a fixed width |
120120
| minWidth | string | no | give the column a minWidth |
@@ -160,8 +160,8 @@ When the breakpoint is reached the column will be hidden. These are the built-in
160160
| style | object | no | | override the style on the Table wrapper |
161161
| responsive | bool | no | true | makes the table horizontally scrollable on smaller screen widths |
162162
| disabled | bool | no | false | disables the Table section |
163-
| onRowClicked | func | no | | callback to access the row, event on row click |
164-
| onRowDoubleClicked | func | no | | callback to access the row, event on row double click |
163+
| onRowClicked | func | no | | callback to access the row, event on row click. <br /> Note that if you are using custom cells (`column[].cell`), you will need to apply the `data-tag="allowRowEvents"` to the innermost element or on the elements you want to propagate the `onRowClicked` event to. |
164+
| onRowDoubleClicked | func | no | | callback to access the row, event on row double click. <br /> Note that if you are using custom cells (`column[].cell`), you will need to apply the `data-tag="allowRowEvents"` to the innermost element or on the elements you want to propagate the `onRowDoubleClicked` event to. |
165165
| overflowY | bool | no | false | if a table is responsive, items such as layovers/menus/dropdowns will be clipped on the last row(s) due to to [overflow-x-y behavior](https://www.brunildo.org/test/Overflowxy2.html) - setting this value ensures there is invisible space below the table to prevent "clipping". However, if possible, the **correct approach is to use menus/layovers/dropdowns that support smart positioning**. **If used, the table parent element must have a fixed `height` or `height: 100%`**. |
166166
| overflowYOffset | string | no | 250px | used with overflowY to "fine tune" the offset |
167167
| dense | bool | no | false | compacts the row height. can be overridden via theming `rows.denseHeight`. note that if any custom elements exceed the dense height then the row will only compact to the tallest element any of your cells |
@@ -193,9 +193,9 @@ When the breakpoint is reached the column will be hidden. These are the built-in
193193
| expandableRowExpanded | func | no | | Expand a row based on a property in your data. e.g. `row => row.expandMe`. `expandableRowExpanded` must return a boolean to determine if the row should be programatically expanded. |
194194
| expandableRowDisabled | func | no | | Disable a row expand based on a property in your data. e.g. `row => row.expandDisabled`. `expandableRowDisabled` must return a boolean to determine if the row should be programatically disabled. |
195195
| expandableRowsComponent | string or component | no | | A custom component to display in the expanded row. It will have the `data` prop composed so that you may access the row data |
196-
| expandOnRowClicked | bool | no | | The default behavior is to expand the row when the expander button is clicked. `expandOnRowClicked` allows expanding the row when an area within the row is clicked. Requires `expandableRows` be set to true. Note that if you are using custom cells you will need to apply the following to the root of your custom cell `data-tag="___react-data-table-allow-propagation___"` so that the event handler can be attached to your custom component |
197-
| expandOnRowDoubleClicked | bool | no | | The default behavior is to expand the row when the expander button is clicked. `expandOnRowDoubleClicked` allows expanding the row when an area within the row is double clicked. Requires `expandableRows` be set to true. Note that if you are using custom cells you will need to apply the following to the root of your custom cell `data-tag="___react-data-table-allow-propagation___"` so that the event handler can be attached to your custom component |
198-
| expandableRowsHideExpander | vool | no | false | Do not render the expander button. This is useful when using `expandOnRowClicked` or `expandOnRowDoubleClicked` |
196+
| expandOnRowClicked | bool | no | | The default behavior is to expand the row when the expander button is clicked. `expandOnRowClicked` allows expanding the row when an area within the row is clicked. Requires `expandableRows` be set to true. <br /><br />**Note:** that if you are using custom cells (`column[].cell`), you will need to apply the `data-tag="allowRowEvents"` to the innermost element or on the elements you want to propagate the `expandOnRowClicked` event to. |
197+
| expandOnRowDoubleClicked | bool | no | | The default behavior is to expand the row when the expander button is clicked. `expandOnRowDoubleClicked` allows expanding the row when an area within the row is double clicked. Requires `expandableRows` be set to true. <br /><br />**Note:** that if you are using custom cells (`column[].cell`), you will need to apply the `data-tag="allowRowEvents"` to the innermost element or on the elements you want to propagate the `expandOnRowDoubleClicked` event to. t |
198+
| expandableRowsHideExpander | bool | no | false | Do not render the expander button. This is useful when using `expandOnRowClicked` or `expandOnRowDoubleClicked` |
199199
| onRowExpandToggled | func | false | | When a row is Expanded or Collapsed `onRowExpandToggled` will fire and return (toggleState, row) |
200200
| expandableInheritConditionalStyles | bool | no | false | Whether to apply `conditionalRowStyles` to the expander row |
201201

@@ -204,19 +204,19 @@ When the breakpoint is reached the column will be hidden. These are the built-in
204204
| Property | Type | Required | Default | Description |
205205
|--------------------------|---------------------|----------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
206206
| defaultSortField | string | no | | setting this ensures the table data is presorted before it renders and the field(selector) is focused |
207-
| defaultSortAsc | bool | no | true | set this to false if you want the table data to be sorted in DESC order. Note that this will apply work when the table is initially loaded |
207+
| defaultSortAsc | bool | no | true | set this to false if you want the table data to be sorted in DESC order. <br /><br />**Note:** This will apply work when the table is initially loaded |
208208
| sortIcon | component | no | | override the default sort icon - the icon must be a font or svg icon and it should be a "downward" icon since animation will be handled by React Data Table |
209209
| onSort | func | no | | callback to access the sort state when a column is clicked. returns ([column](https://github.com/jbetancur/react-data-table-component#columns), sortDirection, event) |
210210
| sortFunction | func | no | | pass in your own custom sort function e.g. `(rows, field, direction) => {...yourSortLogicHere}`. **Your function must return an new array reference**, otherwise RDT will not "know" to re-render. For example, `Array.sort` sorts the array in place but because of JavaScript object equality it will be the same reference and will not re-render. A common pattern is to return `yourArray.slice(0)` which creates a new array.|
211-
| sortServer | bool | no | false | disables internal sorting for use with server-side sorting or when you want to manually control the sort behavior. place your sorting logic and/or api calls in an `onSort` handler. note that `sortFunction` is a better choice if you simply want to override the internal sorting behavior |
211+
| sortServer | bool | no | false | disables internal sorting for use with server-side sorting or when you want to manually control the sort behavior. place your sorting logic and/or api calls in an `onSort` handler. <br /><br />**Note:** `sortFunction` is a better choice if you simply want to override the internal sorting behavior |
212212

213213
#### Pagination
214214

215215
| Property | Type | Required | Default | Description |
216216
|--------------------------|---------------------|----------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
217217
| pagination | bool | no | false | enable pagination with defaults. by default the total record set will be sliced depending on the page, rows per page. if you wish to use server side pagination then use the `paginationServer` property |
218218
| paginationServer | bool | no | false | changes the default pagination to work with server side pagination |
219-
| paginationServerOptions | object | no | `{ persistSelectedOnPageChange: false, persistSelectedOnSort: false }` | when using `selectableRows` is used to make selected rows persist on page change and on sort when using server side pagination. *Note that when using `persistSelectedOnPageChange` that select all checkbox will not be visible (i.e. you cannot select rows there you have to retrieved from the server)* |
219+
| paginationServerOptions | object | no | `{ persistSelectedOnPageChange: false, persistSelectedOnSort: false }` | when using `selectableRows` is used to make selected rows persist on page change and on sort when using server side pagination. <br /><br />**Note:** when using `persistSelectedOnPageChange` that select all checkbox will not be visible (i.e. you cannot select rows there you have to retrieved from the server) |
220220
| paginationDefaultPage | number | no | 1 | the default page to use when the table initially loads |
221221
| paginationResetDefaultPage | bool | no | false | the prop can be "toggled" to reset the pagination back to `paginationDefaultPage`. For this to work make sure you are using some sort of state and toggling the prop. e.g. `setResetPaginationToggle(!resetPaginationToggle)` or for a class component `setState(resetPaginationToggle: !resetPaginationToggle)` |
222222
| paginationTotalRows | number | no | 0 | allows you to provide the total row count for your table as represented by your API when performing server side pagination. if this property is not provided then react-data-table will use `data.length` |
@@ -574,7 +574,7 @@ const columns = [
574574
{
575575
name: 'Title',
576576
sortable: true,
577-
cell: row => <div><div style={{ fontWeight: bold }}>{row.title}</div>{row.summary}</div>,
577+
cell: row => <div data-tag="allowRowEvents"><div style={{ fontWeight: bold }}>{row.title}</div>{row.summary}</div>,
578578
},
579579
{
580580
name: 'Year',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-data-table-component",
3-
"version": "6.11.5",
3+
"version": "6.11.6",
44
"description": "A declarative react based data table",
55
"main": "dist/index.cjs.js",
66
"module": "dist/index.es.js",

src/DataTable/TableCell.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33
import styled, { css } from 'styled-components';
44
import { Cell } from './Cell';
55
import { getProperty, getConditionalStyle } from './util';
6+
import { STOP_PROP_TAG } from './constants';
67

78
const overflowCSS = css`
89
div:first-child {
@@ -26,7 +27,7 @@ const TableCell = memo(({ id, rowIndex, column, row }) => {
2627
}
2728

2829
// apply a tag that TableRow will use to stop event propagation when TableCell is clicked
29-
const dataTag = column.ignoreRowClick || column.button ? null : '___react-data-table-allow-propagation___';
30+
const dataTag = column.ignoreRowClick || column.button ? null : STOP_PROP_TAG;
3031
const extendedCellStyle = getConditionalStyle(row, column.conditionalCellStyles);
3132

3233
return (

src/DataTable/TableRow.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import TableCellCheckbox from './TableCellCheckbox';
66
import TableCellExpander from './TableCellExpander';
77
import ExpanderRow from './ExpanderRow';
88
import { getConditionalStyle, isOdd } from './util';
9-
10-
const STOP_PROP_TAG = '___react-data-table-allow-propagation___';
9+
import { STOP_PROP_TAG } from './constants';
1110

1211
const highlightCSS = css`
1312
&:hover {
@@ -75,7 +74,7 @@ const TableRow = memo(({
7574
const showPointer = pointerOnHover || (expandableRows && (expandOnRowClicked || expandOnRowDoubleClicked));
7675

7776
const handleRowClick = useCallback(e => {
78-
// use event delegation allow events to propagate only when the element with data-tag ___react-data-table-allow-propagation___ is present
77+
// use event delegation allow events to propagate only when the element with data-tag STOP_PROP_TAG is present
7978
if (e.target && e.target.getAttribute('data-tag') === STOP_PROP_TAG) {
8079
onRowClicked(row, e);
8180

src/DataTable/__tests__/DataTable.test.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'jest-styled-components';
22
import React from 'react';
33
import { render, fireEvent } from '@testing-library/react';
44
import DataTable from '../DataTable';
5+
import { STOP_PROP_TAG } from '../constants';
56

67
// eslint-disable-next-line arrow-body-style
78
jest.mock('shortid', () => {
@@ -1021,7 +1022,7 @@ describe('DataTable::expandableRows', () => {
10211022
/>,
10221023
);
10231024

1024-
fireEvent.click(container.querySelector('div[data-tag="___react-data-table-allow-propagation___"]'));
1025+
fireEvent.click(container.querySelector(`div[data-tag="${STOP_PROP_TAG}"]`));
10251026

10261027
expect(container.querySelector('.rdt_ExpanderRow')).toBe(null);
10271028
});
@@ -1037,7 +1038,7 @@ describe('DataTable::expandableRows', () => {
10371038
/>,
10381039
);
10391040

1040-
fireEvent.click(container.querySelector('div[data-tag="___react-data-table-allow-propagation___"]'));
1041+
fireEvent.click(container.querySelector(`div[data-tag="${STOP_PROP_TAG}"]`));
10411042

10421043
expect(container.querySelector('.rdt_ExpanderRow')).not.toBe(null);
10431044
expect(container.firstChild).toMatchSnapshot();
@@ -1053,7 +1054,7 @@ describe('DataTable::expandableRows', () => {
10531054
/>,
10541055
);
10551056

1056-
fireEvent.doubleClick(container.querySelector('div[data-tag="___react-data-table-allow-propagation___"]'));
1057+
fireEvent.click(container.querySelector(`div[data-tag="${STOP_PROP_TAG}"]`));
10571058

10581059
expect(container.querySelector('.rdt_ExpanderRow')).toBe(null);
10591060
});
@@ -1069,7 +1070,7 @@ describe('DataTable::expandableRows', () => {
10691070
/>,
10701071
);
10711072

1072-
fireEvent.doubleClick(container.querySelector('div[data-tag="___react-data-table-allow-propagation___"]'));
1073+
fireEvent.doubleClick(container.querySelector(`div[data-tag="${STOP_PROP_TAG}"]`));
10731074

10741075
expect(container.querySelector('.rdt_ExpanderRow')).not.toBe(null);
10751076
expect(container.firstChild).toMatchSnapshot();
@@ -1088,7 +1089,7 @@ describe('DataTable::expandableRows', () => {
10881089
/>,
10891090
);
10901091

1091-
fireEvent.click(container.querySelector('div[data-tag="___react-data-table-allow-propagation___"]'));
1092+
fireEvent.click(container.querySelector(`div[data-tag="${STOP_PROP_TAG}"]`));
10921093

10931094
expect(container.querySelector('.rdt_ExpanderRow')).toBe(null);
10941095
expect(container.firstChild).toMatchSnapshot();
@@ -1140,7 +1141,8 @@ describe('DataTable::expandableRows', () => {
11401141
/>,
11411142
);
11421143

1143-
fireEvent.click(container.querySelector('div[data-tag="___react-data-table-allow-propagation___"]'));
1144+
fireEvent.click(container.querySelector(`div[data-tag="${STOP_PROP_TAG}"]`));
1145+
11441146
expect(onRowExpandToggledMock).toBeCalled();
11451147
});
11461148

@@ -1157,7 +1159,8 @@ describe('DataTable::expandableRows', () => {
11571159
/>,
11581160
);
11591161

1160-
fireEvent.doubleClick(container.querySelector('div[data-tag="___react-data-table-allow-propagation___"]'));
1162+
fireEvent.doubleClick(container.querySelector(`div[data-tag="${STOP_PROP_TAG}"]`));
1163+
11611164
expect(onRowExpandToggledMock).toBeCalled();
11621165
});
11631166
});
@@ -1448,7 +1451,7 @@ describe('DataTable::selectableRows', () => {
14481451
/>,
14491452
);
14501453

1451-
fireEvent.click(container.querySelector('div[data-tag="___react-data-table-allow-propagation___"]'));
1454+
fireEvent.click(container.querySelector(`div[data-tag="${STOP_PROP_TAG}"]`));
14521455

14531456
expect(rowClickedMock.mock.calls[0][0]).toEqual(mock.data[0]);
14541457
expect(rowClickedMock.mock.calls[0][1]).toBeDefined(); // TODO: mock event?

src/DataTable/__tests__/__snapshots__/DataTable.test.js.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,12 +1274,12 @@ exports[`DataTable::Header should render without a header if noHeader is true 1`
12741274
>
12751275
<div
12761276
class="c10 c6 c11 rdt_TableCell"
1277-
data-tag="___react-data-table-allow-propagation___"
1277+
data-tag="allowRowEvents"
12781278
id="cell-1-1"
12791279
role="gridcell"
12801280
>
12811281
<div
1282-
data-tag="___react-data-table-allow-propagation___"
1282+
data-tag="allowRowEvents"
12831283
>
12841284
Apple
12851285
</div>
@@ -1292,12 +1292,12 @@ exports[`DataTable::Header should render without a header if noHeader is true 1`
12921292
>
12931293
<div
12941294
class="c10 c6 c11 rdt_TableCell"
1295-
data-tag="___react-data-table-allow-propagation___"
1295+
data-tag="allowRowEvents"
12961296
id="cell-1-2"
12971297
role="gridcell"
12981298
>
12991299
<div
1300-
data-tag="___react-data-table-allow-propagation___"
1300+
data-tag="allowRowEvents"
13011301
>
13021302
Zuchinni
13031303
</div>
@@ -2037,12 +2037,12 @@ exports[`DataTable::Pagination should change the page position when using pagina
20372037
>
20382038
<div
20392039
class="c16 c12 c17 rdt_TableCell"
2040-
data-tag="___react-data-table-allow-propagation___"
2040+
data-tag="allowRowEvents"
20412041
id="cell-1-1"
20422042
role="gridcell"
20432043
>
20442044
<div
2045-
data-tag="___react-data-table-allow-propagation___"
2045+
data-tag="allowRowEvents"
20462046
>
20472047
Apple
20482048
</div>

src/DataTable/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const STOP_PROP_TAG = 'allowRowEvents';

0 commit comments

Comments
 (0)