Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

AP-919 Stop propagation of clicks when disabled using input as #122

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Button/Button.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,29 @@ test("when disabled, button does not call click handlers", () => {
expect(rootElementOnClick).not.toHaveBeenCalled();
});

test("when disabled, button with 'as=' set to not a button element does not call click handlers", () => {
const rootElementOnClick = jest.fn();
const asElementOnClick = jest.fn();

const { getByTestId } = render(
<Button
as={<div onClick={asElementOnClick} />}
data-testid="button"
disabled
onClick={rootElementOnClick}
>
submit
</Button>
);

// act
getByTestId("button").click();

// assert
expect(asElementOnClick).not.toHaveBeenCalled();
expect(rootElementOnClick).not.toHaveBeenCalled();
});

test("when loading, button does not call click handlers", () => {
const rootElementOnClick = jest.fn();
const asElementOnClick = jest.fn();
Expand Down
2 changes: 1 addition & 1 deletion src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ export const Button: React.FC<Props> = ({
),
disabled,
onClick: (event: React.MouseEvent<HTMLElement, MouseEvent>) => {
// if (disabled) return event.preventDefault();
if (disabled) return event.preventDefault();

if (otherProps.onClick) {
otherProps.onClick(event);
Expand Down