Skip to content

Commit 008dec3

Browse files
committed
feat: 标签列表高度动态调整
1 parent 27d8dc3 commit 008dec3

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/components/respository/CommentSubmit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function CommentSubmit(props: CommentSubmitProps) {
3838

3939
setCommentData({
4040
...commentData,
41-
comment: value.trim(),
41+
comment: value,
4242
height: e.currentTarget.scrollHeight + 2,
4343
});
4444
};

src/components/side/TagList.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ export default function TagList() {
3232
month,
3333
} = router.query;
3434
const [tags, setTags] = useState<Tag[]>([]);
35+
const [maxHeight, setMaxHeight] = useState<number>(444); // 初始为默认高度
36+
37+
// 动态更新 maxHeight 基于屏幕高度
38+
const updateMaxHeight = () => {
39+
// 根据需求动态计算,例如屏幕高度的 60%
40+
const calculatedHeight = Math.max(window.innerHeight * 0.6, 300); // 最小值为 300px
41+
setMaxHeight(calculatedHeight);
42+
};
3543

3644
useEffect(() => {
3745
const initTags = async () => {
@@ -44,6 +52,14 @@ export default function TagList() {
4452

4553
if (!isMobile()) {
4654
initTags();
55+
// 初始化计算高度
56+
updateMaxHeight();
57+
// 监听窗口大小变化,更新高度
58+
window.addEventListener('resize', updateMaxHeight);
59+
// 清理事件监听器
60+
return () => {
61+
window.removeEventListener('resize', updateMaxHeight);
62+
};
4763
}
4864
}, []); // 确保 useEffect 只在组件挂载时执行
4965

@@ -70,7 +86,10 @@ export default function TagList() {
7086
</div>
7187
</div>
7288
</div>
73-
<div className='hidden-scrollbar max-h-[444px] overflow-y-auto'>
89+
<div
90+
className='hidden-scrollbar overflow-y-auto'
91+
style={{ maxHeight: `${maxHeight}px` }}
92+
>
7493
{!tags.length && <TagListSkeleton />}
7594
{tags.map((item: Tag) => (
7695
<Link

0 commit comments

Comments
 (0)