Skip to content

Commit 757b993

Browse files
committed
Only show a single selected/active state in search result list
1 parent c4ac206 commit 757b993

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/Search/SearchResults/SearchResultsListItem.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ export function SearchResultListItem({
107107
role="option"
108108
aria-selected={isSelected}
109109
onClick={handleClick}
110+
onMouseEnter={(e) => {
111+
// If another result item has focus, move focus to this item
112+
if (document.activeElement instanceof HTMLElement) {
113+
const isResultItem = document.activeElement.closest(
114+
'[data-search-results]'
115+
)
116+
if (
117+
isResultItem &&
118+
document.activeElement !== e.currentTarget
119+
) {
120+
e.currentTarget.focus()
121+
}
122+
}
123+
onSelect?.(index)
124+
}}
110125
onFocus={() => onSelect?.(index)}
111126
onKeyDown={(e) => onKeyDown?.(e, index)}
112127
css={css`
@@ -126,23 +141,15 @@ export function SearchResultListItem({
126141
outline: none;
127142
outline-color: transparent;
128143
129-
/* Highlight styles for selected and hovered items */
130-
&[data-selected],
131-
&:hover {
144+
/* Selected: background + border (hover updates selection via onMouseEnter) */
145+
&[data-selected] {
132146
background-color: ${euiTheme.colors
133147
.backgroundBaseHighlighted};
134148
border-color: ${euiTheme.colors.borderBasePlain};
135-
}
136149
137-
/* Return key icon only shows for selected item */
138-
&[data-selected] .return-key-icon {
139-
visibility: visible;
140-
}
141-
142-
/* Icons turn blue when selected */
143-
&[data-selected] .result-type-icon,
144-
&[data-selected] .return-key-icon {
145-
color: ${euiTheme.colors.primaryText};
150+
.return-key-icon {
151+
visibility: visible;
152+
}
146153
}
147154
148155
/* Focus ring for selected and focus states */

0 commit comments

Comments
 (0)