Skip to content

Commit

Permalink
fix(menu): prevents defaultFocusedValue from focusing items on trig…
Browse files Browse the repository at this point in the history
…ger click (#660)
  • Loading branch information
geotrev committed Sep 12, 2024
1 parent 482fbf0 commit ec77a9d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/menu/src/MenuContainer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,20 @@ describe('MenuContainer', () => {
expect(firstItem).toHaveFocus();
});

it('does not focus default value on click', async () => {
const { getByTestId, getByText } = render(
<TestMenu items={ITEMS} defaultFocusedValue="plant-04" />
);
const trigger = getByTestId('trigger');
const item = getByText('Succulent');

await act(async () => {
await user.click(trigger);
});

expect(item).not.toHaveFocus();
});

it('focuses defaultFocusedValue on ArrowDown keydown', async () => {
const { getByText, getByTestId } = render(
<TestMenu items={ITEMS} defaultFocusedValue="plant-04" />
Expand Down
2 changes: 1 addition & 1 deletion packages/menu/src/useMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const useMenu = <T extends HTMLElement = HTMLElement, M extends HTMLEleme
const focusTriggerRef = useRef<boolean>(false);

const [state, dispatch] = useReducer(stateReducer, {
focusedValue: focusedValue || defaultFocusedValue,
focusedValue,
isExpanded: isExpanded || defaultExpanded,
selectedItems: initialSelectedItems,
valuesRef: values,
Expand Down

0 comments on commit ec77a9d

Please sign in to comment.