@@ -10,15 +10,17 @@ type SuggestionItemProps = {
10
10
usersListboxId : string ;
11
11
highlighted : boolean ;
12
12
mentionMode : MentionMode ;
13
- onSelectUser : ( user : UserItem ) => void ;
13
+ onSelect : ( ) => void ;
14
+ onHighlight : ( ) => void ;
14
15
} ;
15
16
16
17
function SuggestionItem ( {
17
18
user,
18
19
usersListboxId,
19
20
highlighted,
20
21
mentionMode,
21
- onSelectUser,
22
+ onSelect,
23
+ onHighlight,
22
24
} : SuggestionItemProps ) {
23
25
const showUsername = mentionMode === 'username' ;
24
26
@@ -31,8 +33,7 @@ function SuggestionItem({
31
33
key = { user . username }
32
34
id = { `${ usersListboxId } -${ user . username } ` }
33
35
className = { classnames (
34
- 'flex justify-between items-center gap-x-2' ,
35
- 'rounded p-2 hover:bg-grey-2' ,
36
+ 'flex justify-between items-center gap-x-2 rounded p-2' ,
36
37
// Adjust line height relative to the font size. This avoids
37
38
// vertically cropped usernames due to the use of `truncate`.
38
39
'leading-tight' ,
@@ -42,8 +43,13 @@ function SuggestionItem({
42
43
) }
43
44
onClick = { e => {
44
45
e . stopPropagation ( ) ;
45
- onSelectUser ( user ) ;
46
+ onSelect ( ) ;
46
47
} }
48
+ // Using onMouseMove instead of onMouseEnter, so that if the mouse is
49
+ // already hovering this item, and then we change the highlighted
50
+ // suggestion via arrow keys, when the mouse is moved again, this item
51
+ // becomes highlighted without having to first leave it and enter again.
52
+ onMouseMove = { onHighlight }
47
53
role = "option"
48
54
aria-selected = { highlighted }
49
55
>
@@ -69,6 +75,8 @@ export type MentionSuggestionsPopoverProps = Pick<
69
75
users : UserItem [ ] ;
70
76
/** Index for currently highlighted suggestion */
71
77
highlightedSuggestion : number ;
78
+ /** Invoked when currently highlighted suggestion index is changed */
79
+ onHighlightSuggestion : ( index : number ) => void ;
72
80
/** Invoked when a user is selected */
73
81
onSelectUser : ( selectedSuggestion : UserItem ) => void ;
74
82
/** Element ID for the user suggestions listbox */
@@ -85,6 +93,7 @@ export default function MentionSuggestionsPopover({
85
93
users,
86
94
onSelectUser,
87
95
highlightedSuggestion,
96
+ onHighlightSuggestion,
88
97
usersListboxId,
89
98
mentionMode,
90
99
...popoverProps
@@ -113,7 +122,8 @@ export default function MentionSuggestionsPopover({
113
122
highlighted = { highlightedSuggestion === index }
114
123
mentionMode = { mentionMode }
115
124
usersListboxId = { usersListboxId }
116
- onSelectUser = { onSelectUser }
125
+ onSelect = { ( ) => onSelectUser ( u ) }
126
+ onHighlight = { ( ) => onHighlightSuggestion ( index ) }
117
127
/>
118
128
) ) }
119
129
{ users . length === 0 && (
0 commit comments