Is the popup not opening with just one click?

https://i.stack.imgur.com/09dcf.png

Upon clicking the first input cell, the popup opens and closes as expected. However, when closing the initial input and opening another one, an orange mark icon appears but the popup doesn't open until the second click. This issue is present across all input cells, where the popup only opens after the single click. Any help in resolving this matter would be greatly appreciated.

The functionality to close the popup by clicking outside of it is working correctly.

Component file ->

<tr v-for="(row, index) in table" :key="index">
  <td class="dot_td">
    <img :src="row.cell1.imgSrc" />
  </td>
  <th v-html="row.cell2.content">
  </th>
  <td v-for="inputCell in row.inputCells" :key="inputCell.input" :class="inputCell.rectification === 1 ? 'border_td' : ''">
    <input v-bind="inputCell.input" :value="inputCell.inputData">
    <a style="cursor: pointer;" class="request_icon" @click="openPopup($event, inputCell)">
      <svg width="14" height="13" viewBox="0 0 14 13" fill="none" xmlns="http://www.w3.org/2000/svg">
        <path d="M13.5 6.5C13.5 9.77946 10.6254 12.5 7 12.5C3.37461 12.5 0.5 9.77946 0.5 6.5C0.5 3.22054 3.37461 0.5 7 0.5C10.6254 0.5 13.5 3.22054 13.5 6.5Z"
        stroke="#CDCDCD" />
        <path d="M6.46866 10V4.54545H7.53045V10H6.46866ZM7.00488 3.70384C6.82022 3.70384 6.66161 3.64228 6.52903 3.51918C6.39882 3.3937 6.33372 3.24455 6.33372 3.07173C6.33372 2.89654 6.39882 2.7474 6.52903 2.62429C6.66161 2.49882 6.82022 2.43608 7.00488 2.43608C7.18954 2.43608 7.34698 2.49882 7.47718 2.62429C7.60976 2.7474 7.67605 2.89654 7.67605 3.07173C7.67605 3.24455 7.60976 3.3937 7.47718 3.51918C7.34698 3.64228 7.18954 3.70384 7.00488 3.70384Z"
        fill="#CDCDCD" />
      </svg>
    </a>
  </td>
  <td>
    {{ row.totalCell.text }}
  </td>
</tr>

Script ->

<script setup>
const openPopup = (event, inputCell) => {
    const iconbtn = event.currentTarget;
    const popup = document.getElementById('request_popup');
    
    userComment.value = inputCell.commentData;
    UsercommentDate.value = inputCell.UsercommentDate;
    currentInputCell.value = inputCell;
    managerComment.value = inputCell.Managercomment;
    isPopupVisible.value = !isPopupVisible.value;
    const rect = iconbtn.getBoundingClientRect();

    if (isPopupVisible.value) {
        iconbtn.classList.add('requested');
        popupStyle.top = rect.bottom + window.scrollY + 'px';
        popupStyle.left = rect.left + window.scrollX + 'px';

        // Adding an event listener to close the popup on outside click
        const closePopupOnOutsideClick = (event) => {
            const isClickInsidePopup = iconbtn.contains(event.target) || popup.contains(event.target);
            if (!isClickInsidePopup) {
                closePopup(iconbtn);
                document.removeEventListener('click', closePopupOnOutsideClick);
            }
        };

        document.addEventListener('click', closePopupOnOutsideClick);
        
    }else{
        isPopupVisible.value = false;
        iconbtn.classList.remove('requested');
    }
    
};

const closePopup = (iconbtn) => {
    isPopupVisible.value = false;
    if(iconbtn){
    iconbtn.classList.remove('requested');
    }
};
<script>

Answer №1

To improve the function of detecting clicks outside, consider using a blur event instead of creating additional functionality. Use

iconbtn.addEventListener('blur', closePopupOnOutsideClick);

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

Unexpected value detected in D3 for translate function, refusing to accept variable

I'm experiencing a peculiar issue with D3 where it refuses to accept my JSON data when referenced by a variable, but oddly enough, if I print the data to the console and manually paste it back into the same variable, it works perfectly fine. The foll ...

Connecting an onclick event to trigger an external file

I have a scenario where I need to link an array of buttons with respective mp3 files. For example, if button number 5 is clicked, the 5th mp3 file should be played. How can I modify the code below to achieve this functionality? Any examples or suggestions ...

Attempting to pass data to a v-for loop in Vue, but it seems like I am overlooking a crucial detail

Is it correct to use v-for in HTML or should I not use v-for in Vue3? The 'items:' is defined but never used, but when I try to use it in iteration with v-for, how can I fix this issue? I am unsure of the proper way to do it. <template> ...

