Skip to content

Commit

Permalink
refactor: use onPress event instead (component-wise) (#4354)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
wingkwong authored Dec 17, 2024
1 parent 5946e90 commit fa38828
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 11 deletions.
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
2 changes: 1 addition & 1 deletion packages/components/button/__tests__/button-group.test.tsx
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
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
2 changes: 1 addition & 1 deletion packages/components/dropdown/stories/dropdown.stories.tsx
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
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
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

0 comments on commit fa38828

Please sign in to comment.