diff --git a/src/App.tsx b/src/App.tsx index 55bb376..b8637d5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -366,7 +366,14 @@ function MainContent(): React.JSX.Element { > {contextHolder} - {!immersiveMode && ( +
- )} +
= ({ const scrollContainerRef = useRef(null) const groupRefs = useRef>({}) const searchAreaRef = useRef(null) + const immersiveToolbarRef = useRef(null) + const immersiveToolbarContentRef = useRef(null) + const [immersiveToolbarWidth, setImmersiveToolbarWidth] = useState(null) const [selectedStudent, setSelectedStudent] = useState(null) const [batchMode, setBatchMode] = useState(false) @@ -320,6 +323,33 @@ export const Home: React.FC = ({ return () => document.removeEventListener("mousedown", onDocumentClick) }, []) + useEffect(() => { + if (!immersiveMode) return + const contentEl = immersiveToolbarContentRef.current + if (!contentEl) return + + let frameId: number | null = null + const updateToolbarWidth = () => { + if (frameId !== null) cancelAnimationFrame(frameId) + frameId = requestAnimationFrame(() => { + const contentWidth = Math.ceil(contentEl.getBoundingClientRect().width) + const nextWidth = contentWidth + 20 + setImmersiveToolbarWidth((prev) => (prev === nextWidth ? prev : nextWidth)) + }) + } + + updateToolbarWidth() + const observer = new ResizeObserver(updateToolbarWidth) + observer.observe(contentEl) + window.addEventListener("resize", updateToolbarWidth) + + return () => { + observer.disconnect() + window.removeEventListener("resize", updateToolbarWidth) + if (frameId !== null) cancelAnimationFrame(frameId) + } + }, [immersiveMode]) + useEffect(() => { return () => { if (longPressTimerRef.current !== null) { @@ -376,6 +406,10 @@ export const Home: React.FC = ({ setSearchKeyword((prev) => `${prev}${keyValue}`) } + const getImmersivePopupContainer = useCallback((triggerNode: HTMLElement) => { + return immersiveToolbarRef.current ?? triggerNode.parentElement ?? document.body + }, []) + const getDisplayText = (name: string) => { if (!name) return "" return name.length > 2 ? name.substring(name.length - 2) : name @@ -2467,29 +2501,34 @@ export const Home: React.FC = ({ )} - {immersiveMode && ( -
+
{ + searchAreaRef.current = node + immersiveToolbarContentRef.current = node + }} style={{ display: "flex", alignItems: "center", @@ -2519,6 +2558,7 @@ export const Home: React.FC = ({ setLayoutType(v as LayoutType)} + getPopupContainer={getImmersivePopupContainer} style={{ width: 126, flexShrink: 0 }} options={[ { value: "grouped", label: t("home.layoutBy.grouped") }, @@ -2625,8 +2666,7 @@ export const Home: React.FC = ({
)}
-
- )} + {isPortraitMode ? (