It is proving challenging to fully eliminate top and bottom padding in MUI TableCell in order to enable clickable whole cell content

I've been working on making the content of my table cells clickable for routing within my app, and I've made some progress in removing unclickable horizontal space by adjusting padding. However, I'm still facing issues with unclickable space on the top and bottom of certain cells.

After inspecting elements and trying different styling approaches, including specific adjustments for MuiTableCell-sizeSmall, the vertical space between rows remains unresponsive to clicks. Why is this happening?

//Styling

const useStyles = makeStyles(theme => ({
  table: {
    minWidth: 650,
    position: 'relative',
    fontSize: 10
  },
  largeIcon: {
    width: 60,
    height: 60
  },
  tableContainer: {
    minHeight: 320
  },
  tableBodyContainer: {
    minHeight: 265
  },
  tableHeadRow: {
    '& .MuiTableCell-root': {
      borderRight: `1px solid ${COLORS.WHITE}`,
      borderBottom: `none`,
      padding: '8px 5px 8px',
      fontSize: 10,
      cursor: 'pointer'
    }
  },
  arrow: {
    color: theme.palette.grey[500]
  },
  arrowActive: {
    transform: 'rotate(-180deg)',
    color: theme.palette.primary.main,
    display: 'inline-block'
  },
  tableRow: {
    '& .MuiTableCell-root': {
      borderRight: `1px solid ${theme.palette.grey[200]}`,
      borderBottom: 'none',
      minWidth: 25,
      padding: 0
    },
    '& .MuiTableCell-root:first-child': {
      border: 'none',
      padding: 0
    },
    '& .MuiTableCell-sizeSmall': {
      padding: 0
    }
  },
  selectedRow: {
    backgroundColor: `${COLORS.SECONDARY} !important`,
    '& .MuiTableCell-root': {
      color: COLORS.WHITE
    }
  }
}));

// table code

return (
    <div className={classes.tableContainer}>
      <TableContainer className={classes.tableBodyContainer}>
        <Table className={classes.table} size="small">
          <TableHead>
            <TableRow className={classes.tableHeadRow}>
              <TableCell />
              {tableHeadElements.map(e => (
                <TableCell key={e.key} align="center">
                  {e.label}
                </TableCell>
              ))}
            </TableRow>
          </TableHead>
          <TableBody>
            {folders?.items.map((folder: IFolderDTO, index: number) => {
              const { id, name, updatedAt } = folder;
              return (
                <TableRow
                  className={classes.tableRow}
                  classes={{ selected: classes.selectedRow }}
                  selected={selectedRow === id}
                  onClick={() => setSelectedRow(id)}
                  key={index}
                >
                  <TableCell align="center">
                    <Link to={APP_DASHBOARD_CHILD_FOLDER_CONTENTS_PATH(id)}>
                      <Box>
                        <IconButton color="default" size={'medium'}>
                          <FolderIcon fontSize="default" />
                        </IconButton>
                      </Box>
                    </Link>
                  </TableCell>
                  {[name, new Date(updatedAt)].map(cell => (
                    <TableCell key={index} align="center">
                      <Link to={APP_DASHBOARD_CHILD_FOLDER_CONTENTS_PATH(id)}>
                        <Box>{getCorrectFormat(cell)}</Box>
                      </Link>
                    </TableCell>
                  ))}
                  <FolderActionsMenu
                    folderId={id}
                    onDeleteFolder={onDeleteFolder}
                    openDialogWithId={openDialogWithId}
                  />
                </TableRow>
              );
            })}
          </TableBody>
        </Table>
      </TableContainer>
      <FolderFormDialog />
    </div>
  );
};

Answer №1

Do you require a straightforward demonstration of a compact table without any extras?

    import * as React from 'react';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
import Paper from '@mui/material/Paper';

function createData(name, calories, fat, carbs, protein) {
  return { name, calories, fat, carbs, protein };
}

const rows = [
  createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
  createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
  createData('Eclair', 262, 16.0, 24, 6.0),
  createData('Cupcake', 305, 3.7, 67, 4.3),
  createData('Gingerbread', 356, 16.0, 49, 3.9),
];

export default function CompactTable() {
  return (
    <TableContainer component={Paper}>
      <Table sx={{ minWidth: 650 }} size="small" aria-label="a dense table">
        <TableHead>
          <TableRow>
            <TableCell>Dessert (100g serving)</TableCell>
            <TableCell align="right">Calories</TableCell>
            <TableCell align="right">Fat&nbsp;(g)</TableCell>
            <TableCell align="right">Carbs&nbsp;(g)</TableCell>
            <TableCell align="right">Protein&nbsp;(g)</TableCell>
          </TableRow>
        </TableHead>
        <TableBody>
          {rows.map((row) => (
            <TableRow
              key={row.name}
              sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
            >
              <TableCell component="th" scope="row">
                {row.name}
              </TableCell>
              <TableCell align="right">{row.calories}</TableCell>
              <TableCell align="right">{row.fat}</TableCell>
              <TableCell align="right">{row.carbs}</TableCell>
              <TableCell align="right">{row.protein}</TableCell>
            </TableRow>
          ))}
        </TableBody>
      </Table>
    </TableContainer>
  );
}

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

Setting a const value (true or false) based on the size of the window - a step-by-step guide

