Skip to content

Commit

Permalink
fix(text): prevent always running detect text alignment (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
wkashdan committed Mar 26, 2024
1 parent f367505 commit c30f147
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/components/Text/src/Text.vue
Expand Up @@ -123,7 +123,7 @@ export default {
data() {
return {
isCentered: false,
isCenteredAndSpaced: false,
};
},
Expand Down Expand Up @@ -204,19 +204,19 @@ export default {
if (this.resolvedLetterSpacing !== 'inherit') {
styles.letterSpacing = this.resolvedLetterSpacing;
}
if (this.isCentered) {
if (this.isCenteredAndSpaced) {
styles.paddingLeft = styles.letterSpacing;
}
return styles;
},
},
mounted() {
this.detectAlignCenter();
this.detectAlignCenterAndLetterSpacing();
},
updated() {
this.detectAlignCenter();
this.detectAlignCenterAndLetterSpacing();
},
methods: {
Expand All @@ -227,10 +227,14 @@ export default {
* Detect if the text is center aligned and add left padding
* to balance out the letter spacing
*/
detectAlignCenter() {
detectAlignCenterAndLetterSpacing() {
if (!this.resolvedLetterSpacing) {
return;
}
const computedStyle = window.getComputedStyle(this.$el);
const textAlign = computedStyle.getPropertyValue('text-align');
this.isCentered = textAlign === 'center';
this.isCenteredAndSpaced = textAlign === 'center';
},
},
Expand Down

0 comments on commit c30f147

Please sign in to comment.