mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-05 10:29:30 +08:00
fix(notes): focus the first action when the on-demand menu mounts
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { ArrowLeft, Bookmark, Check, ChevronRight, CornerUpRight, FileDown, FileText, Pin, PinOff } from 'lucide-react'
|
||||
import type { NotePage, NoteSummary } from '@/lib/notes-api'
|
||||
@@ -21,6 +21,11 @@ export default function NotePageMenu({
|
||||
const { t } = useTranslation()
|
||||
const [moving, setMoving] = useState(false)
|
||||
const [query, setQuery] = useState('')
|
||||
const menuRef = useRef<HTMLDivElement>(null)
|
||||
useEffect(() => {
|
||||
// The parent can open before this on-demand chunk has mounted.
|
||||
menuRef.current?.querySelector<HTMLElement>('[role="menuitem"]:not(:disabled)')?.focus()
|
||||
}, [])
|
||||
const targets = pages
|
||||
.filter(p => p.id !== page?.id && !invalidParents.has(p.id))
|
||||
.filter(p => (p.title || '').toLowerCase().includes(query.trim().toLowerCase()))
|
||||
@@ -29,7 +34,7 @@ export default function NotePageMenu({
|
||||
onMetadata({ parent_id })
|
||||
}
|
||||
return (
|
||||
<div className="dt-popover dt-note-page-menu" role="menu">
|
||||
<div ref={menuRef} className="dt-popover dt-note-page-menu" role="menu">
|
||||
{moving ? (
|
||||
<>
|
||||
<button role="menuitem" className="dt-menu-item is-quiet" onClick={() => setMoving(false)}>
|
||||
|
||||
Reference in New Issue
Block a user