Collapsible Rows in Material-UI Table seamlessly integrated with regular rows

While using material-ui v4, I encountered an issue where my collapsible row columns are not aligning properly with my regular columns. Below is a photo and the code snippet for reference. As you can see in the image, when I expand the Frozen Yogurt row, the columns do not line up with the headings (dessert, calories, fat, carbs, protein). Is there a way to make the columns in the collapsible row align with the table headings? Additionally, I would like them to remain aligned even when the screen size changes.

Click here for the image of the issue

import React from "react";
import PropTypes from "prop-types";
import { makeStyles } from "@material-ui/core/styles";...
 ...
 ...
    					</Table>
    				</Box>
    			</Collapse>
    		</TableCell>
    	</TableRow>
    </React.Fragment>
  );
}

Row.propTypes = {
	row: PropTypes.shape({...}).isRequired
};

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

export default function CollapsibleTable() {
	return (
		<TableContainer component={Paper}>
			... 
			(remaining code remains the same as provided)
            ...  
			
					

Answer №1

To solve the issue, you can specify a negative margin. I have demonstrated adding it as an inline style, but you can also include it within an object using makeStyles

<IconButton
  style={{ marginLeft: "-24px" }}
  aria-label="expand row"
  onClick={() => setOpen(!open)}>
  {open ? <KeyboardArrowUpIcon /> : <KeyboardArrowDownIcon />}
</IconButton>;

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

Position a <div> element in the center of another <div> element

Link to code: https://jsfiddle.net/z4udfg3o/ My goal is to center the "caixa" divs within the "produtos" div. Initially, I achieved this by using exact values with margin-left. However, I now want it to be responsive across different screen sizes, so I ha ...

Receive emails: using the require() function with ES Module

After following the react-email documentation, I encountered an error when trying to run the yarn email command: $ email dev --port 3001 ***\node_modules\ora\index.js:65 if (process.platform === 'win32') { ...

Other elements are unable to conceal Material UI InputBase

Displayed below is a navigation bar that sticks to the top, followed by rows of InputBase components from material-ui. Despite setting the background color of the nav bar to white, the input always appears above the nav. This strange behavior stopped when ...

The issue of the React input inside the modal component losing focus and triggering state re-rendering

Recently, I've encountered an issue with a modal component that I'm working on. Whenever I type characters into either input field, the focus is lost after entering just one character. I tried adding some console.logs to debug the problem and no ...

What steps do I need to take to create a fresh interface in useState with the help of Typescript

I'm attempting to replicate an input by utilizing useState with an interface. Each time I click on the + button, the interface should be duplicated in the state, thereby duplicating my input. Here is the code I am working on: interface newInputsInter ...

`Custom React-Redux data-table component with advanced features`

Experiencing performance challenges with react-redux in electron while using a large data table. I have developed a custom table structure like the one below: <Table> <TableHead> <tr> x*<Column /> </tr> <TableHea ...

When the selection is changed, the SelectableList fails to show the currently selected item

Encountering an issue with a SelectableList. Upon initial display, the default item selected in the list appears as expected. However, when attempting to select a different item from the list, it does not register as selected and the index remains undefine ...

Using Firebase to connect and disconnect from state in React with Re-base

I'm encountering some issues with React and Firebase while using the re-base module. When attempting to retrieve content from Firebase across different components in my app, I run into a problem. On one component/"page," which is home, I have the abi ...

Istio - Directing traffic for multiple React applications through a single virtual service

Two frontend express static react apps need to be routed accordingly. One should be accessible at the root, while the other at /provider. Currently, the route to /provider is not displaying the static content, although it works for the root. apiVersion: n ...

Guide to expanding the sidebar width

As I delve into the world of CSS, I find myself puzzled by the issue of expanding the sidebar to ensure that the "Gestion des utilisateurs" section appears on a single line. https://i.stack.imgur.com/xzFEA.png To provide context, I have included an illus ...

Beginning of my initial endeavor (seeking feedback, general advice, criticism)

Hey everyone! I'm looking for a forum-style platform similar to Stack Overflow where I can get some feedback on my first project. It's the first one I've built from scratch, so I'm open to any critiques or suggestions on what could be i ...

Choose a child element with Inline styling within the Material UI makeStyles feature

Having trouble selecting a child element from style.js using material ui makeStyles for styling. style.css .item:hover > .subListItem { display: block; } The problem persists even after trying inline styling. style.js item: { "&:hover &g ...

Transfer the information on the onClick event to the loop's function

When creating my component within the parent component, I follow this approach: renderRow(row){ var Buttons = new Array(this.props.w) for (var i = 0; i < this.props.w; i++) { var thisButton=<FieldButton handler={this.actionFunction} key={&ap ...

Flexbox: Arrange header and footer in a sidebar layout using flexbox styling

In my content layout, I have structured the sections as header, content, and footer. While I want to maintain this order for small devices, I am looking to shift the header and footer to the sidebar on desktop. I have already implemented this using floats ...

Validation of forms in ReactJS using Material UI components with Formik

I'm currently working on implementing phone number field validation using reactjs, material ui, and formik. Despite reading a substantial article on the topic, I haven't been able to successfully implement it in my project. Below is the reprodu ...

Vanishing Submit Button with CSS

In my input submit button, I have included the following code: <input class="buttons" type="button" onclick="javascript:jQuery(xxxx)" style="font-size: 12px;" value="Invite to Bid"> Additionally, there is a CSS function that adds an elegant "Go" im ...

Exploring Bottom Tab Styling in React Navigation

How can I achieve a similar style for the bottom tab like the one shown in this model? View Model <HomeTabs.Navigator screenOptions={({route})=>({ tabBarIcon: ({color, size})=>{ const {name} = icons[route.name ...

How to prevent click events and still enable scrolling within a DIV using CSS/JS

Basically, I am looking to enable scrolling within a DIV while also disabling click events. Any suggestions on how this can be achieved? Appreciate any help! ...

Displaying a list of data separately in rows using React JS

I am encountering an issue with React Js. I need to display names data in individual rows. const names = ['James', 'John', 'Paul', 'Ringo']; Here is my code: return ( <div class="col-lg-8 bar-name"> ...

Managing multiple sets of radio buttons using the useState hook

Within my renderUpgrades-function, I handle the options of an item by including them in radio-button-groups. Each item has multiple options and each option has its own radio-button-group. Typically, a radio-button-group can be managed using useState, wit ...