Choose an item from a list that does not have a particular class

Here is a list of items: <ul id='myList'> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <li class='item-selected'>Item 4</li> <li>Item 5</li> & ...

Receive a warning in the Heroku log stating "(node) sys is outdated. Util should be used instead" while the script is executed

I recently deployed a Node script on Heroku to be executed by a scheduler. However, upon running the script, I noticed a warning message in the logs. Dec 07 11:01:10 xxx heroku/scheduler.3255 Starting process with command `node bin/script` Dec 07 11:01:1 ...

Refreshing information within a table using Ajax Prototype

For my current project, I am utilizing PrototypeJS. I have implemented Ajax.PeriodicalUpdater to insert real-time data as required. However, I am facing an issue where the data is not getting replaced inside a specific table. Below is the HTML code snippet ...

Interact with multidimensional arrays using Vue JS

Is there a way to access properties within objects nested inside multidimensional arrays when using v-for with VueJS? var arr =[{"fruit": {"fruitName": "apple"}, "vegetable":[{"vegetableName": "carrot" }]}]; I am attempting to display it in the following ...

When working with React, encountering a "TypeError: is not a function" message from a function prop can

I am a beginner with React and I'm attempting to pass a function as a prop to a child component. In this scenario, the parent component looks like this: const [gameStarted, setGameStarted] = useState(false); const [gameSettings, setGameSettings] = use ...

When using React with Firebase, remember to specify the "to" property when using setState to avoid errors

Struggling to figure out what's going wrong after hours of trying. I'm new to React and would really appreciate your help. Initially, my state was an array of accommodations which I mapped over successfully. However, once I connected Firebase wit ...

What is the best way to display div elements based on a selected option?

Here is the code for a select list that contains the number of guests for a room: <select name="txtHotelGuestNO" id="txtHotelGuestNO" class="hotels" onchange="show_room_choose()"> <?php for($i=1;$i<=100;$i++) echo "<option value=$i>$ ...

Securing '/login' and '/login/' as well as '/dashboard' and '/dashboard/' in vue-router

I've implemented a routeguard using vue-router in my system. The guard redirects users with a token back to the dashboard if they try to access the /login or /login/ routes, and vice versa for users without a token. router.js router.beforeEach((to, ...

How can I use JavaScript to disable a table row and then save the selected option in a MySQL database?

I have a PHP snippet that dynamically displays table rows. Each row contains a radio button with "Yes" and "No" options. I have implemented a JS function where, upon choosing an option, a pop-up box is displayed. If the user selects the "Yes" option in t ...

Callback after completion of a for loop in Angular TypeScript

During the execution of my javascript async function, I encountered a situation where my printing code was running before the div creation. I needed to ensure that my print code would run only after the completion of the for loop, but I struggled to find a ...

What is the importance of having references to maintain the existence of mutable objects?

In the documentation for useRef, it is mentioned that this hook is useful for storing mutable values. I've been thinking, why can't we just use a variable in the outer scope of the component to achieve the same result? // the object I want to st ...

What exactly does a 'hoisted manifest' mean when it comes to using Yarn?

Encountering an issue while attempting to install a package using yarn, I am receiving the error message: expected hoisted manifest for \"myPackage#@material-ui/core#react-dom\" However, the concept of a 'hoisted manifest' is not entir ...

Remove the ability to select from the dropped list item

Here is the HTML and Javascript code I used to enable drag and drop functionality for list items from one div to another: HTML: <div class="listArea"> <h4> Drag and Drop list in Green Area: </h4> <ul class="unstyle"> & ...

How to import a JSON file in AngularJS using Node.js

I am currently working with NodeJS and AngularJS to handle some data. Within my Angular application, I am trying to access a JSON file and distribute its content into separate controllers. Right now, I am utilizing the http.get method within a controller ...

The addDays method cannot be used with date variables

Having two TextBoxes where I input 2 dates and try to retrieve an array of dates between them. Here is the code I'm using: $(".txtto").change(function () { var dates = new Array(); var dateto = new Date(); ...

Promise disregards the window being open

I'm facing an issue with redirecting users to Twitter using window.open in a specific function. It seems like the instruction is being ignored, even though it works perfectly on other pages. Any ideas on how to fix this? answerQuestion() { if ...

Adjust the color of input labels using jQuery validate

I have a form where I want to change the class of the input labels when a specific field fails validation. My goal is to add the 'error' class to the spans that are directly above any invalid form elements. Here is an example of my HTML structur ...