Skip to content

Commit

Permalink
feat: change getStyle advanced attributes preferred
Browse files Browse the repository at this point in the history
  • Loading branch information
kongshan committed Jan 15, 2021
1 parent 5f05458 commit 0e0d775
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/components/ellipsisText/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { PureComponent } from "react";
import { Tooltip } from "antd";

interface Props {
export interface Props {
value: string ;
title?: string;
className?: string;
Expand All @@ -17,9 +17,13 @@ const initialState = {

type State = typeof initialState;

class EllipsisText extends PureComponent<Props, State> {
export interface NewHTMLElement extends HTMLElement {
currentStyle?: CSSStyleDeclaration
}

export default class EllipsisText extends PureComponent<Props, State> {
ellipsisRef: HTMLElement | null = null;
state: State = {
state = {
...initialState
};

Expand All @@ -45,11 +49,9 @@ class EllipsisText extends PureComponent<Props, State> {
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);
};
Expand Down Expand Up @@ -126,6 +128,4 @@ class EllipsisText extends PureComponent<Props, State> {
</Tooltip>
);
}
}

export default EllipsisText
}

0 comments on commit 0e0d775

Please sign in to comment.