Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Joy][Chip] Fix unbinded onClick prop #34455

Merged
merged 5 commits into from Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/mui-joy/src/Chip/Chip.test.js
@@ -1,6 +1,7 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, describeConformance } from 'test/utils';
import { spy } from 'sinon';
import { createRenderer, describeConformance, fireEvent } from 'test/utils';
import { ThemeProvider } from '@mui/joy/styles';
import Chip, { chipClasses as classes } from '@mui/joy/Chip';
import { unstable_capitalize as capitalize } from '@mui/utils';
Expand Down Expand Up @@ -100,6 +101,15 @@ describe('<Chip />', () => {
expect(getByRole('button')).toBeVisible();
});

it('should call onClick', () => {
const handleClick = spy();
const { getByRole } = render(<Chip onClick={handleClick} />);

fireEvent.click(getByRole('button'));

expect(handleClick.callCount).to.equal(1);
});

it('renders action element when `componentsProps.action` is provided', () => {
const { getByRole } = render(<Chip componentsProps={{ action: {} }} />);

Expand Down
4 changes: 2 additions & 2 deletions packages/mui-joy/src/Chip/Chip.tsx
Expand Up @@ -215,7 +215,6 @@ const Chip = React.forwardRef(function Chip(inProps, ref) {
const ownerState: ChipOwnerState = {
...props,
component,
onClick,
disabled,
size,
color,
Expand Down Expand Up @@ -256,6 +255,7 @@ const Chip = React.forwardRef(function Chip(inProps, ref) {
additionalProps: {
'aria-labelledby': id,
as: resolvedActionProps?.component,
onClick,
},
ownerState,
className: classes.action,
Expand Down Expand Up @@ -347,7 +347,7 @@ Chip.propTypes /* remove-proptypes */ = {
*/
endDecorator: PropTypes.node,
/**
* @ignore
* Element action click handler.
*/
onClick: PropTypes.func,
/**
Expand Down
4 changes: 4 additions & 0 deletions packages/mui-joy/src/Chip/ChipProps.ts
Expand Up @@ -46,6 +46,10 @@ export interface ChipTypeMap<P = {}, D extends React.ElementType = 'div'> {
* Element placed after the children.
*/
endDecorator?: React.ReactNode;
/**
* Element action click handler.
*/
onClick?: React.MouseEventHandler<HTMLButtonElement>;
/**
* The size of the component.
* It accepts theme values between 'sm' and 'lg'.
Expand Down