diff --git a/components/vc-tabs/src/InkTabBarNode.jsx b/components/vc-tabs/src/InkTabBarNode.jsx index 92f827d06..47240e504 100644 --- a/components/vc-tabs/src/InkTabBarNode.jsx +++ b/components/vc-tabs/src/InkTabBarNode.jsx @@ -1,46 +1,11 @@ import PropTypes from '../../_util/vue-types' -import { setTransform, isTransformSupported } from './utils' +import { setTransform, isTransformSupported, getLeft, getTop } from './utils' import BaseMixin from '../../_util/BaseMixin' -export function getScroll (w, top) { - let ret = w[`page${top ? 'Y' : 'X'}Offset`] - const method = `scroll${top ? 'Top' : 'Left'}` - if (typeof ret !== 'number') { - const d = w.document - // ie6,7,8 standard mode - ret = d.documentElement[method] - if (typeof ret !== 'number') { - // quirks mode - ret = d.body[method] - } - } - return ret -} - -function offset (elem) { - let x - let y - const doc = elem.ownerDocument - const body = doc.body - const docElem = doc && doc.documentElement - const box = elem.getBoundingClientRect() - x = box.left - y = box.top - x -= docElem.clientLeft || body.clientLeft || 0 - y -= docElem.clientTop || body.clientTop || 0 - const w = doc.defaultView || doc.parentWindow - x += getScroll(w) - y += getScroll(w, true) - return { - left: x, top: y, - } -} - function componentDidUpdate (component, init) { const { styles = {}} = component.$props const rootNode = component.getRef('root') const wrapNode = component.getRef('nav') || rootNode - const containerOffset = offset(wrapNode) const inkBarNode = component.getRef('inkBar') const activeTab = component.getRef('activeTab') const inkBarNodeStyle = inkBarNode.style @@ -51,12 +16,10 @@ function componentDidUpdate (component, init) { } if (activeTab) { const tabNode = activeTab - const tabOffset = offset(tabNode) const transformSupported = isTransformSupported(inkBarNodeStyle) if (tabBarPosition === 'top' || tabBarPosition === 'bottom') { - let left = tabOffset.left - containerOffset.left + let left = getLeft(tabNode, wrapNode) let width = tabNode.offsetWidth - // If tabNode'width width equal to wrapNode'width when tabBarPosition is top or bottom // It means no css working, then ink bar should not have width until css is loaded // Fix https://github.com/ant-design/ant-design/issues/7564 @@ -80,7 +43,7 @@ function componentDidUpdate (component, init) { inkBarNodeStyle.right = `${wrapNode.offsetWidth - left - width}px` } } else { - let top = tabOffset.top - containerOffset.top + let top = getTop(tabNode, wrapNode) let height = tabNode.offsetHeight if (styles.inkBar && styles.inkBar.height !== undefined) { height = parseFloat(styles.inkBar.height, 10) diff --git a/components/vc-tabs/src/ScrollableTabBarNode.jsx b/components/vc-tabs/src/ScrollableTabBarNode.jsx index 14fb9a303..b3962c08c 100644 --- a/components/vc-tabs/src/ScrollableTabBarNode.jsx +++ b/components/vc-tabs/src/ScrollableTabBarNode.jsx @@ -3,6 +3,7 @@ import addDOMEventListener from 'add-dom-event-listener' import debounce from 'lodash/debounce' import PropTypes from '../../_util/vue-types' import BaseMixin from '../../_util/BaseMixin' +import { getComponentFromProp } from '../../_util/props-util' function noop () { } @@ -17,6 +18,8 @@ export default { scrollAnimated: PropTypes.bool.def(true), navWrapper: PropTypes.func.def(arg => arg), activeKey: PropTypes.any, + prevIcon: PropTypes.any, + nextIcon: PropTypes.any, }, data () { @@ -83,7 +86,8 @@ export default { }, setNextPrev () { const navNode = this.$props.getRef('nav') - const navNodeWH = this.getScrollWH(navNode) + const navTabsContainer = this.$props.getRef('navTabsContainer') + const navNodeWH = this.getScrollWH(navTabsContainer || navNode) const containerWH = this.getOffsetWH(this.$props.getRef('container')) const navWrapNodeWH = this.getOffsetWH(this.$props.getRef('navWrap')) let { offset } = this @@ -267,7 +271,13 @@ export default { }, render () { const { next, prev } = this - const { prefixCls, scrollAnimated, navWrapper } = this.$props + const { + prefixCls, + scrollAnimated, + navWrapper, + } = this.$props + const prevIcon = getComponentFromProp(this, 'prevIcon') + const nextIcon = getComponentFromProp(this, 'nextIcon') const showNextPrev = prev || next const prevButton = ( @@ -281,7 +291,7 @@ export default { }} onTransitionend={this.prevTransitionEnd} > - + {prevIcon || } ) @@ -295,7 +305,7 @@ export default { [`${prefixCls}-tab-arrow-show`]: showNextPrev, }} > - + {nextIcon || } ) diff --git a/components/vc-tabs/src/TabBarTabsNode.jsx b/components/vc-tabs/src/TabBarTabsNode.jsx index ed3b87920..3ae896d91 100644 --- a/components/vc-tabs/src/TabBarTabsNode.jsx +++ b/components/vc-tabs/src/TabBarTabsNode.jsx @@ -19,7 +19,7 @@ export default { getRef: PropTypes.func.def(noop), }, render () { - const { panels: children, activeKey, prefixCls, tabBarGutter } = this.$props + const { panels: children, activeKey, prefixCls, tabBarGutter, saveRef } = this.$props const rst = [] children.forEach((child, index) => { @@ -43,7 +43,7 @@ export default { if (activeKey === key) { directives.push({ name: 'ref', - value: this.saveRef('activeTab'), + value: saveRef('activeTab'), }) } const tab = getComponentFromProp(child, 'tab') @@ -64,7 +64,14 @@ export default { ) }) - return