Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(text): prevent always running detect text alignment #579

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/components/Text/src/Text.vue
Original file line number Diff line number Diff line change
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