Skip to content

Commit 078a64a

Browse files
authored
fix(DataTable): rowHeight xLarge => xlarge (#368)
* fix(DataTable): Update rowHeight prop value from xLarge => xlarge * fix(DataTable): clear timeout on unmount * fix(DataTable): use existing timeout if it exists, don't create a new one
1 parent 7f4980a commit 078a64a

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

packages/core/src/components/DataTable/DataTable.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,20 @@ export class DataTable extends React.Component<DataTableProps & WithStylesProps,
141141
});
142142
} else if (dynamicRowHeight && (filteredDataChanged || dimensionsChanged || sortChanged)) {
143143
// We need to make sure the cache is cleared before React tries to re-render.
144-
if (this.timeoutId) window.clearTimeout(this.timeoutId);
145-
this.timeoutId = window.setTimeout(() => {
146-
this.cache.clearAll();
147-
this.forceUpdate();
148-
});
144+
if (!this.timeoutId) {
145+
this.timeoutId = window.setTimeout(() => {
146+
this.cache.clearAll();
147+
this.forceUpdate();
148+
this.timeoutId = 0;
149+
});
150+
}
149151
}
150152
}
151153

154+
componentWillUnmount() {
155+
if (this.timeoutId) window.clearTimeout(this.timeoutId);
156+
}
157+
152158
private getTableHeight = (expandedDataList: ExpandedRow[]): number => {
153159
const { height, rowHeight, showAllRows, dynamicRowHeight } = this.props;
154160
// @ts-ignore _rowHeightCache is missing from DataTable types
@@ -222,11 +228,13 @@ export class DataTable extends React.Component<DataTableProps & WithStylesProps,
222228

223229
if (dynamicRowHeight) {
224230
// We need to make sure the cache is cleared before React tries to re-render.
225-
if (this.timeoutId) window.clearTimeout(this.timeoutId);
226-
this.timeoutId = window.setTimeout(() => {
227-
this.cache.clearAll();
228-
this.forceUpdate();
229-
});
231+
if (!this.timeoutId) {
232+
this.timeoutId = window.setTimeout(() => {
233+
this.cache.clearAll();
234+
this.forceUpdate();
235+
this.timeoutId = 0;
236+
});
237+
}
230238
}
231239
};
232240

packages/core/src/components/DataTable/constants.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const HEIGHT_TO_PX: HeightMap = {
2121
small: 48,
2222
regular: 56,
2323
large: 64,
24-
xLarge: 80,
24+
xlarge: 80,
2525
jumbo: 108,
2626
};
2727

packages/core/src/components/DataTable/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DataTable } from './DataTable';
55

66
export type DataTableRef = (instance: DataTable) => void;
77
export type TableRef = React.RefObject<Table>;
8-
export type RowHeightOptions = 'micro' | 'small' | 'regular' | 'large' | 'xLarge' | 'jumbo';
8+
export type RowHeightOptions = 'micro' | 'small' | 'regular' | 'large' | 'xlarge' | 'jumbo';
99
export type HeightOptions = RowHeightOptions | undefined;
1010
export type ColumnLabelCase = 'sentence' | 'title' | 'uppercase' | '';
1111

0 commit comments

Comments
 (0)