Skip to content

Commit

Permalink
Add data-cy prop (#3643)
Browse files Browse the repository at this point in the history
* Add `aria-description`

* Add support for specifying data attributes

* Merge conflict

* Rest props are not safe

* Update test
  • Loading branch information
amanmahajan7 authored Jan 7, 2025
1 parent 071dd8f commit fc63ace
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export interface DataGridProps<R, SR = unknown, K extends Key = Key> extends Sha
/** @default 'ltr' */
direction?: Maybe<Direction>;
'data-testid'?: Maybe<string>;
'data-cy'?: Maybe<string>;
}

/**
Expand Down Expand Up @@ -264,7 +265,8 @@ function DataGrid<R, SR, K extends Key>(
'aria-description': ariaDescription,
'aria-describedby': ariaDescribedBy,
'aria-rowcount': rawAriaRowCount,
'data-testid': testId
'data-testid': testId,
'data-cy': dataCy
} = props;

/**
Expand Down Expand Up @@ -1122,6 +1124,7 @@ function DataGrid<R, SR, K extends Key>(
onScroll={handleScroll}
onKeyDown={handleKeyDown}
data-testid={testId}
data-cy={dataCy}
>
<DataGridDefaultRenderersProvider value={defaultGridComponents}>
<HeaderRowSelectionChangeProvider value={selectHeaderRowLatest}>
Expand Down
6 changes: 5 additions & 1 deletion test/browser/label.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ test('should set label and description', () => {
'aria-label': 'label',
'aria-labelledby': 'labelledby',
'aria-description': 'description',
'aria-describedby': 'describedby'
'aria-describedby': 'describedby',
'data-testid': 'testid',
'data-cy': 'cy'
});

const grid = getGrid().element();
expect(grid).toHaveAttribute('aria-label', 'label');
expect(grid).toHaveAttribute('aria-labelledby', 'labelledby');
expect(grid).toHaveAttribute('aria-description', 'description');
expect(grid).toHaveAttribute('aria-describedby', 'describedby');
expect(grid).toHaveAttribute('data-testid', 'testid');
expect(grid).toHaveAttribute('data-cy', 'cy');
});

0 comments on commit fc63ace

Please sign in to comment.