The multi-subrow feature in Material-UI tables does not support simultaneous hovering

I have integrated a table from material-ui into my project, similar to the image shown below:

My issue is that when I hover over a specific row in the table, the background color changes to dark. However, some rows may contain sub-rows and I want these sub-rows to also change to a darker background color when hovered over.

Currently, my design structure only allows for the selected table cell to change its background color when hovered, rather than all sub-row's background colors getting darker as well.

I have attempted wrapping the sub-table cells of sub-rows into their own table row or cell using div elements, but this approach did not work. Is there a better way to achieve the desired behavior?

import { Table,TableHead,TableRow,TableCell,TableBody,Divider,makeStyles} from '@material-ui/core'
export default Table = () => {
const subRow=[{a:'test1',b:1},{a:'test2',b:2}]
const tableClasses = useStyles()
  return(


 <Table>
  <TableHead>
    <TableRow>
      <TableCell />
    </TableRow>
  </TableHead>
  <TableBody>
    <TableRow>
      <TableCell>WER</TableCell>
      <TableCell>234</TableCell>

      <TableCell>
        {subRow.map((e, index) => {
          return (
            <div className={tableClasses.subRow}>
              <div> {e.a} </div>
              {index < subCells.length - 1 && <Divider />}
            </div>
          );
        })}
      </TableCell>
      <TableCell>
        {subRow.map((e, index) => {
          return (
            <div className={tableClasses.subRow}>
              <div> {e.a} </div>
              {index < subCells.length - 1 && <Divider />}
            </div>
          );
        })}
      </TableCell>
    </TableRow>
  </TableBody>
</Table>;

)
const useStyles = makeStyles(() => ({
 subRow:{
  '&:hover':{
    backgroundColor: 'red'
 }},
}))
}

Answer №1

When you declare inline styles on an element, there is no need to use a selector because by doing so, you are already selecting the div to apply style. A proper inline style declaration should look like this ->

<div style="background:red;">
.
One limitation of using inline styles is that you can't use pseudo/state selectors such as :hover.

If you want to use those selectors, you have to place your style code in a <style></style> block or a separate css file.

For example, if your code outputs to the browser as a standard HTML <table> element;

<style>
table tbody td:hover {background-color:red;}
/* or if you want to narrow it down to the div... */
table tbody td div:hover {background-color:red;}
</style>

If it still doesn't work, make sure to double-check the classes used to create the table structure and ensure that more specific base UI styles are not overriding your styles.

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

Looking to troubleshoot an error in my TypeScript reducer implementation. How can I fix this issue?

I'm currently using typescript along with react, redux, and typessafe-actions. However, I've come across a particular error that I need help with. The error message reads: "No overload matches this call. Overload 1 of 2, '(...items: Concat ...

What causes the child positioning to break when a CSS-Filter is applied to the parent element?

