Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tabs): scroll the active tab to the center position #1663

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,9 @@
if (!tab) return;
const tabLeft = tab?.offsetLeft;
const tabWidth = tab?.offsetWidth;
const navScrollScrollLeft = navScroll.value.scrollLeft;
const navScrollWidth = navScroll.value.offsetWidth;
if (tabLeft + tabWidth - navScrollScrollLeft > navScrollWidth) {
navScroll.value.scrollTo({ left: tabLeft + tabWidth - navScrollWidth, behavior: 'smooth' });
} else if (tabLeft < navScrollScrollLeft) {
navScroll.value.scrollTo({ left: tabLeft, behavior: 'smooth' });
}
const scrollDistance = tabLeft - navScrollWidth / 2 + tabWidth / 2;
navScroll.value.scrollTo({ left: scrollDistance, behavior: 'smooth' });

Check failure on line 129 in src/tabs/tabs.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / test

Unhandled error

TypeError: navScroll.value.scrollTo is not a function ❯ moveToActiveTab src/tabs/tabs.tsx:129:25 ❯ Module.<anonymous> src/tabs/tabs.tsx:161:9 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tabs/__test__/index.test.jsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is ": showBottomLine". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 129 in src/tabs/tabs.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / test

Unhandled error

TypeError: navScroll.value.scrollTo is not a function ❯ moveToActiveTab src/tabs/tabs.tsx:129:25 ❯ Module.<anonymous> src/tabs/tabs.tsx:161:9 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tabs/__test__/index.test.jsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is ": showBottomLine". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 129 in src/tabs/tabs.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / test

Unhandled error

TypeError: navScroll.value.scrollTo is not a function ❯ moveToActiveTab src/tabs/tabs.tsx:129:25 ❯ Module.<anonymous> src/tabs/tabs.tsx:161:9 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tabs/__test__/index.test.jsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is ": showBottomLine". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 129 in src/tabs/tabs.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / test

Unhandled error

TypeError: navScroll.value.scrollTo is not a function ❯ moveToActiveTab src/tabs/tabs.tsx:129:25 ❯ Module.<anonymous> src/tabs/tabs.tsx:161:9 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tabs/__test__/index.test.jsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is ": showBottomLine". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 129 in src/tabs/tabs.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / test

Unhandled error

TypeError: navScroll.value.scrollTo is not a function ❯ moveToActiveTab src/tabs/tabs.tsx:129:25 ❯ Module.<anonymous> src/tabs/tabs.tsx:161:9 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tabs/__test__/index.test.jsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is ": showBottomLine". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 129 in src/tabs/tabs.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / test

Unhandled error

TypeError: navScroll.value.scrollTo is not a function ❯ moveToActiveTab src/tabs/tabs.tsx:129:25 ❯ Module.<anonymous> src/tabs/tabs.tsx:148:9 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tabs/__test__/index.test.jsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is ": showBottomLine". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 129 in src/tabs/tabs.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / test

Unhandled error

TypeError: navScroll.value.scrollTo is not a function ❯ moveToActiveTab src/tabs/tabs.tsx:129:25 ❯ Module.<anonymous> src/tabs/tabs.tsx:161:9 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tabs/__test__/index.test.jsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is ": showBottomLine". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 129 in src/tabs/tabs.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / test

Unhandled error

TypeError: navScroll.value.scrollTo is not a function ❯ moveToActiveTab src/tabs/tabs.tsx:129:25 ❯ Module.<anonymous> src/tabs/tabs.tsx:148:9 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tabs/__test__/index.test.jsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is ": showBottomLine". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 129 in src/tabs/tabs.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / test

Unhandled error

TypeError: navScroll.value.scrollTo is not a function ❯ moveToActiveTab src/tabs/tabs.tsx:129:25 ❯ Module.<anonymous> src/tabs/tabs.tsx:161:9 ❯ runNextTicks node:internal/process/task_queues:60:5 ❯ processTimers node:internal/timers:509:9 This error originated in "src/tabs/__test__/index.test.jsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "src/tabs/__test__/index.test.jsx". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 129 in src/tabs/tabs.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / test

Unhandled error

TypeError: navScroll.value.scrollTo is not a function ❯ moveToActiveTab src/tabs/tabs.tsx:129:25 ❯ Module.<anonymous> src/tabs/tabs.tsx:161:9 ❯ runNextTicks node:internal/process/task_queues:60:5 ❯ processTimers node:internal/timers:509:9 This error originated in "src/tabs/__test__/index.test.jsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "src/tabs/__test__/index.test.jsx". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

滚动到激活项时,底步滚动条似乎总会停顿一下

2024-12-18.11.53.30.mov

}
};

Expand Down
Loading