Skip to content

Commit

Permalink
auto focus search input
Browse files Browse the repository at this point in the history
  • Loading branch information
georgi committed Jan 13, 2025
1 parent fb2caec commit 7e6ff92
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions web/src/components/context_menus/ConnectableNodes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @jsxImportSource @emotion/react */
import React, { memo, useCallback, useState, useRef } from "react";
import React, { memo, useCallback, useState, useRef, useEffect } from "react";
import {
Menu,
MenuItem,
Expand Down Expand Up @@ -164,6 +164,15 @@ const ConnectableNodes: React.FC<ConnectableNodesProps> = ({
const [isFocused, setIsFocused] = useState(false);
const focusedNodeRef = useRef<HTMLDivElement>(null);
const currentHoveredNodeRef = useRef<NodeMetadata | null>(null);
const searchInputRef = useRef<HTMLInputElement>(null);

useEffect(() => {
if (isVisible) {
setTimeout(() => {
searchInputRef.current?.focus();
}, 100);
}
}, [isVisible]);

const filteredNodes = searchTerm
? searchNodesHelper(connectableNodes, searchTerm)
Expand Down Expand Up @@ -271,14 +280,14 @@ const ConnectableNodes: React.FC<ConnectableNodesProps> = ({
</MenuItem>
<MenuItem>
<TextField
inputRef={searchInputRef}
className="connectable-nodes-search"
size="small"
fullWidth
placeholder="Search nodes..."
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
onClick={(e) => e.stopPropagation()}
autoFocus
onKeyDown={(e) => {
if (e.key === "Escape") {
hideMenu();
Expand Down

0 comments on commit 7e6ff92

Please sign in to comment.