Skip to content

Commit 1355ef2

Browse files
committed
fix(Menu): focused state
1 parent b146fba commit 1355ef2

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.changeset/silly-tools-tease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Fix focused state styles on Menu items.

src/components/pickers/Menu/MenuButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const StyledButton = tasty(Block, {
1717
border: {
1818
'': '#clear',
1919
pressed: '#clear',
20-
'focused & !hovered': '#purple-text',
20+
focused: '#purple-text',
2121
},
2222
fill: {
2323
'': '#clear',

src/components/pickers/Menu/MenuItem.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Key, Node } from '@react-types/shared';
22
import { useRef } from 'react';
3-
import { FocusRing, useHover, useMenuItem } from 'react-aria';
3+
import { FocusRing, useFocusVisible, useHover, useMenuItem } from 'react-aria';
44
import { TreeState } from 'react-stately';
55

66
import { Styles } from '../../../tasty';
@@ -32,6 +32,9 @@ export function MenuItem<T>(props: MenuItemProps<T>) {
3232
const ref = useRef<HTMLLIElement>(null);
3333
const { hoverProps, isHovered } = useHover({ isDisabled: isDisabledKey });
3434

35+
// Determine if focus should be shown (keyboard modality only)
36+
const { isFocusVisible } = useFocusVisible({});
37+
3538
const {
3639
menuItemProps,
3740
labelProps,
@@ -56,12 +59,15 @@ export function MenuItem<T>(props: MenuItemProps<T>) {
5659
ref,
5760
);
5861

62+
// Show focused state only when focus is keyboard-visible
63+
const isKeyboardFocused = isFocused && isFocusVisible;
64+
5965
const buttonProps = {
6066
qa: itemProps.qa ? itemProps.qa : `MenuButton-${key}`,
6167
mods: {
6268
...itemProps.mods,
6369
hovered: isHovered,
64-
focused: isFocused,
70+
focused: isKeyboardFocused,
6571
pressed: isPressed,
6672
},
6773
};
@@ -90,7 +96,7 @@ export function MenuItem<T>(props: MenuItemProps<T>) {
9096
selected: isSelected,
9197
selectable: isSelectable,
9298
hovered: isHovered,
93-
focused: isFocused,
99+
focused: isKeyboardFocused,
94100
}}
95101
>
96102
<ClearSlots>

0 commit comments

Comments
 (0)