What is causing this unique component to be positioned outside of the <tr> tag?

table.vue

...
        <tbody class="table-body">
            <slot></slot>
        </tbody>
...

TableCellRow.vue

<template>
    <td class="table-row-cell" :class="this.class">
        <slot></slot>
    </td>
</template>

My attempt to use it:

<my-table>
                <template #default>
                    <tr>
                        <td>i am inside the tr</td> <----- this is inside the <tr>
                            <table-row-cell> <-------- this is outside of the <tr>
                                    i am outside the tr
                            </table-row-cell>
                    </tr>
                </template>
            </my-table>

and like this:

            <my-table>
                <tr>
                    <td>i am inside the tr</td>
                    <table-row-cell>
                        i am outside the tr
                    </table-row-cell>
                </tr>
            </my-table>

In this latest scenario, this is what happens:

<tbody class="table-body"> i am inside the tr <td class="table-row-cell"> i am outside the tr </td></tbody>

And in the first instance I observe this:

<tbody class="table-body"><tr><td>i am inside the tr</td></tr><td class="table-row-cell"> i am outside the tr </td></tbody>

I've also attempted just this:

            <my-table><template #default>
                <tr>
                    <table-row-cell>
                        i am outside the tr
                    </table-row-cell>
                </tr>
            </template>
</my-table>

But still get this outcome:

<tbody class="table-body"><tr></tr><td class="table-row-cell"> i am outside the tr </td></tbody>

So what could be going wrong? Am I unable to utilize a component within a <tr> tag that solely contains another <tr> tag? Why does Vue present this behavior? I only want to insert a <table-row-cell> into the slot of my customized table and include a custom <td> component within that - why is it proving to be so challenging? Am I overlooking something obvious? Both components seem correctly implemented, so what seems to be the issue?

To illustrate the problem locally, here's the simplest example:

<table class="i-am-the-example-table">
            <tbody>
                <tr class="i-am-the-tr-hello">
                    <table-row-cell>
                        i am external to the TABLE itself, for some unknown reason
                    </table-row-cell>
                </tr>
            </tbody>
        </table>

tableRowCell component:

<template>
    <td>
        <slot></slot>
    </td>
</template>

Component globally registered:

import TableRowCell from "./components/custom/Tables/TableRowCell.vue";
app.component("TableRowCell", TableRowCell);

The visual representation on my side can be seen here: https://i.sstatic.net/3s7mm9lD.png

Answer №1

Since the original poster is not utilizing bundlers (meaning no .vue files), the solution is to follow these steps:

<tbody>
  <tr is="vue:tab-descgen" ></tr>
</tbody>

Hats off to the solution provided here. I have enhanced the response by including more specifics on why this issue occurs and adapting it to reflect the recent Vue3 modifications!

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

Steps for displaying a loading gif animation prior to retrieving text content using JavaScript

Before fetching the PHP result, I want a loading GIF image to display within the div section. <!DOCTYPE html> <html> <head> <title> CTR Calculator Tool | Free Click Through Rate Online Calculator </title> & ...

Ensure all <li> tags within a HTML document exhibit consistent jquery mousedown and hover effects, abstaining from the assignment of unique IDs to each

I understand that this approach might not be correct, but I wanted to create a simulation of what I am trying to achieve. Is there a way for each <li> element within a specific <ul class="myul"> to have separate mousedown, mouseout, hover effe ...

Transfer an Array of Objects containing images to a POST API using Angular

Looking to send an array of objects (including images) to a POST API using Angular and Express on the backend. Here's the array of objects I have: [{uid: "", image: File, description: "store", price: "800"} {uid: "f ...

Simulate a keyboard key being pressed and held for 5 seconds upon loading the page

Is it possible to create a script that automatically triggers an event to press and hold down the Space key for 5 seconds upon page load, without any user interaction? After the 5 seconds, the key should be released. It is important to emphasize that abso ...

Struggling to retrieve the header in Angular 6

