mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
fix(listbox): pass missing press events to usePress (#4812)
* fix(listbox): pass missing press events to usePress * feat(listbox): add test case for press event * chore(changeset): add changeset
This commit is contained in:
parent
8dc5aaa3ca
commit
b2e7e04e89
5
.changeset/nine-ties-bake.md
Normal file
5
.changeset/nine-ties-bake.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@heroui/listbox": patch
|
||||
---
|
||||
|
||||
pass missing press events to usePress (#4798)
|
||||
@ -299,4 +299,48 @@ describe("Listbox", () => {
|
||||
|
||||
expect(menuItem).not.toHaveProperty("className", expect.stringContaining("truncate"));
|
||||
});
|
||||
|
||||
it("should trigger press events", async () => {
|
||||
const onPress = jest.fn();
|
||||
const onPressStart = jest.fn();
|
||||
const onPressEnd = jest.fn();
|
||||
const onPressUp = jest.fn();
|
||||
const onPressChange = jest.fn();
|
||||
|
||||
const {getAllByRole} = render(
|
||||
<Listbox aria-label="Actions">
|
||||
<ListboxItem
|
||||
key="new"
|
||||
onPress={onPress}
|
||||
onPressChange={onPressChange}
|
||||
onPressEnd={onPressEnd}
|
||||
onPressStart={onPressStart}
|
||||
onPressUp={onPressUp}
|
||||
>
|
||||
New file
|
||||
</ListboxItem>
|
||||
<ListboxItem key="copy">Copy link</ListboxItem>
|
||||
<ListboxItem key="edit">Edit file</ListboxItem>
|
||||
<ListboxItem key="delete" color="danger">
|
||||
Delete file
|
||||
</ListboxItem>
|
||||
</Listbox>,
|
||||
);
|
||||
|
||||
let listboxItems = getAllByRole("option");
|
||||
|
||||
expect(listboxItems.length).toBe(4);
|
||||
|
||||
await user.click(listboxItems[0]);
|
||||
|
||||
expect(onPress).toHaveBeenCalled();
|
||||
|
||||
expect(onPressStart).toHaveBeenCalled();
|
||||
|
||||
expect(onPressEnd).toHaveBeenCalled();
|
||||
|
||||
expect(onPressUp).toHaveBeenCalled();
|
||||
|
||||
expect(onPressChange).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@ -41,6 +41,10 @@ export function useListboxItem<T extends object>(originalProps: UseListboxItemPr
|
||||
classNames,
|
||||
autoFocus,
|
||||
onPress,
|
||||
onPressUp,
|
||||
onPressStart,
|
||||
onPressEnd,
|
||||
onPressChange,
|
||||
onClick: deprecatedOnClick,
|
||||
shouldHighlightOnFocus,
|
||||
hideSelectedIcon = false,
|
||||
@ -74,6 +78,10 @@ export function useListboxItem<T extends object>(originalProps: UseListboxItemPr
|
||||
ref: domRef,
|
||||
isDisabled: isDisabled,
|
||||
onPress,
|
||||
onPressUp,
|
||||
onPressStart,
|
||||
onPressEnd,
|
||||
onPressChange,
|
||||
});
|
||||
|
||||
const {isHovered, hoverProps} = useHover({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user