Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit 62757b1

Browse files
Merge pull request #819 from intellihr/INT-12161-minor-gridlayout-fixes
[INT-12161] Remove unusable key prop and fix GridChild typing in gridlayout
2 parents f9f44f1 + 975435d commit 62757b1

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

src/domain/Layouts/GridLayout/GridLayout.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
CellSize,
66
GutterSize,
77
HorizontalAlignment,
8-
IStyledCellProps,
98
StyledCell,
109
StyledGridLayout,
1110
VerticalAlignment
@@ -53,11 +52,6 @@ interface IVerticalAlignmentDefinition {
5352
}
5453

5554
interface IGridLayoutCell {
56-
/**
57-
* Key for the cell. This is important for animations, as cells with the same key will be kept unanimated
58-
* when transitioning. Defaults to the index of the cell.
59-
*/
60-
key?: string | number
6155
/** The content to place within the cell */
6256
content?: JSX.Element | string | null
6357
/** The size this cell takes up within the grid */
@@ -103,10 +97,11 @@ type GridChild =
10397
| false
10498
| null
10599
| undefined
100+
| GridChild[]
106101

107102
interface IGridLayoutPropsWithChildren extends IGridLayoutBaseProps {
108103
/** The cell components to place within the grid */
109-
children: GridChild[] | GridChild
104+
children: GridChild
110105
}
111106

112107
type GridLayoutProps = IGridLayoutPropsWithCells | IGridLayoutPropsWithChildren
@@ -144,16 +139,18 @@ export class GridLayout extends React.PureComponent<GridLayoutProps, never> {
144139
if ('cells' in this.props) {
145140
renderChildren = this.props.cells && this.props.cells.map(this.getCellForDefinition)
146141
} else if (this.props.children) {
147-
renderChildren = React.Children.map<
148-
React.ReactElement | false | null | undefined,
149-
GridChild
150-
>(this.props.children, (child) => {
142+
renderChildren = React.Children.map(this.props.children, (child) => {
151143
if (!child) {
152144
return child
153145
}
154146

147+
// This can never happen, as React.children expands out child arrays automatically
148+
// Kept because otherwise typescript complains (typing of .map isn't great)
149+
if (Array.isArray(child)) {
150+
return null
151+
}
152+
155153
const {
156-
key,
157154
size,
158155
offset,
159156
flexHorizontalAlignment,
@@ -162,7 +159,6 @@ export class GridLayout extends React.PureComponent<GridLayoutProps, never> {
162159

163160
return (
164161
React.cloneElement(child, {
165-
key,
166162
size,
167163
offset,
168164
displayType,
@@ -205,7 +201,6 @@ export class GridLayout extends React.PureComponent<GridLayoutProps, never> {
205201
} = this.props
206202

207203
const {
208-
key,
209204
content,
210205
size,
211206
displayType,
@@ -216,7 +211,7 @@ export class GridLayout extends React.PureComponent<GridLayoutProps, never> {
216211

217212
return (
218213
<StyledCell
219-
key={key || index}
214+
key={index}
220215
size={size || 'auto'}
221216
offset={offset || 0}
222217
gridColumns={gridColumns!}

src/domain/Layouts/GridLayout/subcomponents/Cell.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
type CellDisplayType = 'block' | 'flex'
1717

1818
interface ICellProps {
19-
key?: string | number
2019
gridColumns?: number
2120
size?: CellSize | IStyledCellSizes
2221
offset?: CellOffset | IStyledCellOffsets

0 commit comments

Comments
 (0)