mirror of
https://github.com/docmost/docmost.git
synced 2026-08-31 02:46:27 +08:00
fix focus
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { IBaseProperty, IBaseRow } from "@/ee/base/types/base.types";
|
import { IBaseProperty, IBaseRow } from "@/ee/base/types/base.types";
|
||||||
import { timeAgo } from "@/lib/time.ts";
|
import { timeAgo } from "@/lib/time.ts";
|
||||||
@@ -24,29 +24,21 @@ export function RowDetailTitle({
|
|||||||
? (((row.cells ?? {})[primaryProperty.id] as string) ?? "")
|
? (((row.cells ?? {})[primaryProperty.id] as string) ?? "")
|
||||||
: "";
|
: "";
|
||||||
const [value, setValue] = useState(initial);
|
const [value, setValue] = useState(initial);
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
|
||||||
const didAutofocusRef = useRef(false);
|
|
||||||
|
|
||||||
// Re-sync when the row changes underneath us (navigation or remote edit).
|
// Re-sync when the row changes underneath us (navigation or remote edit).
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setValue(initial);
|
setValue(initial);
|
||||||
}, [initial]);
|
}, [initial]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (didAutofocusRef.current || !canEdit || initial) return;
|
|
||||||
didAutofocusRef.current = true;
|
|
||||||
inputRef.current?.focus();
|
|
||||||
}, [canEdit, initial]);
|
|
||||||
|
|
||||||
const updatedAgo = row.updatedAt ? timeAgo(new Date(row.updatedAt)) : "";
|
const updatedAgo = row.updatedAt ? timeAgo(new Date(row.updatedAt)) : "";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className={classes.header}>
|
<header className={classes.header}>
|
||||||
{canEdit ? (
|
{canEdit ? (
|
||||||
<input
|
<input
|
||||||
ref={inputRef}
|
|
||||||
type="text"
|
type="text"
|
||||||
className={classes.titleInput}
|
className={classes.titleInput}
|
||||||
|
{...(!initial ? { "data-autofocus": true } : {})}
|
||||||
placeholder={t("Untitled")}
|
placeholder={t("Untitled")}
|
||||||
aria-label={primaryProperty?.name ?? t("Untitled")}
|
aria-label={primaryProperty?.name ?? t("Untitled")}
|
||||||
value={value}
|
value={value}
|
||||||
|
|||||||
Reference in New Issue
Block a user