Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions apps/roam/src/components/FuzzySelectInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type FuzzySelectInputProps<T extends Result = Result> = {
options?: T[];
placeholder?: string;
autoFocus?: boolean;
disabled?: boolean;
initialIsLocked?: boolean;
};

Expand All @@ -33,7 +32,6 @@ const FuzzySelectInput = <T extends Result = Result>({
options = [],
placeholder = "Enter value",
autoFocus,
disabled,
initialIsLocked,
}: FuzzySelectInputProps<T>) => {
const [isLocked, setIsLocked] = useState(initialIsLocked || false);
Expand Down Expand Up @@ -64,6 +62,7 @@ const FuzzySelectInput = <T extends Result = Result>({
setQuery(item.text);
setValue(item);
setIsOpen(false);
requestAnimationFrame(() => inputRef.current?.focus());
}
},
[mode, initialUid, setValue, onLockedChange],
Expand Down Expand Up @@ -132,6 +131,12 @@ const FuzzySelectInput = <T extends Result = Result>({
}
}, [activeIndex, isOpen]);

useEffect(() => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on Canvas in "create" mode the autofocus doesn't get applied.

if (!autoFocus || mode !== "create" || isLocked) return;
const id = setTimeout(() => inputRef.current?.focus(), 150);
return () => clearTimeout(id);
}, [autoFocus, mode, isLocked]);

if (mode === "edit") {
return (
<TextArea
Expand All @@ -143,7 +148,6 @@ const FuzzySelectInput = <T extends Result = Result>({
growVertically
placeholder={placeholder}
autoFocus={autoFocus}
disabled={disabled}
/>
);
}
Expand Down Expand Up @@ -172,14 +176,14 @@ const FuzzySelectInput = <T extends Result = Result>({
<Popover
isOpen={isOpen}
minimal
autoFocus={false}
enforceFocus={false}
position={PopoverPosition.BOTTOM_LEFT}
modifiers={{
flip: { enabled: false },
preventOverflow: { enabled: false },
}}
className="fuzzy-select-input-popover w-full"
autoFocus={false}
enforceFocus={false}
content={
<Menu className="max-h-64 max-w-md overflow-auto" ulRef={menuRef}>
{filteredItems.map((item, index) => (
Expand All @@ -199,14 +203,13 @@ const FuzzySelectInput = <T extends Result = Result>({
target={
<InputGroup
fill
inputRef={inputRef}
className="w-full"
disabled={disabled}
value={query}
onChange={(e) => setQuery(e.target.value)}
onKeyDown={handleKeyDown}
autoFocus={autoFocus}
placeholder={placeholder}
inputRef={inputRef}
onFocus={() => {
setIsFocused(true);
}}
Expand Down
4 changes: 2 additions & 2 deletions apps/roam/src/components/ModifyNodeDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,9 @@ const ModifyNodeDialog = ({
? "..."
: `Enter a ${selectedNodeType.text.toLowerCase()} ...`
}
disabled={loading}
mode={mode}
initialUid={content.uid}
autoFocus
/>
</div>

Expand All @@ -551,10 +551,10 @@ const ModifyNodeDialog = ({
setValue={setReferencedNodeValueCallback}
options={options.referencedNode}
placeholder={loading ? "..." : "Select a referenced node"}
disabled={loading}
mode={"create"}
initialUid={referencedNodeValue.uid}
initialIsLocked={isReferencedNodeLocked}
autoFocus={false}
/>
</div>
)}
Expand Down