-
-
Notifications
You must be signed in to change notification settings - Fork 206
Not fitting, only uses max font size #48
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
Comments
Not sure, probably has to do with vue maybe re-rendering the DOM and fitty losing the element reference? Do you see the same issue outside of Vue. |
I don't think it's a DOM re-rendering problem, the DOM only changes in reaction to model changes. Even then it changes the content (The actual text in this case, which is static), not the styling...etc unless I explicitly set it up to do so. I only call fitty AFTER the DOM has finished rendering the models state. Manually calling fitty after the DOM has been rendered (And no more reactive changes are being made) doesn't seem to resolve the issue either. Fitty changes the element style as expected (Showing that it still has the element reference), but it doesn't seem to want to change the font-size to force the child element to fit in. Only using the max-size each time. If possible, can you move forward with helping me diagnose this under the assumption that the DOM is NOT re-rendering? Testing this without Vue is possible, but it might not be applicable to the use-case, I won't even be using the same styling library... |
@douglasg14b Please understand that Fitty is a free project that seems to work for most use cases, if it doesn't that's unfortunate and while I truly would like to fix/diagnose it, I'm super busy with work that does put bread on the table. I might have time to look into this further somewhere in the next few weeks. |
|
Uh, why close the issue? It hasn't stopped being an issue unfortunately, you specifically said that you are unable to dedicate time to it's discovery at this time due to other obligations. Which I respect. And I don't expect you to solely try and sort this out, but rather assist me in figuring out the cause when the time becomes available. However, it is much more difficult to respect closing issues for the sake of closing issues..... |
@douglasg14b You're absolutely right, I quickly read my last comment this morning and missed the last line. I'll re-open it. |
Thanks! Sorry for the grumpy reply, my Mondays are usually fraught with updating long-standing issues that ProBot is marking as stale... |
@douglasg14b All good ;-) |
Have you tried just doing a call on the element itself from within your Vue component instead of using a directive? I have something like the following working fine in my Vue (Nuxt) project: <template>
<div ref="toFit">Text</div>
</template> <script>
import fitty from 'fitty';
export default {
mounted() {
const fitTitle = fitty(this.$refs.toFit, {
minSize: 24,
maxSize: 70,
});
fitTitle.element.addEventListener('fit', e => {
console.log(e);
});
},
};
</script> |
The same happens inside PowerBI custom visuals. But it's stuck at 18px font size for the minimum font size. It does listen to the max limit. |
I was having similar issues to you, but I took the code @nathanchase suggested and modified it a bit to manually fit the text on the <template>
<div><slot /></div>
</template> mounted() {
const fitText = fitty( this.$el, {
minSize: 24,
maxSize: 72,
} );
fitText.element.addEventListener( 'fit', fitText.fit );
}, I was previously waiting for an arbitrary interval of 25ms but was inconsistent and had visual glitches, this modification has made it consistent without any visual weirdness. But it loops infinitely, which is obviously undesirable. My attempts to remove the event listener early on causes the initial issue to reappear. |
I'm using this inside of a vue directive to try and fix text to it's container, however it does not seem to actually do anything except set the font size to the max I allow.
Watching the
fit
event shows no change even when I manually trigger thefit()
function on the element.The relevant markup looks like:
The
span
that I am usingfitty()
on it larger thandiv 2
since the text causes it to overflow, which seems to be what fitty expects?Other Info:
fit
from the dom changemax-width
, and then callingfit()
, it still does not change the text's size to anything but the maxThe text was updated successfully, but these errors were encountered: