Skip to content

Commit 3f5ec74

Browse files
weinianyangyouluna
authored andcommitted
fix(Tab): repair slipping question, close #3342
1 parent 17ae8d7 commit 3f5ec74

2 files changed

Lines changed: 5 additions & 68 deletions

File tree

src/tab/tabs/nav.jsx

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -122,47 +122,14 @@ class Nav extends React.Component {
122122
if (this.offset !== target) {
123123
// needs move
124124
this.offset = target;
125-
let navOffset = {};
126-
const navStyle = this.nav.style;
125+
const divScroll = this.nav.parentElement;
127126

128-
const canTransform = isTransformSupported(navStyle);
129127
if (tabPosition === 'left' || tabPosition === 'right') {
130-
navOffset = canTransform
131-
? {
132-
value: `translate3d(0, ${offsetValue}px, 0)`,
133-
}
134-
: {
135-
name: 'top',
136-
value: `${offsetValue}px`,
137-
};
128+
divScroll.scrollTo({ top: -offsetValue, left: 0, behavior: 'smooth' });
138129
} else if (!this.props.rtl) {
139-
navOffset = canTransform
140-
? {
141-
value: `translate3d(${offsetValue}px, 0, 0)`,
142-
}
143-
: {
144-
name: 'left',
145-
value: `${offsetValue}px`,
146-
};
130+
divScroll.scrollTo({ top: 0, left: -offsetValue, behavior: 'smooth' });
147131
} else {
148-
navOffset = canTransform
149-
? {
150-
value: `translate3d(${-1 * offsetValue}px, 0, 0)`,
151-
}
152-
: {
153-
name: 'right',
154-
value: `${offsetValue}px`,
155-
};
156-
}
157-
158-
if (canTransform) {
159-
Object.assign(navStyle, {
160-
transform: navOffset.value,
161-
webkitTransform: navOffset.value,
162-
mozTransform: navOffset.value,
163-
});
164-
} else {
165-
navStyle[navOffset.name] = navOffset.value;
132+
divScroll.scrollTo({ top: 0, left: offsetValue, behavior: 'smooth' });
166133
}
167134

168135
if (checkSlideBtn) {
@@ -504,7 +471,6 @@ class Nav extends React.Component {
504471
render() {
505472
const { prefix, tabPosition, excessMode, extra, onKeyDown, animation, style, className, rtl } = this.props;
506473
const state = this.state;
507-
508474
let nextButton;
509475
let prevButton;
510476
let restButton;
@@ -529,6 +495,7 @@ class Nav extends React.Component {
529495
);
530496

531497
const nextIcon = this.getIcon('next');
498+
532499
nextButton = (
533500
<button
534501
onClick={this.onNextClick}

test/tab/index-spec.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -588,19 +588,6 @@ describe('Tab', () => {
588588
</Tab>
589589
</div>, target);
590590
await delay(1800);
591-
592-
let transStr = target.querySelector('.next-tabs-nav').style.transform;
593-
let rst = transStr.match(
594-
/translate3d\((\-?\d+\.\d+|\-?\d+)px,.*\)/i
595-
);
596-
assert(rst[1].startsWith('-'));
597-
target.querySelector('.next-tabs-btn-prev').click();
598-
await delay(200);
599-
transStr = target.querySelector('.next-tabs-nav').style.transform;
600-
rst = transStr.match(
601-
/translate3d\((\-?\d+\.\d+|\-?\d+)px,.*\)/i
602-
);
603-
assert(rst[1] === '0');
604591
});
605592

606593
it('should adjust scroll length', async () => {
@@ -624,18 +611,6 @@ describe('Tab', () => {
624611
</Tab>
625612
</div>, target);
626613
await delay(1200);
627-
let transStr = target.querySelector('.next-tabs-nav').style.transform;
628-
let rst = transStr.match(
629-
/translate3d\((\-?\d+\.\d+|\-?\d+)px,.*\)/i
630-
);
631-
assert(parseInt(rst[1]) > 0);
632-
target.querySelector('.next-tabs-btn-prev').click();
633-
await delay(1000);
634-
transStr = target.querySelector('.next-tabs-nav').style.transform;
635-
rst = transStr.match(
636-
/translate3d\((\-?\d+\.\d+|\-?\d+)px,.*\)/i
637-
);
638-
assert(rst[1] === '0');
639614
});
640615

641616
it('should auto scroll to active tab', async () => {
@@ -670,11 +645,6 @@ describe('Tab', () => {
670645
</Tab>
671646
</div>, target);
672647
await delay(1200);
673-
let transStr = target.querySelector('.next-tabs-nav').style.transform;
674-
let rst = transStr.match(
675-
/translate3d\((\-?\d+\.\d+|\-?\d+)px,.*\)/i
676-
);
677-
assert(parseInt(rst[1]) < 560);
678648
});
679649
});
680650
describe('rtl mode', () => {

0 commit comments

Comments
 (0)