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

refactor: use onPress event instead (component-wise) #4354

Merged
merged 7 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/two-ghosts-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/alert": patch
---

replace decrepate onClick in Alert
2 changes: 1 addition & 1 deletion packages/components/alert/src/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const Alert = forwardRef<"div", AlertProps>((props, ref) => {
aria-label="Close"
radius="full"
variant="light"
onClick={handleClose}
onPress={handleClose}
{...(getCloseButtonProps() as ButtonProps)}
>
<CloseIcon height={20} width={20} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("ButtonGroup", () => {
const handler = jest.fn();
const wrapper = render(
<ButtonGroup isDisabled={true}>
<Button disableRipple data-testid="button-test" onClick={handler}>
<Button disableRipple data-testid="button-test" onPress={handler}>
action
</Button>
</ButtonGroup>,
Expand Down
8 changes: 4 additions & 4 deletions packages/components/button/__tests__/button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ describe("Button", () => {
expect(onPress).toHaveBeenCalled();
});

it("should trigger onClick function", async () => {
const onClick = jest.fn();
const {getByRole} = render(<Button disableRipple onClick={onClick} />);
it("should trigger onPress function", async () => {
const onPress = jest.fn();
const {getByRole} = render(<Button disableRipple onPress={onPress} />);

const button = getByRole("button");

await user.click(button);

expect(onClick).toHaveBeenCalled();
expect(onPress).toHaveBeenCalled();
wingkwong marked this conversation as resolved.
Show resolved Hide resolved
});

it("should ignore events when disabled", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/button/stories/button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const StateTemplate = (args: ButtonProps) => {
{...args}
aria-label={isOpen ? "Close" : "Open"}
aria-pressed={isOpen}
onClick={handlePress}
onPress={handlePress}
>
{isOpen ? "Close" : "Open"}
</Button>
Expand Down
8 changes: 4 additions & 4 deletions packages/components/card/__tests__/card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ describe("Card", () => {
expect(onPress).toHaveBeenCalled();
});

it("should trigger onClick function", async () => {
const onClick = jest.fn();
const {getByRole} = render(<Card disableRipple isPressable onClick={onClick} />);
it("should trigger onPress function", async () => {
const onPress = jest.fn();
const {getByRole} = render(<Card disableRipple isPressable onPress={onPress} />);

const button = getByRole("button");

await user.click(button);

expect(onClick).toHaveBeenCalled();
expect(onPress).toHaveBeenCalled();
});

it("should render correctly when nested", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const Template = ({
<Button>{label}</Button>
</DropdownTrigger>
<DropdownMenu aria-label="Actions" color={color} variant={variant}>
<DropdownItem key="new" onClick={() => alert("New file")}>
<DropdownItem key="new" onPress={() => alert("New file")}>
New file
</DropdownItem>
<DropdownItem key="copy">Copy link</DropdownItem>
Expand Down
8 changes: 4 additions & 4 deletions packages/components/link/__tests__/link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ describe("Link", () => {
expect(onPress).toHaveBeenCalled();
});

it("should trigger onClick function", async () => {
const onClick = jest.fn();
const {getByRole} = render(<Link onClick={onClick} />);
it("should trigger onPress function", async () => {
const onPress = jest.fn();
const {getByRole} = render(<Link onPress={onPress} />);

const link = getByRole("link");

await user.click(link);

expect(onClick).toHaveBeenCalled();
expect(onPress).toHaveBeenCalled();
wingkwong marked this conversation as resolved.
Show resolved Hide resolved
});

it('should have target="_blank" and rel="noopener noreferrer" when "isExternal" is true', () => {
wingkwong marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion packages/components/link/stories/link.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const PressableTemplate = (args: LinkProps) => {
};

return (
<Link {...args} onClick={handlePress}>
<Link {...args} onPress={handlePress}>
{isOpen ? "Open" : "Close"}
</Link>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/components/listbox/stories/listbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const Template = ({color, variant, ...args}: ListboxProps) => (
onAction={(key: Key) => alert(key)}
{...args}
>
<ListboxItem key="new" onClick={() => alert("[onClick] New file")}>
<ListboxItem key="new" onPress={() => alert("[onPress] New file")}>
New file
</ListboxItem>
<ListboxItem key="copy">Copy link</ListboxItem>
Expand Down
6 changes: 2 additions & 4 deletions packages/components/menu/__tests__/menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,13 @@ describe("Menu", () => {
expect(onAction).toHaveBeenCalledTimes(0);
});

it("should dispatch onPress, onAction and onClick events", async () => {
it("should dispatch onPress, onAction", async () => {
let onPress = jest.fn();
let onClick = jest.fn();
let onAction = jest.fn();

const wrapper = render(
<Menu aria-label="Actions" onAction={onAction}>
<MenuItem key="new" onClick={onClick} onPress={onPress}>
<MenuItem key="new" onPress={onPress}>
New file
</MenuItem>
<MenuItem key="copy">Copy link</MenuItem>
Expand All @@ -341,7 +340,6 @@ describe("Menu", () => {

expect(onAction).toHaveBeenCalledTimes(1);
expect(onPress).toHaveBeenCalledTimes(1);
expect(onClick).toHaveBeenCalledTimes(1);
});

it("should menuItem classNames work", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/menu/stories/menu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const defaultProps = {

const Template = ({color, variant, ...args}: MenuProps) => (
<Menu aria-label="Actions" color={color} variant={variant} onAction={alert} {...args}>
<MenuItem key="new" onClick={() => alert("[onClick] New file")}>
<MenuItem key="new" onPress={() => alert("[onPress] New file")}>
New file
</MenuItem>
<MenuItem key="copy">Copy link</MenuItem>
Expand Down
Loading