Skip to content

Commit 7c462eb

Browse files
trangdoan982claude
andauthored
ENG-1646: Auto-resize content input and 512 char limit in node creation dialog (Roam) (#985)
* ENG-1646: Auto-resize content input and 512 char limit in node creation dialog (Roam) - Replace InputGroup with TextArea (growVertically) in create mode for auto-resize - Add 512 character limit with an inline warning message at the limit Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Apply 512 char limit to edit mode and reduce textarea min-height to 1 line - Add maxLength and limit warning to edit mode textarea - Reduce min-height from 96px to 2rem so textarea starts at ~1 line and grows naturally Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9bfd6a9 commit 7c462eb

2 files changed

Lines changed: 49 additions & 31 deletions

File tree

apps/roam/src/components/FuzzySelectInput.tsx

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import React, {
88
import {
99
Button,
1010
TextArea,
11-
InputGroup,
1211
Menu,
1312
MenuItem,
1413
Popover,
@@ -18,6 +17,7 @@ import fuzzy from "fuzzy";
1817
import { Result } from "~/utils/types";
1918

2019
const RESULTS_LIMIT = 50;
20+
const MAX_CONTENT_LENGTH = 512;
2121

2222
type FuzzySelectInputProps<T extends Result = Result> = {
2323
value?: T;
@@ -44,7 +44,7 @@ const FuzzySelectInput = <T extends Result = Result>({
4444
const [isFocused, setIsFocused] = useState(false);
4545

4646
const menuRef = useRef<HTMLUListElement>(null);
47-
const inputRef = useRef<HTMLInputElement>(null);
47+
const inputRef = useRef<HTMLTextAreaElement>(null);
4848

4949
const filteredItems = useMemo(() => {
5050
if (!query) return options;
@@ -86,7 +86,7 @@ const FuzzySelectInput = <T extends Result = Result>({
8686
);
8787

8888
const handleKeyDown = useCallback(
89-
(e: React.KeyboardEvent<HTMLInputElement>) => {
89+
(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
9090
if (e.key === "ArrowDown") {
9191
e.preventDefault();
9292
setActiveIndex((prev) =>
@@ -158,17 +158,26 @@ const FuzzySelectInput = <T extends Result = Result>({
158158
}, [autoFocus, mode, isLocked]);
159159

160160
if (mode === "edit") {
161+
const editText = value?.text || "";
161162
return (
162-
<TextArea
163-
value={value?.text || ""}
164-
onChange={(e) => {
165-
setValue({ text: e.target.value, uid: value?.uid || "" } as T);
166-
}}
167-
fill
168-
growVertically
169-
placeholder={placeholder}
170-
autoFocus={autoFocus}
171-
/>
163+
<div className="w-full">
164+
<TextArea
165+
value={editText}
166+
onChange={(e) => {
167+
setValue({ text: e.target.value, uid: value?.uid || "" } as T);
168+
}}
169+
fill
170+
growVertically
171+
placeholder={placeholder}
172+
autoFocus={autoFocus}
173+
maxLength={MAX_CONTENT_LENGTH}
174+
/>
175+
{editText.length >= MAX_CONTENT_LENGTH && (
176+
<p className="mt-1 text-xs text-red-500">
177+
Character limit reached ({MAX_CONTENT_LENGTH})
178+
</p>
179+
)}
180+
</div>
172181
);
173182
}
174183

@@ -227,23 +236,32 @@ const FuzzySelectInput = <T extends Result = Result>({
227236
</Menu>
228237
}
229238
target={
230-
<InputGroup
231-
fill
232-
inputRef={inputRef}
233-
className="w-full"
234-
value={query}
235-
onChange={(e) => handleInputChange(e.target.value)}
236-
onKeyDown={handleKeyDown}
237-
autoFocus={autoFocus}
238-
placeholder={placeholder}
239-
onFocus={() => {
240-
setIsFocused(true);
241-
}}
242-
onBlur={() => {
243-
setIsFocused(false);
244-
setTimeout(() => setIsOpen(false), 200);
245-
}}
246-
/>
239+
<div className="w-full">
240+
<TextArea
241+
fill
242+
inputRef={inputRef}
243+
className="w-full"
244+
value={query}
245+
onChange={(e) => handleInputChange(e.target.value)}
246+
onKeyDown={handleKeyDown}
247+
autoFocus={autoFocus}
248+
placeholder={placeholder}
249+
growVertically
250+
maxLength={MAX_CONTENT_LENGTH}
251+
onFocus={() => {
252+
setIsFocused(true);
253+
}}
254+
onBlur={() => {
255+
setIsFocused(false);
256+
setTimeout(() => setIsOpen(false), 200);
257+
}}
258+
/>
259+
{query.length >= MAX_CONTENT_LENGTH && (
260+
<p className="mt-1 text-xs text-red-500">
261+
Character limit reached ({MAX_CONTENT_LENGTH})
262+
</p>
263+
)}
264+
</div>
247265
}
248266
/>
249267
);

apps/roam/src/styles/discourseGraphStyles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ div.roamjs-discourse-drawer div.bp3-drawer {
168168
}
169169

170170
.roamjs-canvas-dialog textarea {
171-
min-height: 96px;
171+
min-height: 2rem;
172172
}
173173

174174
/*

0 commit comments

Comments
 (0)