fix: focus task name on create dialog open (#788)

* fix: focus task name on create dialog open

* fix: guard task-name focus effect to first truthy transition

---------

Co-authored-by: Kandev Agent <agent@kandev.dev>
This commit is contained in:
João Salavisa
2026-05-02 23:47:19 +01:00
committed by GitHub
parent 32f098a6fc
commit 5b7760e797
3 changed files with 15 additions and 3 deletions
@@ -313,6 +313,12 @@ export type DialogPromptSectionProps = {
descriptionPlaceholder?: string;
/** Optional slot rendered above the description textarea (e.g. a tab toggle). */
aboveDescriptionSlot?: React.ReactNode;
/**
* Whether the description textarea should grab focus on mount. Defaults to
* `!isTaskStarted`. Callers that render a task-name input above the
* description should pass `false` so the name field wins focus.
*/
autoFocusDescription?: boolean;
};
// importBindings collapses the optional Jira/Linear import callbacks into the
@@ -344,19 +350,21 @@ export function DialogPromptSection({
extraFormSlot,
descriptionPlaceholder,
aboveDescriptionSlot,
autoFocusDescription,
}: DialogPromptSectionProps) {
const importsEnabled = !isSessionMode && !isTaskStarted;
const ws = workspaceId ?? null;
const placeholder = isPassthroughProfile
? "Passthrough mode — prompt not supported"
: descriptionPlaceholder;
const shouldAutoFocus = autoFocusDescription ?? !isTaskStarted;
return (
<>
{aboveDescriptionSlot}
<TaskFormInputs
key={fs.openCycle}
isSessionMode={isSessionMode}
autoFocus={!isTaskStarted}
autoFocus={shouldAutoFocus}
initialDescription={initialDescription}
onDescriptionChange={fs.setHasDescription}
onKeyDown={handleKeyDown}
@@ -249,9 +249,11 @@ export const InlineTaskName = memo(function InlineTaskName({
autoFocus,
}: InlineTaskNameProps) {
const inputRef = useRef<HTMLInputElement>(null);
const hasFocusedRef = useRef(false);
useEffect(() => {
if (autoFocus && inputRef.current) {
if (autoFocus && !hasFocusedRef.current && inputRef.current) {
hasFocusedRef.current = true;
inputRef.current.focus();
inputRef.current.select();
}
+3 -1
View File
@@ -177,6 +177,7 @@ function CreateModeBody(props: DialogFormBodyProps) {
isLocalExecutor,
} = props;
const showTaskName = (isCreateMode || isEditMode) && !isTaskStarted;
const taskNameAutoFocus = !isEditMode && !fs.useGitHubUrl;
return (
<>
<RepoChipsRow
@@ -197,7 +198,7 @@ function CreateModeBody(props: DialogFormBodyProps) {
<InlineTaskName
value={fs.taskName}
onChange={onTaskNameChange}
autoFocus={!isEditMode && !fs.useGitHubUrl}
autoFocus={taskNameAutoFocus}
/>
)}
<DialogPromptSection
@@ -215,6 +216,7 @@ function CreateModeBody(props: DialogFormBodyProps) {
descriptionPlaceholder={props.descriptionPlaceholder}
aboveDescriptionSlot={props.aboveDescriptionSlot}
extraFormSlot={props.extraFormSlot}
autoFocusDescription={!isTaskStarted && !(showTaskName && taskNameAutoFocus)}
/>
<CreateModeSelectors
isTaskStarted={isTaskStarted}