Skip to content

Commit 0e0d775

Browse files
author
kongshan
committed
feat: change getStyle advanced attributes preferred
1 parent 5f05458 commit 0e0d775

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/components/ellipsisText/index.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { PureComponent } from "react";
22
import { Tooltip } from "antd";
33

4-
interface Props {
4+
export interface Props {
55
value: string ;
66
title?: string;
77
className?: string;
@@ -17,9 +17,13 @@ const initialState = {
1717

1818
type State = typeof initialState;
1919

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> {
2125
ellipsisRef: HTMLElement | null = null;
22-
state: State = {
26+
state = {
2327
...initialState
2428
};
2529

@@ -45,11 +49,9 @@ class EllipsisText extends PureComponent<Props, State> {
4549
return rangeWidth;
4650
};
4751

48-
getStyle = (dom: any, attr: string) => {
52+
getStyle = (dom: NewHTMLElement, attr: string) => {
4953
// 兼容IE8
50-
const stylePadding = dom.currentStyle
51-
? dom.currentStyle[attr]
52-
: getComputedStyle(dom)[attr];
54+
const stylePadding = window?.getComputedStyle(dom)[attr] || dom.currentStyle[attr]
5355

5456
return stylePadding.slice(0, -2);
5557
};
@@ -126,6 +128,4 @@ class EllipsisText extends PureComponent<Props, State> {
126128
</Tooltip>
127129
);
128130
}
129-
}
130-
131-
export default EllipsisText
131+
}

0 commit comments

Comments
 (0)