While studying, I encountered a challenge: In the code below, I need to dynamically set useState(false) based on the screen size. If the screen is larger than 947px, for instance, it should automatically be changed to true. The issue arises because sett ...

Follow the guidelines and examples provided on the Material UI documentation/demo page to incorporate Material

My goal is to incorporate the left sidenav under the AppBar, similar to how it is displayed on the material-ui documentation page. Any suggestions on how to achieve this? https://i.stack.imgur.com/A6bY5.png ...

Monitor Jenkins live logs with a personalized dashboard for real-time viewing

Our Jenkins CE is currently running close to 4000 jobs, with users accessing a Dashboard that utilizes Jenkins APIs. Previously, we provided an href link with a logs button for viewing logs, which would open the Jenkins logs page in an iFrame when clicked. ...

Ways to clear all CSS rules from a class without deleting the class itself using jQuery

Clear out all CSS properties within a class without actually removing the class itself using jQuery For instance : .ui-widget { font-family: Verdana, Arial, sans-serif/*{ffDefault}*/; font-size: 1.1em/*{fsDefault}*/; left: 350 ...

Issues with babel plugin-proposal-decorators failing to meet expectations

I recently included these two devDependencies in my package.json: "@babel/plugin-proposal-class-properties": "^7.1.0", "@babel/plugin-proposal-decorators": "^7.1.6", In the configuration file .babelrc, I have listed them as plugins: { "presets": ["m ...

Exploring jQuery's class attribute: Uncovering the key-value pair trick

I am encountering difficulties in obtaining the class of my div elements, which are intended to function as tabs on a simple asp.net website. I aim to achieve this using jQuery for better control over dynamic functions in the future. However, every time I ...

Top method for retrieving CSS variable in a customized Angular directive

I have a question regarding the process of converting the statement below to Angular's renderer2: this.elementRef.nativeElement.style.setProperty( '--primary-color ' , '#455363' ) The above statement modifies a CSS variable in the ...

What is the method for setting a cell's row-span to 2 using bootstrap?

Is there a way to make the red cell in a Bootstrap grid have a row-span=2 and fill the second row as well? .cell {height: 100px; border: 1px solid; border-collapse:collapse;} .red {background: red;} .yel {background: lightyellow;} <link href="https:/ ...

When the webpage is launched, the font styles specified in the CSS do not take effect and

As a beginning coder, I have encountered a small issue. In my HTML document, I attempted to set the font types of my paragraphs and headings to Arial using CSS. The code snippet is as follows: h4{ font-family arial san-serif; } However, when I run the c ...

Error: The property 'getClientRects' cannot be read because it is null

I'm brand new to learning about React and I've been attempting to incorporate the example found at: Unfortunately, I've hit a roadblock and can't seem to resolve this pesky error message: TypeError: Cannot read property 'getClient ...

Conceal the slider image without removing it

Is there a way to hide the slider background image on mobile screens? @media screen and (max-width: 800px){ .home #mainSliderWrapper { background-image: none; } .stlye { background-image: none; } .img--holder { background-image:none; } } I tr ...

Guide on showcasing local database images on a browser using React.js

new Product { Id = 2, CategoryId = 2, BrandId=5, ProductName = "Galaxy S23", Stock = 20, Price = 24999, CreatedTime = DateTime.UtcNow, Product ...

"Placing the save button on top of a div - a step

I am trying to position a div with an ID below a save button in my HTML code. The current setup looks like this: <button id="item_new" data-action="create" class="floating-button mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect mdl-button- ...

The useAutocomplete function in Material-UI fails to consider the disabled

Currently, I am working on developing my own Autocomplete component by utilizing the useAutocomplete hook from the mui/base package. Most parts of the implementation are functioning correctly, except for the disabled option. My expectation is that the com ...

How come the previous sibling element appears on top when the initial sibling is set to a position of absolute?

I have encountered an issue with two sibling sections. I applied position:absolute to the first section, but the second section is overlapping it. Even after trying to use position:relative on the second section, the problem persists. https://i.stack.imgur ...

When executing the command node server.js, an error is thrown stating: "Route.post() is expecting a callback function, however, it received an object of type Undefined at Route.<computed

As the title suggests, I am creating a boilerplate for use in multiple projects. Everything seems fine from a syntax perspective, but when I try to run 'node Server.js', this is the error that occurs: Node.js v20.11.0 PS C:\Users\Edward ...

Dynamic CSS manipulation with jQuery: Generate and access styles on the fly

I am working on an application where I am utilizing jQuery along with maphilight for highlighting image map segments. In addition to this functionality, I want to dynamically highlight specific HTML elements based on mouseover/mouseout events for the image ...

Dealing with POST redirection and retrieving parameters in Next.js

In a typical scenario, browsers send GET requests and servers return pages. However, in my case, I am making requests to a remote server and need to receive responses. The issue is that the server redirects me back to my page via a POST request with some d ...

Having trouble executing a props function that is passed to children components within a loop in ReactJS

Starting out with React and trying to build a comment box and board with multiple comments. Each comment will have an input box, save/edit button, and remove button. I passed the updateComment function from the board component to the Comment component as ...

CSS - How to specify a class within an id using syntax

How can I target a specific tag within an ID using the class name in selector syntax? For example, how can I make the inner "li" turn red in the code snippet below? <html> <head> <style type="text/css"> #navigation li ...