Skip to content

Commit fc63ace

Browse files
authored
Add data-cy prop (#3643)
* Add `aria-description` * Add support for specifying data attributes * Merge conflict * Rest props are not safe * Update test
1 parent 071dd8f commit fc63ace

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/DataGrid.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export interface DataGridProps<R, SR = unknown, K extends Key = Key> extends Sha
205205
/** @default 'ltr' */
206206
direction?: Maybe<Direction>;
207207
'data-testid'?: Maybe<string>;
208+
'data-cy'?: Maybe<string>;
208209
}
209210

210211
/**
@@ -264,7 +265,8 @@ function DataGrid<R, SR, K extends Key>(
264265
'aria-description': ariaDescription,
265266
'aria-describedby': ariaDescribedBy,
266267
'aria-rowcount': rawAriaRowCount,
267-
'data-testid': testId
268+
'data-testid': testId,
269+
'data-cy': dataCy
268270
} = props;
269271

270272
/**
@@ -1122,6 +1124,7 @@ function DataGrid<R, SR, K extends Key>(
11221124
onScroll={handleScroll}
11231125
onKeyDown={handleKeyDown}
11241126
data-testid={testId}
1127+
data-cy={dataCy}
11251128
>
11261129
<DataGridDefaultRenderersProvider value={defaultGridComponents}>
11271130
<HeaderRowSelectionChangeProvider value={selectHeaderRowLatest}>

test/browser/label.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ test('should set label and description', () => {
77
'aria-label': 'label',
88
'aria-labelledby': 'labelledby',
99
'aria-description': 'description',
10-
'aria-describedby': 'describedby'
10+
'aria-describedby': 'describedby',
11+
'data-testid': 'testid',
12+
'data-cy': 'cy'
1113
});
1214

1315
const grid = getGrid().element();
1416
expect(grid).toHaveAttribute('aria-label', 'label');
1517
expect(grid).toHaveAttribute('aria-labelledby', 'labelledby');
1618
expect(grid).toHaveAttribute('aria-description', 'description');
1719
expect(grid).toHaveAttribute('aria-describedby', 'describedby');
20+
expect(grid).toHaveAttribute('data-testid', 'testid');
21+
expect(grid).toHaveAttribute('data-cy', 'cy');
1822
});

0 commit comments

Comments
 (0)