diff --git a/src/components/ellipsisText/index.tsx b/src/components/ellipsisText/index.tsx index b9370336d..b450e9add 100644 --- a/src/components/ellipsisText/index.tsx +++ b/src/components/ellipsisText/index.tsx @@ -1,7 +1,7 @@ import React, { PureComponent } from "react"; import { Tooltip } from "antd"; -interface Props { +export interface Props { value: string ; title?: string; className?: string; @@ -17,9 +17,13 @@ const initialState = { type State = typeof initialState; -class EllipsisText extends PureComponent { +export interface NewHTMLElement extends HTMLElement { + currentStyle?: CSSStyleDeclaration +} + +export default class EllipsisText extends PureComponent { ellipsisRef: HTMLElement | null = null; - state: State = { + state = { ...initialState }; @@ -45,11 +49,9 @@ class EllipsisText extends PureComponent { return rangeWidth; }; - getStyle = (dom: any, attr: string) => { + getStyle = (dom: NewHTMLElement, attr: string) => { // 兼容IE8 - const stylePadding = dom.currentStyle - ? dom.currentStyle[attr] - : getComputedStyle(dom)[attr]; + const stylePadding = window?.getComputedStyle(dom)[attr] || dom.currentStyle[attr] return stylePadding.slice(0, -2); }; @@ -126,6 +128,4 @@ class EllipsisText extends PureComponent { ); } -} - -export default EllipsisText \ No newline at end of file +} \ No newline at end of file