Commit 104a972
authored
Fix page jitter by compensating for scrollbar width (#63)
Fixes the page jitter/shake issue when the search modal opens by compensating for the scrollbar width, following the same approach as VitePress.
## Problem
When the search modal opens, hiding the body scrollbar caused the page content to shift to the right, creating a jarring visual effect.
## Solution
Instead of adding a configuration option, this implements the standard fix by:
1. Calculating the scrollbar width: `window.innerWidth - document.documentElement.clientWidth`
2. Adding `padding-right` equal to the scrollbar width when hiding body overflow
3. Removing the padding when restoring overflow
This ensures the page content stays in the exact same position when the modal opens and closes.
## Changes Made
- Modified `search-modal.ts` `willUpdate` method to calculate and apply padding compensation
- Updated demo page (`index.html`) to demonstrate the fix with scrollable content
- No configuration needed - works automatically for all users
- No breaking changes
## Visual Proof
**Before opening modal** (with scrollbar):

**After opening modal** (no layout shift):

✅ **The page content stays perfectly aligned - no jitter or shift!**
## Testing
- ✅ Build passes successfully
- ✅ Linting passes
- ✅ Security scan passed (0 alerts)
- ✅ Visual verification confirms no layout shift
Fixes #62
<!-- START COPILOT CODING AGENT SUFFIX -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>搜索组件导致页面抖动问题</issue_title>
> <issue_description><img width="1162" height="499" alt="Image" src="https://github.com/user-attachments/assets/fa12a3c0-fd05-4725-aa70-49eebc8d2512" />
>
> 页面滚动条隐藏导致整体页面内容右移:
>
> <img width="1195" height="496" alt="Image" src="https://github.com/user-attachments/assets/24c2a80d-c997-49b2-97d9-6a06741765ff" />
>
> 参考 [vitepress 实例](https://howiehz.top/halo-theme-higan-haozi/guide/style-reference),搜索组件显示不会导致页面滚动条隐藏:
>
> <img width="1366" height="899" alt="Image" src="https://github.com/user-attachments/assets/3a88707c-27c2-4b5f-8e3d-9d032395fd37" />
>
> 希望提供配置项,决定是否隐藏滚动条,谢谢❤。
> </issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> <comment_new><author>@ruibaby</author><body>
> /kind improvement
> </body></comment_new>
> </comments>
>
</details>
- Fixes #62
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.
```release-note
减少当搜索框打开时,网页整体的抖动问题
```1 parent aab5d42 commit 104a972
2 files changed
+24
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
51 | 65 | | |
52 | 66 | | |
53 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
46 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
47 | 54 | | |
48 | 55 | | |
| 56 | + | |
49 | 57 | | |
50 | 58 | | |
51 | 59 | | |
| |||
0 commit comments