One of my projects includes a title-screen "animation" where the title is initially centered on a fullscreen page and then shrinks and sticks to the top as you scroll down. I have provided a simplified working example below: $(window).scroll( () => ...

Is it possible to detect when a user reaches the end of a div without using a scroll event?

Seeking a JavaScript solution that can identify when a user reaches the bottom of a div with overflow: auto. While there are numerous solutions on Stack Overflow utilizing the onscroll event, I am curious if this can be accomplished using newer technology ...

Insert an HTML element prior to the content using the ng-bind directive

I am working with a table that is generated by an ng-repeat loop and connected to a model using ng-bind. In the first column, I want to dynamically add an HTML element based on a specific condition. How can I accomplish this? <!doctype html> <htm ...

Utilizing External Libraries in SAPUI5 Extension Development

I am facing an issue while trying to integrate an external library into my UI5 project. Specifically, I am working with jsPDF but it could be any other library as well. I have included it in the manifest.json file in the following manner: "js": [{ ...

Updating form in react requires a double click

I'm facing an issue with the popup form in my note-taking project. The popup form displays when a user wants to edit a note, and it should already contain the contents of the selected note. While the form shows the correct contents, I've noticed ...

Open a new lead form in Crm 2013 by clicking a button and automatically passing the details of the

I have integrated an Add New Lead button into the main form on the Homepage for contacts. Clicking this button triggers a script that opens a new form and passes "Crm Parameter FirstSelectedItemId" as a parameter. By selecting a contact and clicking crea ...

Ways to incorporate a scroll feature and display an iframe using JQuery

Is there a way to animate the appearance of hidden iframes one by one as the user scrolls down the website using jQuery? I have come across some solutions, but they all seem to make them appear all at once. I'm looking for a way to make the iframes s ...

Using a variable to retrieve results from an array leads to an undefined outcome

I am encountering an issue with accessing arrays returned from a `GET` response. The names of these arrays may vary depending on the request, so I have a variable that specifies which array to use. Unfortunately, I keep receiving 'undefined'. Fo ...

The functionality of Jquery is successfully integrated into a specific function, however it seems to only work for one of the calls. To make the other call work,

After a user makes a selection, I am attempting to reset the 'selected' item. This process calls the Vue function tS() shown below. The issue lies with the first call $('#sel1').prop('selectedIndex',0);, as it only seems to wo ...

What is the best way to navigate back on a button click in jquery AJAX without causing a page refresh?

Is there a way to navigate back without refreshing the page? I am fetching data dynamically using AJAX, but when I try to go back using the browser button, it takes me all the way back to the starting point. Let's look at the situation: 3 Different ...

Content displayed in the center of a modal

Struggling to center the captcha when clicking the submit button. Check out the provided jsfiddle for more details. https://jsfiddle.net/rzant4kb/ <script src="https://cdn.jsdelivr.net/npm/@popperjs/<a href="/cdn-cgi/l/email-protection" class=" ...

Transpiler failed to load

My Angular application running on Node has recently encountered a problem with the transpiler. I have been trying to load mmmagic to evaluate uploaded files, but encountered difficulties in the process. While attempting to update NPM packages, I gave up on ...

The TypeScript compiler does not recognize the property 'theme' in this context

I am currently working on a ReactJS starter project using typescript along with material-ui v1.x beta. I have encountered an issue with the themes, which are detailed at: . TypeScript is throwing errors stating that the 'theme' property does not ...

I'm curious, in which environment does SvelteKit, Next.js, and Nuxt.js code execute? Also, is it possible to create HTTP request handlers within

My experience with using SvelteKit in my personal projects has been quite enjoyable. However, coming from a background of working with frameworks like Next.js and Nuxt.js, I often find myself confused about where the code I write actually runs. In my day ...

How can I locate the first word using XPath?

When dealing with the following HTML / XML code: <div class="contentBlock"> <h2> </h2> <h1></h1> <h1>DBS055 - single module packages</h1> </div> I am interested in extracting only the code D ...

Element with a fixed position located inside a column in Bootstrap 4

Is there a way to keep a bar fixed at the bottom of the user's screen, but only within a specific column? Applying position:fixed; bottom:0; stretches the element across the entire screen, so how can I make the bar remain within the column boundaries? ...

Is there a way to incorporate the Indian rupee symbol into a Google chart?

I've been trying to incorporate the Indian Rupee symbol into a Google chart using the code below: var formatter = new google.visualization.NumberFormat({ prefix: '&#8377;' }); However, I'm encountering an issue where ...

Utilizing JavaScript: Passing a parameter into a function to be used with getElementById()

Implementing a feature that displays statistics by incrementing rapidly until reaching their final value when the element is in view, creating the illusion of a rising number. Encountering some difficulty in passing the necessary parameters to identify th ...

Axios failing to include Content-Type in header

I have set up an Odoo instance in the backend and developed a custom module that includes a web controller. Here is the code for the web controller: Web Controller # -*- coding: utf-8 -*- from odoo import http import odoo from odoo.http import Response, ...