Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Measure fitted mobile menu content height correctly https://github.com/siyuan-note/siyuan/issues/19519

Daniele7de13ffd56d
diff --git a/app/src/menus/Menu.ts b/app/src/menus/Menu.ts
index d047b59900..c79f899ab9 100644
--- a/app/src/menus/Menu.ts
+++ b/app/src/menus/Menu.ts
@@ -353,10 +353,14 @@ export class Menu {
// 使用当前方向记录的完整视口高度,避免软键盘收起期间菜单高度被压缩
const maxHeight = Math.max(window.innerHeight, orientationSize?.height1 || 0) * .56;
if (this.element.classList.contains("b3-menu--fit")) {
- // 内容不足时收缩面板,避免列表下方留白;先清空高度,否则 scrollHeight 会被当前高度撑大
+ // 内容不足时收缩面板,避免列表下方留白;测量时取消弹性拉伸,否则 scrollHeight 会包含被撑大的空白
this.element.style.height = "";
+ const itemsElement = this.element.lastElementChild as HTMLElement;
+ const itemsFlex = itemsElement.style.flex;
+ itemsElement.style.flex = "none";
const titleHeight = this.element.firstElementChild.getBoundingClientRect().height;
- const contentHeight = this.element.lastElementChild.scrollHeight;
+ const contentHeight = itemsElement.scrollHeight;
+ itemsElement.style.flex = itemsFlex;
this.element.style.height = Math.min(maxHeight, Math.max(160, titleHeight + contentHeight)) + "px";
return;
}
diff --git a/app/src/menus/menuSheetHeight.test.ts b/app/src/menus/menuSheetHeight.test.ts
index 8d3def85c5..5891c7cd55 100644
--- a/app/src/menus/menuSheetHeight.test.ts
+++ b/app/src/menus/menuSheetHeight.test.ts
@@ -17,7 +17,14 @@ const setup = (options: {fit: boolean, contentHeight: number, viewportHeight: nu
classes.add("b3-menu--fit");
}
const title = {getBoundingClientRect: () => ({height: 16})};
- const items = {scrollHeight: options.contentHeight};
+ const itemsStyle = {flex: ""} as CSSStyleDeclaration;
+ const items = {
+ style: itemsStyle,
+ // 模拟真实底部菜单中 flex: 1 将内容区域撑满父容器的情况
+ get scrollHeight() {
+ return itemsStyle.flex === "none" ? options.contentHeight : options.viewportHeight * .9 - 16;
+ },
+ };
const element = {
style: {height: "100px"} as CSSStyleDeclaration,
firstElementChild: title,
@@ -39,7 +46,7 @@ const setup = (options: {fit: boolean, contentHeight: number, viewportHeight: nu
element,
updateSheetTitle: () => {},
});
- return {menu, element};
+ return {menu, element, itemsStyle};
};
describe("mobile menu sheet content fit", () => {
@@ -50,9 +57,10 @@ describe("mobile menu sheet content fit", () => {
});
it("shrinks the sheet to short content", () => {
- const {menu, element} = setup({fit: true, contentHeight: 272, viewportHeight: 2000});
+ const {menu, element, itemsStyle} = setup({fit: true, contentHeight: 272, viewportHeight: 2000});
menu.resetPosition();
assert.equal(element.style.height, "288px");
+ assert.equal(itemsStyle.flex, "");
});
it("caps fitted content at the standard sheet height", () => {