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

Change useMenuTrigger onPressStart to state.open #6024

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
2 changes: 1 addition & 1 deletion packages/@react-aria/menu/src/useMenuTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function useMenuTrigger<T>(props: AriaMenuTriggerProps, state: MenuTrigge
if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard' && !isDisabled) {
// If opened with a screen reader, auto focus the first item.
// Otherwise, the menu itself will be focused.
state.toggle(e.pointerType === 'virtual' ? 'first' : null);
state.open(e.pointerType === 'virtual' ? 'first' : null);
}
},
onPress(e) {
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/menu/test/useMenuTrigger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ describe('useMenuTrigger', function () {
beforeEach(() => {
state.isOpen = false;
state.setOpen = setOpen;
state.toggle = (focusStrategy) => {
state.open = (focusStrategy) => {
state.setFocusStrategy(focusStrategy);
state.setOpen(!state.isOpen);
state.setOpen(true);
};
state.focusStrategy = 'first';
state.setFocusStrategy = setFocusStrategy;
Expand Down
15 changes: 15 additions & 0 deletions packages/@react-spectrum/menu/test/MenuTrigger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ describe('MenuTrigger', function () {
verifyMenuToggle(Component, props, {}, (button) => triggerPress(button));
});

it.each`
Name | Component | props
${'MenuTrigger'} | ${MenuTrigger} | ${{onOpenChange}}
`('$Name will not close the menu when mousing over the trigger again without lifting press', function ({Component, props}) {
let tree = renderComponent(Component, props, {});
let triggerButton = tree.getByRole('button');
fireEvent.mouseEnter(triggerButton);
fireEvent.mouseDown(triggerButton, {detail: 1});
fireEvent.mouseLeave(triggerButton);
fireEvent.mouseEnter(triggerButton);
fireEvent.mouseUp(triggerButton, {detail: 1});

expect(onOpenChange).toBeCalledTimes(1);
});

// Enter and Space keypress tests are ommitted since useMenuTrigger doesn't have space and enter cases in it's key down
// since usePress handles those cases

Expand Down