Skip to content

Commit

Permalink
fix(react): added onClick type to SwitcherItem (#15457)
Browse files Browse the repository at this point in the history
updated author name and email

Co-authored-by: Guilherme Datilio Ribeiro <guilhermedatilio@gmail.com>
  • Loading branch information
amercury and guidari committed Jan 8, 2024
1 parent 963d062 commit 384f35b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Expand Up @@ -1397,6 +1397,15 @@
"contributions": [
"code"
]
},
{
"login": "amercury",
"name": "Alexandr Ovchinnikov",
"avatar_url": "https://avatars.githubusercontent.com/u/17834588?v=4",
"profile": "https://github.com/amercury",
"contributions": [
"code"
]
}
],
"commitConvention": "none"
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -271,6 +271,7 @@ check out our [Contributing Guide](/.github/CONTRIBUTING.md) and our
<td align="center"><a href="https://samuelechinellato.com/#/"><img src="https://avatars.githubusercontent.com/u/49278203?v=4?s=100" width="100px;" alt=""/><br /><sub><b>SamChinellato</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=SamChinellato" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/stevenpatrick009"><img src="https://avatars.githubusercontent.com/u/106097350?v=4?s=100" width="100px;" alt=""/><br /><sub><b>stevenpatrick009</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=stevenpatrick009" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/xalc"><img src="https://avatars.githubusercontent.com/u/18441947?v=4?s=100" width="100px;" alt=""/><br /><sub><b>HunterXalc</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=xalc" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/amercury"><img src="https://avatars.githubusercontent.com/u/17834588?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alexandr Ovchinnikov</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=amercury" title="Code">💻</a></td>
<td align="center"><a href="https://mattborghi.github.io/"><img src="https://avatars.githubusercontent.com/u/11933424?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Matias Borghi</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=mattborghi" title="Code">💻</a></td>
</tr>
</table>
Expand Down
3 changes: 3 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Expand Up @@ -7379,6 +7379,9 @@ Map {
"index": Object {
"type": "number",
},
"onClick": Object {
"type": "func",
},
"onKeyDown": Object {
"type": "func",
},
Expand Down
8 changes: 8 additions & 0 deletions packages/react/src/components/UIShell/SwitcherItem.tsx
Expand Up @@ -30,6 +30,10 @@ interface BaseSwitcherItemProps {
* event handlers
*/
onKeyDown?: (event: KeyboardEvent) => void;
/**
* event handlers
*/
onClick?: (event: MouseEvent) => void;
/**
* Specify the tab index of the Link
*/
Expand Down Expand Up @@ -143,6 +147,10 @@ SwitcherItem.propTypes = {
* Specify the index of the SwitcherItem
*/
index: PropTypes.number,
/**
* event handlers
*/
onClick: PropTypes.func,
/**
* event handlers
*/
Expand Down
Expand Up @@ -7,7 +7,7 @@

import React from 'react';
import SwitcherItem from '../SwitcherItem';
import { render, screen } from '@testing-library/react';
import { render, screen, fireEvent } from '@testing-library/react';

describe('SwitcherItem', () => {
describe('renders as expected - Component API', () => {
Expand Down Expand Up @@ -78,5 +78,19 @@ describe('SwitcherItem', () => {
'-1'
);
});

it('should handle onClick event', () => {
const dummyHandler = jest.fn();

render(
<SwitcherItem aria-label="dummy-aria-label" onClick={dummyHandler}>
Dummy child
</SwitcherItem>
);

fireEvent.click(screen.getByRole('listitem').firstChild);

expect(dummyHandler).toHaveBeenCalledTimes(1);
});
});
});

0 comments on commit 384f35b

Please sign in to comment.