Skip to content

Commit ec77a9d

Browse files
authored
fix(menu): prevents defaultFocusedValue from focusing items on trigger click (#660)
1 parent 482fbf0 commit ec77a9d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/menu/src/MenuContainer.spec.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,20 @@ describe('MenuContainer', () => {
280280
expect(firstItem).toHaveFocus();
281281
});
282282

283+
it('does not focus default value on click', async () => {
284+
const { getByTestId, getByText } = render(
285+
<TestMenu items={ITEMS} defaultFocusedValue="plant-04" />
286+
);
287+
const trigger = getByTestId('trigger');
288+
const item = getByText('Succulent');
289+
290+
await act(async () => {
291+
await user.click(trigger);
292+
});
293+
294+
expect(item).not.toHaveFocus();
295+
});
296+
283297
it('focuses defaultFocusedValue on ArrowDown keydown', async () => {
284298
const { getByText, getByTestId } = render(
285299
<TestMenu items={ITEMS} defaultFocusedValue="plant-04" />

packages/menu/src/useMenu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const useMenu = <T extends HTMLElement = HTMLElement, M extends HTMLEleme
9797
const focusTriggerRef = useRef<boolean>(false);
9898

9999
const [state, dispatch] = useReducer(stateReducer, {
100-
focusedValue: focusedValue || defaultFocusedValue,
100+
focusedValue,
101101
isExpanded: isExpanded || defaultExpanded,
102102
selectedItems: initialSelectedItems,
103103
valuesRef: values,

0 commit comments

Comments
 (0)