diff --git a/components/affix/index.tsx b/components/affix/index.tsx index e1fe20aab4..77a679ae85 100644 --- a/components/affix/index.tsx +++ b/components/affix/index.tsx @@ -20,7 +20,7 @@ function getScroll(target, top) { return ret; } -function getTargetRect(target) { +function getTargetRect(target): any { return target !== window ? target.getBoundingClientRect() : { top: 0, left: 0, bottom: 0 }; @@ -55,6 +55,7 @@ export interface AffixProps { offsetBottom?: number; style?: React.CSSProperties; onChange?: (affixed?: boolean) => any; + target?: () => Window | HTMLElement; } export default class Affix extends React.Component { @@ -123,7 +124,8 @@ export default class Affix extends React.Component { // Backwards support offsetTop = offsetTop || offset; const scrollTop = getScroll(targetNode, true); - const elemOffset = getOffset(ReactDOM.findDOMNode(this), targetNode); + const affixNode = ReactDOM.findDOMNode(this) as HTMLElement; + const elemOffset = getOffset(affixNode, targetNode); const elemSize = { width: this.refs.fixedNode.offsetWidth, height: this.refs.fixedNode.offsetHeight, @@ -150,7 +152,7 @@ export default class Affix extends React.Component { position: 'fixed', top: targetRect.top + offsetTop, left: targetRect.left + elemOffset.left, - width: ReactDOM.findDOMNode(this).offsetWidth, + width: affixNode.offsetWidth, }); this.setPlaceholderStyle(e, { width: affixNode.offsetWidth, @@ -166,7 +168,7 @@ export default class Affix extends React.Component { position: 'fixed', bottom: targetBottomOffet + offsetBottom, left: targetRect.left + elemOffset.left, - width: ReactDOM.findDOMNode(this).offsetWidth, + width: affixNode.offsetWidth, }); this.setPlaceholderStyle(e, { width: affixNode.offsetWidth, diff --git a/components/back-top/index.tsx b/components/back-top/index.tsx index 72339bd8eb..f8a5873056 100644 --- a/components/back-top/index.tsx +++ b/components/back-top/index.tsx @@ -26,17 +26,11 @@ function getScroll(target, top) { interface BackTopProps { visibilityHeight?: number; onClick?: (event) => void; + target?: () => HTMLElement | Window; prefixCls?: string; className?: string; } -export default class BackTop extends React.Component { - - static propTypes = { - visibilityHeight: React.PropTypes.number, - target: React.PropTypes.func, - } - export default class BackTop extends React.Component { static defaultProps = { onClick() {}, @@ -71,7 +65,7 @@ export default class BackTop extends React.Component { document.body.scrollTop = value; document.documentElement.scrollTop = value; } else { - targetNode.scrollTop = value; + (targetNode as HTMLElement).scrollTop = value; } }