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

fix(tabs): fix connot read properties of null (reading width) #5212

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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: 5 additions & 3 deletions dist/tabs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@ VantComponent({
const offsetLeft = tabRects
.slice(0, currentIndex)
.reduce((prev, curr) => prev + curr.width, 0);
this.setData({
scrollLeft: offsetLeft - (navRect.width - tabRect.width) / 2,
});
if (navRect && (navRect === null || navRect === void 0 ? void 0 : navRect.width) && tabRect && (tabRect === null || tabRect === void 0 ? void 0 : tabRect.width)) {
this.setData({
scrollLeft: offsetLeft - (navRect.width - tabRect.width) / 2,
});
}
if (!scrollWithAnimation) {
nextTick(() => {
this.setData({ scrollWithAnimation: true });
Expand Down
8 changes: 5 additions & 3 deletions lib/tabs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,11 @@ var relation_1 = require("../common/relation");
var offsetLeft = tabRects
.slice(0, currentIndex)
.reduce(function (prev, curr) { return prev + curr.width; }, 0);
_this.setData({
scrollLeft: offsetLeft - (navRect.width - tabRect.width) / 2,
});
if (navRect && (navRect === null || navRect === void 0 ? void 0 : navRect.width) && tabRect && (tabRect === null || tabRect === void 0 ? void 0 : tabRect.width)) {
_this.setData({
scrollLeft: offsetLeft - (navRect.width - tabRect.width) / 2,
});
}
if (!scrollWithAnimation) {
(0, utils_1.nextTick)(function () {
_this.setData({ scrollWithAnimation: true });
Expand Down
8 changes: 5 additions & 3 deletions packages/tabs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,11 @@ VantComponent({
.slice(0, currentIndex)
.reduce((prev, curr) => prev + curr.width, 0);

this.setData({
scrollLeft: offsetLeft - (navRect.width - tabRect.width) / 2,
});
if (navRect && navRect?.width && tabRect && tabRect?.width) {
this.setData({
scrollLeft: offsetLeft - (navRect.width - tabRect.width) / 2,
});
}

if (!scrollWithAnimation) {
nextTick(() => {
Expand Down