Skip to content

Commit fa38828

Browse files
authored
refactor: use onPress event instead (component-wise) (#4354)
* refactor: use onPress event instead * chore(changeset): add changeset * refactor(button): remove duplicate test case * refactor(link): remove duplicate test case * chore: add back onClick test case * chore(menu): keep onClick test case * chore: keep the original order
1 parent 5946e90 commit fa38828

File tree

9 files changed

+16
-11
lines changed

9 files changed

+16
-11
lines changed

.changeset/two-ghosts-search.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nextui-org/alert": patch
3+
---
4+
5+
replace decrepate onClick in Alert

packages/components/alert/src/alert.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const Alert = forwardRef<"div", AlertProps>((props, ref) => {
7373
aria-label="Close"
7474
radius="full"
7575
variant="light"
76-
onClick={handleClose}
76+
onPress={handleClose}
7777
{...(getCloseButtonProps() as ButtonProps)}
7878
>
7979
<CloseIcon height={20} width={20} />

packages/components/button/__tests__/button-group.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("ButtonGroup", () => {
2626
const handler = jest.fn();
2727
const wrapper = render(
2828
<ButtonGroup isDisabled={true}>
29-
<Button disableRipple data-testid="button-test" onClick={handler}>
29+
<Button disableRipple data-testid="button-test" onPress={handler}>
3030
action
3131
</Button>
3232
</ButtonGroup>,

packages/components/button/stories/button.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const StateTemplate = (args: ButtonProps) => {
8282
{...args}
8383
aria-label={isOpen ? "Close" : "Open"}
8484
aria-pressed={isOpen}
85-
onClick={handlePress}
85+
onPress={handlePress}
8686
>
8787
{isOpen ? "Close" : "Open"}
8888
</Button>

packages/components/card/__tests__/card.test.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ describe("Card", () => {
4141
expect(onPress).toHaveBeenCalled();
4242
});
4343

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

4848
const button = getByRole("button");
4949

5050
await user.click(button);
5151

52-
expect(onClick).toHaveBeenCalled();
52+
expect(onPress).toHaveBeenCalled();
5353
});
5454

5555
it("should render correctly when nested", () => {

packages/components/dropdown/stories/dropdown.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const Template = ({
148148
<Button>{label}</Button>
149149
</DropdownTrigger>
150150
<DropdownMenu aria-label="Actions" color={color} variant={variant}>
151-
<DropdownItem key="new" onClick={() => alert("New file")}>
151+
<DropdownItem key="new" onPress={() => alert("New file")}>
152152
New file
153153
</DropdownItem>
154154
<DropdownItem key="copy">Copy link</DropdownItem>

packages/components/link/stories/link.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const PressableTemplate = (args: LinkProps) => {
5858
};
5959

6060
return (
61-
<Link {...args} onClick={handlePress}>
61+
<Link {...args} onPress={handlePress}>
6262
{isOpen ? "Open" : "Close"}
6363
</Link>
6464
);

packages/components/listbox/stories/listbox.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ const Template = ({color, variant, ...args}: ListboxProps) => (
174174
onAction={(key: Key) => alert(key)}
175175
{...args}
176176
>
177-
<ListboxItem key="new" onClick={() => alert("[onClick] New file")}>
177+
<ListboxItem key="new" onPress={() => alert("[onPress] New file")}>
178178
New file
179179
</ListboxItem>
180180
<ListboxItem key="copy">Copy link</ListboxItem>

packages/components/menu/stories/menu.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const defaultProps = {
4545

4646
const Template = ({color, variant, ...args}: MenuProps) => (
4747
<Menu aria-label="Actions" color={color} variant={variant} onAction={alert} {...args}>
48-
<MenuItem key="new" onClick={() => alert("[onClick] New file")}>
48+
<MenuItem key="new" onPress={() => alert("[onPress] New file")}>
4949
New file
5050
</MenuItem>
5151
<MenuItem key="copy">Copy link</MenuItem>

0 commit comments

Comments
 (0)