Skip to content

Commit 9b9dc89

Browse files
nsdeschenesclaude
andcommitted
fix(metrics): Prevent metric selector hover from stealing search input focus
When hovering over options in the metric selector listbox, setFocused(true) was triggering a useEffect in useSelectableItem that called focusSafely(ref.current), stealing DOM focus from the search input. Replace setFocused(true) with only setFocusedKey for hover, and track hover state separately so options still get visual focus styling without moving actual DOM focus. Co-Authored-By: Claude Opus 4 <noreply@anthropic.com> Made-with: Cursor
1 parent 30448b1 commit 9b9dc89

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

static/app/views/explore/metrics/metricToolbar/metricSelector.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,16 +597,21 @@ function MetricListBoxOption({
597597
}: MetricListBoxOptionProps) {
598598
const ref = useRef<HTMLLIElement>(null);
599599
const option = item.value!;
600+
const [isHovered, setIsHovered] = useState(false);
600601
const {optionProps, isFocused, isSelected, isDisabled, isPressed} = useOption(
601602
{key: item.key, 'aria-label': option.label},
602603
listState,
603604
ref
604605
);
605606
const optionPropsMerged = mergeProps(optionProps, {
606607
onMouseEnter: () => {
607-
listState.selectionManager.setFocused(true);
608+
// Only update focusedKey — do NOT call setFocused(true).
609+
// setFocused(true) triggers a useEffect in useSelectableItem that calls
610+
// focusSafely(ref.current), which would steal DOM focus from the search input.
608611
listState.selectionManager.setFocusedKey(item.key);
612+
setIsHovered(true);
609613
},
614+
onMouseLeave: () => setIsHovered(false),
610615
});
611616

612617
return (
@@ -617,7 +622,7 @@ function MetricListBoxOption({
617622
ref={mergeRefs(ref, measureRef)}
618623
size={size}
619624
label={option.label}
620-
isFocused={listState.selectionManager.isFocused && isFocused}
625+
isFocused={isFocused || isHovered}
621626
isSelected={isSelected}
622627
isPressed={isPressed}
623628
disabled={isDisabled}

0 commit comments

Comments
 (0)