What is the best way to retrieve the current CSS width of a Vue component within a flexbox layout grid after it has been modified?

There's something about this Vue lifecycle that has me scratching my head. Let me simplify it as best I can.

I've got a custom button component whose size is controlled by a flex grid container setup like this:

<template>
        <div class="component d-flex flex-column flex-grow-1" style="min-height: 0">
            <div class="justify-center align-content-center"
            style="display: grid; width: 100%; height: 100%; grid-gap: 1rem;
            grid-template-columns: repeat(12, minmax(0, 1fr));
            grid-template-rows: repeat(8, minmax(0, 1fr));">
                <slot/>
            </div>
        </div>
    </template>
    

The grid panel structure resembles this:

<template>
        <v-card :style="cardStyle" v-bind="$attrs">
            <slot></slot>
        </v-card>
    </template>

    <script>
    export default {
        computed: {
            cardStyle: function() {
                return 'grid-column: span ' + (this.columns || 2) +
                '; grid-row: span ' + (this.rows || 2) + ';';
            }
        },
        props: {
            columns: [Number, String],
            rows: [Number, String],
        }
    }
    </script>
    

My button utilizes the panel for sizing in this manner:

<template>
        <grid-panel ref="elm" :columns='columns || 2' :rows='rows || 2' elevation="0">
            <v-btn class="ma-0 align-stretch flex-column py-4"
            width="100%" max-width="100%" height="100%" :color="color || 'rgba(0,0,0,0)"'>

                <div class="d-flex fill-height py-2" style="width:100%">
                    <div ref="iconTest" class="fill-height">
                        <v-icon ref="icon" class="mb-0 flex-shrink-1 notransition py-0 pr-2" :color="iconColor" style="width:auto; height:auto">{{ icon }}</v-icon>
                    </div>
                    <div ref="text" class="flex-grow-1 d-flex align-center text-center">
                        <span ref="innerSpan" style="font-size: 1px" class="textFitted text-center d-inline-block notransition">
                            {{ label }}
                        </span>
                    </div>
                </div>
            </v-btn>
        </grid-panel>
    </template>
    

It may seem complicated, but hang tight.

Answer №1

Upon discovering that the issue was caused by slow loading fonts, the solution became clear:

mounted() {
    this.isMounted = true;
    document.fonts.ready.then(() => {
        console.log('All fonts loaded!');
        this.updateSizes();
    })
    //this.updateSizes();
},

This resolved the issue. Although I wish the fonts would load quicker, I am satisfied that this fix is effective.

Answer №2

Consider using the ResizeObserver to solve your issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Which is the better option for setting a title: using .prop or .attr?

I came across a comment that mentioned The suggestion was to utilize the .prop() method instead of .attr() when setting the "title" property in jQuery versions 1.6 or newer. Could someone provide an explanation for this recommendation? ...

Establishing a proxy server to support the development of a Create React application

Recently, I initiated a react application with the help of create-react-app. Following that, I executed the npm run eject script to unlock access to all files. Subsequently, I incorporated express and crafted a server.js file which is located on the same l ...

Using Blob to save CSV file on Safari

Here are the codes I am using to generate a download link for users to download a .csv file from my website. var link = document.createElement("a"); link.id = "csvDwnLink"; window.URL = window.URL || window.webkitURL; var csv = "\ufeff" + CSV, b ...

Best practices for uploading an array of objects (multiple image files) using Node.js

Encountering an issue in my application where I need to upload multiple photos. The object consists of motherPhoto, fatherPhoto, spousePhoto, and siblingsPhoto: { "mothername": "kerin", "motherPhoto": "C:/fakepath/mot ...

Text box input that displays the latter portion before the initial part

Looking for assistance with showing the end of the entered text rather than the beginning in an input field. For example, the input could be "Starting portion, Ending Portion". If the input field is limited to 14 characters, instead of displaying the firs ...

I am unable to achieve negative X degree rotation of the image while using mousemove to rotate it

I need assistance with moving a picture in 3D. I want the offsetX of the mouse to be positive when it's past half of the picture, and negative otherwise. How can I achieve this effect for rotation degrees? This is what I have tried: $('#img ...

What could be the issue with my interactive dropdown menu?

I am currently experiencing an issue with a drop down list that is supposed to fetch records from a column in another table, but no records are appearing. Additionally, I would like to add an option in the drop down list labeled "others" for users to inp ...

Tips for embedding a script into an HTML document

I've been experimenting with tinymce npm and following their guide, but I've hit a roadblock. Including this line of code in the <head> of your HTML page is crucial: <script src="/path/to/tinymce.min.js"></script>. So, I place ...

Enhancing gallery user experience with jquery to animate the opacity of active (hovered) thumbnails

I am attempting to create an animation that changes the opacity of thumbnails. By default, all thumbnails have an opacity of 0.8. When hovered over, the opacity should increase to 1 and then return to 0.8 when another thumbnail is hovered over. Here is th ...

Seeking guidance on resolving issues with this div table

After almost getting everything set up, I encountered some strange issues that have been difficult to resolve. The challenges I'm facing include: The spacing on the right side is too large. Tables always appear stacked without any spacing in bet ...

Customize MUI 5 input label background color for your own component

Struggling with overriding the background color for a MUI 5 input label on focus in a specific component? I successfully changed it to blue globally in my _theme.js file, but now need to make it red for my KeywordSearchTextField in index.js following MUI ...

Stop flex child from shrinking in size

I have a form row with two inputs. There is a requirement to show ⚠️ (warning emoji) next to the second input in the row, based on the input number. However, because of how flexbox behaves, the input size gets reduced... How can I maintain the input s ...

Make the checkbox font-weight bold when it is checked

Attempting to apply custom CSS to enhance the appearance of checkboxes using input and label elements. The goal is to make the font-weight bold when a user clicks on the checkbox, and then revert it back to regular if clicked again. Currently stuck on this ...

Retrieve the $ionicConfigProvider within a Controller

In my controller file named ProfileController.js, I am trying to change the text of the back button. After doing some research, I found this code snippet: $ionicConfigProvider.backButton.text('Go Back').icon('ion-chevron-left'); How can ...

Determining the visibility of an element on a webpage using JavaScript and Puppeteer

I've created a framework that scans websites hosted on our servers to ensure they comply with our policies. If any prohibited content is found, we capture a screenshot along with other relevant details. However, taking a screenshot may not be possibl ...

Creating webpages dynamically by utilizing Javascript

I need assistance with a task involving a list of elements that allows users to print only the clicked element, rather than the entire page. The elements are structured as follows: <div class="element" id="#element1">Element 1</div> <div cl ...

Issue with font icons not displaying properly on Firefox

In Firefox, the icon is not displaying in the center, but it works fine in Opera. body { height: 100vh; display: grid; place-items: center; } .link { background-color: red; padding: 3px; display: grid; place-items: center; ...

Personalize rejection message in the context of Promise.all()

Hello, I am currently working on customizing the error response in case a promise from an array fails. After referencing Handling errors in Promise.all, I have come up with the following code. However, I may need to make some adjustments to achieve the de ...

Styling your div elements in CSS to shrink in width relative to their parent container

.container { max-width: 750px; height: 100px; background-color: red; margin: 0; padding: 0; } .box1 { width: 100px; height: 100%; float: left; background-color: black; } .box2 { width: 650px; height: 100%; fl ...

JavaScript is failing to update the table values as users interact with it

I've created an HTML table and used PHP to populate the values. The goal is to allow users to update order statuses with a status and message input. Initially it works fine, but after multiple uses, it either updates the wrong row or doesn't up ...