1
1
import React , { PureComponent } from "react" ;
2
2
import { Tooltip } from "antd" ;
3
3
4
- interface Props {
4
+ export interface Props {
5
5
value : string ;
6
6
title ?: string ;
7
7
className ?: string ;
@@ -17,9 +17,13 @@ const initialState = {
17
17
18
18
type State = typeof initialState ;
19
19
20
- class EllipsisText extends PureComponent < Props , State > {
20
+ export interface NewHTMLElement extends HTMLElement {
21
+ currentStyle ?: CSSStyleDeclaration
22
+ }
23
+
24
+ export default class EllipsisText extends PureComponent < Props , State > {
21
25
ellipsisRef : HTMLElement | null = null ;
22
- state : State = {
26
+ state = {
23
27
...initialState
24
28
} ;
25
29
@@ -45,11 +49,9 @@ class EllipsisText extends PureComponent<Props, State> {
45
49
return rangeWidth ;
46
50
} ;
47
51
48
- getStyle = ( dom : any , attr : string ) => {
52
+ getStyle = ( dom : NewHTMLElement , attr : string ) => {
49
53
// 兼容IE8
50
- const stylePadding = dom . currentStyle
51
- ? dom . currentStyle [ attr ]
52
- : getComputedStyle ( dom ) [ attr ] ;
54
+ const stylePadding = window ?. getComputedStyle ( dom ) [ attr ] || dom . currentStyle [ attr ]
53
55
54
56
return stylePadding . slice ( 0 , - 2 ) ;
55
57
} ;
@@ -126,6 +128,4 @@ class EllipsisText extends PureComponent<Props, State> {
126
128
</ Tooltip >
127
129
) ;
128
130
}
129
- }
130
-
131
- export default EllipsisText
131
+ }
0 commit comments