fix(files): a folder made from the upload dialog gives the keyboard back the target once it is made
This commit is contained in:
@@ -81,13 +81,7 @@ export default function UploadDialog({
|
||||
const foldersQ = useQuery({ queryKey: qk.fileFolders(), queryFn: api.fileFolders });
|
||||
const [naming, setNaming] = useState(false);
|
||||
const targetBox = useRef<HTMLDivElement>(null);
|
||||
// A new folder's name ended by a key leaves the keyboard's focus nowhere: back on the list.
|
||||
const refocusTarget = useRef(false);
|
||||
useEffect(() => {
|
||||
if (naming || !refocusTarget.current) return;
|
||||
refocusTarget.current = false;
|
||||
targetBox.current?.querySelector("button")?.focus();
|
||||
}, [naming]);
|
||||
// A press on Cancel, the ✕ or the backdrop blurs the name field before the dialog closes, and the
|
||||
// field saves on blur: that press is "never mind", not "make it". The press is seen before the
|
||||
// blur it causes, in every browser (which control takes the focus, if any, differs: Safari
|
||||
@@ -112,6 +106,15 @@ export default function UploadDialog({
|
||||
},
|
||||
meta: { failTitle: "errors.writeFailed.folder.create" },
|
||||
});
|
||||
// A new folder's name ended by a key leaves the keyboard's focus nowhere: back on the list — once
|
||||
// it is back, as the folder is made (or fails): until then its place says it is being made.
|
||||
useEffect(() => {
|
||||
if (naming || !refocusTarget.current) return;
|
||||
const list = targetBox.current?.querySelector("button");
|
||||
if (!list) return;
|
||||
refocusTarget.current = false;
|
||||
list.focus();
|
||||
}, [naming, makeFolder.isPending]);
|
||||
// Not while a folder is being named or made: the file would go to the last target, not that one.
|
||||
const targetSettling = naming || makeFolder.isPending;
|
||||
const targets = (foldersQ.data ?? []).filter(takesUploads);
|
||||
|
||||
Reference in New Issue
Block a user