Skip to content

Commit 795f439

Browse files
committed
Fix #49
1 parent 4c8e42b commit 795f439

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var TextTruncate = require('react-text-truncate'); // CommonJS or UMD
4141
Please polyfill `requestAnimationFrame` before you called `<TextTruncated />`
4242

4343
## Changelog
44+
* 0.10.2 Fix truncated wrong when font property changed
4445
* 0.10.1 Fix unknown prop `element`
4546
* 0.10.0 Allow pass `element` to specify root element type
4647
* 0.9.3 Fix SSR window not found (removed raf polyfill)

lib/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@
107107
}
108108
_this.rafId = window.requestAnimationFrame(_this.update.bind(_this));
109109
}, _this.update = function () {
110+
var style = window.getComputedStyle(_this.scope);
111+
var font = [style['font-weight'], style['font-style'], style['font-size'], style['font-family']].join(' ');
112+
_this.canvas.font = font;
110113
_this.forceUpdate();
111114
}, _temp), _possibleConstructorReturn(_this, _ret);
112115
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-text-truncate",
3-
"version": "0.10.1",
3+
"version": "0.10.2",
44
"description": "Truncate text for React.js",
55
"main": "lib/index.js",
66
"scripts": {

src/TextTruncate.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ export default class TextTruncate extends Component {
5151
};
5252

5353
update = () => {
54+
const style = window.getComputedStyle(this.scope);
55+
const font = [
56+
style['font-weight'],
57+
style['font-style'],
58+
style['font-size'],
59+
style['font-family']
60+
].join(' ');
61+
this.canvas.font = font;
5462
this.forceUpdate();
5563
};
5664

0 commit comments

Comments
 (0)