When setting headers from an Express server written in NodeJS, I use the following code: app.use('/routes', function(req, res, next) { res.setHeader('test', 'test'); next(); ); The headers are successfully sent to th ...

Below are the steps to handle incorrect input after receiving only one letter:

H-I This is my input .centered-name { width: 80%; margin: auto; } .group { width: 100%; overflow: hidden; position: relative; } .label { position: absolute; top: 40px; color: #666666; font: 400 26px Roboto; cursor: text; transit ...

When using mongoose, is it possible to add a new item and retrieve the updated array in one endpoint?

My API endpoint for the post operation query using mongoose is not returning the updated array after adding a new item. I have been struggling with this issue for 3 days without any success. Any help would be greatly appreciated. router.post("/:spot ...

What is the best way to display a div based on a keyword match?

If the keyword search results in a match, I can display the corresponding input text and its related category div. Now, I am attempting to also search through category names. If the searched keyword matches a category name, that specific div should be visi ...

Displaying the state in NextJS rather than revealing server error messages

I recently implemented a register page on my NextJS app where users can input their information. Once the registration is successful, the form clears and a success message is displayed. However, I encountered an issue after adding the success message. Now ...

What are your thoughts on the size of a React component being 500 lines long?

Currently, I am in the process of constructing a Table component that includes filters and requires an extensive amount of logic. Additionally, I have incorporated material UI which tends to add multiple lines of code. Despite these elements, I feel that ...

Accessing the variable's value within a separate if statement within the function

I have a function that retrieves data from JSON and passes it to render, but I had to include two different conditions to process the data. Below is the function: filterItems = () => { let result = []; const { searchInput } = this.state; c ...

Convert HTML Tables to PDF Format

I am facing an issue with exporting my table data into a PDF using jQuery. I have made sure to install all the necessary library files, but my code doesn't seem to be working correctly. Can anyone spot any errors in my code or suggest what might be mi ...

Optimize Material-UI input fields to occupy the entire toolbar

I'm having trouble getting the material-ui app bar example to work as I want. I've created a CodeSandbox example based on the Material-UI website. My Goal: My goal is to make the search field expand fully to the right side of the app bar, regar ...

The ng-model directive in drop-down selection elements

I have a series of questions along with their answers, and I want the user to select an answer from a drop-down menu. How can I achieve this? I've attempted the following code, but the select option isn't appearing on the screen. HTML: <div ...

Displaying incorrect field names to the user during Angular validation

I've been tasked with implementing validation in my Angular app, and I need to show a popup listing all invalid fields upon form submission. This directive comes straight from my boss, so I have no say in the matter. Currently, I have a method that r ...

I would like to know the best approach to utilizing a PHP array or JSON response within JavaScript

Let me present my workflow briefly. While I initiate an Ajax call from the index.phtml file, the Ajax response is as follows: Array ( [Data] => Array ( [0] => Array ( [PlayerId] => 20150 ...

Is there a way to store div content in a PHP Session?

Just starting to learn php & ajax, so be patient with me. I have a clickable map. When the user clicks on a point, the value is displayed in a div. Once they select a point, they should be able to proceed to the next step. Now I want to save the content ...

How can I add information into a nested div element?

I encountered an issue when attempting to insert data into my block. The div structure is as follows: <div class="1"> <div class="2"> <div class="3"> <div class="4"></div> </div> ...

"Explore a different approach to file uploading with React Native JavaScript by using either blob or base64 encoding

I am in the process of uploading visuals. When I employ this technique, it functions as expected: formData.append("file",{uri,type,name}); Yet, I prefer not to transmit my visual using the URI. My intention is to divide the visual into distinct sections ...

error: encountering issue with Vue TypeScript Jest tests - '$store' property is undefined

I've been facing issues with my tests failing after a recent npm install. I've tried adjusting versions up and down, but haven't had any success. Interestingly, the $store isn't directly used in any of the components or tests. Despit ...