How can ListSubheader in Material-UI be customized to match the style of iOS UITableView?

Here is the current appearance of my ListSubheader.

https://i.stack.imgur.com/HAzTA.png

Currently, it is just aligned to the left.

However, the default header view in UITableView on iOS looks like this:

https://i.stack.imgur.com/F9Amv.png

It features a background color, different fonts, and font colors.

How can I achieve this look? As a beginner with material-ui, do I need to apply CSS formatting?

Answer №1

If you are working with material-ui V4 and utilizing hooks, here is how you can customize ListSubheader styles:

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
import ListSubheader from '@material-ui/core/ListSubheader';

const useStyles = makeStyles(theme => ({
  listSubHeaderRoot: {
    backgroundColor: '#E5E5E5',
    color: '#252525'
    /* To change the font, use the fontFamily rule */
  }
}));

export default function PinnedSubheaderList() {
  const classes = useStyles();

  return (
    <List subheader={<li />}>
      {[0, 1].map(sectionId => (
        <li key={`section-${sectionId}`}>
          <ul className={classes.ul}>
            <ListSubheader classes={{root:classes.listSubHeaderRoot}}>{`I'm sticky ${sectionId}`}</ListSubheader>
            {[0, 1].map(item => (
              <ListItem key={`item-${sectionId}-${item}`}>
                <ListItemText primary={`Item ${item}`} />
              </ListItem>
            ))}
          </ul>
        </li>
      ))}
    </List>
  );
}

https://codesandbox.io/s/material-demo-krzsh?fontsize=14&hidenavigation=1&theme=dark

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

Creating a personalized design for Bootstrap Badge

Looking to customize the shape of bootstrap badges from the default ellipse to a rectangle with rounded corners. Any tips on the best approach to accomplish this? ...

VSCODE's intellisense feature seems to be ignoring CSS code within JSX files

I've been puzzling over why Visual Studio Code isn't recognizing CSS syntax inside JSX files. While I'm typing, CSS IntelliSense doesn't provide suggestions for CSS - only Emmet suggestions.https://i.stack.imgur.com/FegYO.png Despite t ...

Position your content on the right side of the Angular Material tabs

I'm struggling with positioning content next to the tabs on the right side. I attempted placing content in a disabled mat-tab, but I don't want the content (located on the right) to be disabled. In addition, the content includes a dropdown menu ...

What is the best way to align an element next to another using id or class?

I am looking to align the search element next to either "Media Heading 1" or "Media Heading 2" based on their id/class. For instance: Assume I have an element with the class of "media-item-1" and I aim to position the search div alongside that element us ...

PHP dropdown menu is a dynamic feature that provides users

Can anyone help me identify the issue with this code? I am struggling to display the sub menu... I suspect the problem lies in the section where I retrieve the sub menu from the database. However, upon inspection, everything seems correct... It's po ...

What is the best way to ensure that circles only touch each other by their edges?

Trying to align three circles touching each other has been a challenge for me. Although I have successfully managed to make two touch, the third one remains elusive. How can I ensure that all three circles are in contact with each other, especially when th ...

The font size of the textarea dynamically adjusts based on the size of the screen

Some strange behavior is occurring in the Android default browser when I set the width and height of a textarea to 100%. The font size of the textarea seems to increase based on the screen size, and even though I attempted to alert the font-size using jQue ...

Rotate the image as you hover your cursor over it

I am trying to implement a script where the image is rotated when the user hovers over it. Unfortunately, the hovering effect is not functioning as expected. $("#alcazar-image").rotate({ bind: { mouseover : function() { $(this).rotate({anima ...

What is the optimal resolution for a background image in a Cordova app?

Currently working on a Cordova application that requires different background images for various screens. Despite using media queries to provide the background image in different resolutions, we are facing an issue where the background image is not displ ...

ngInfiniteScroll Activates on Every Scroll Occurrence

Implementing ngInfiniteScroll for endless scrolling on my website has required me to set the height of the outer div to a specific value. Without this adjustment, the Infinite Scroll feature activates unintentionally. <div style="height: 1px"> &l ...

Showcasing menu options in a double-column layout - MUI Menu

Just starting out with React. I'm using MUI menu to display items in two columns, but I've noticed a significant gap between the menu items when using grid display with repeat 2 and 1fr. display:'grid' , gridTemplateColumns : 'repe ...

A guide on accessing Textfield input values in Redux-form while utilizing MaterialUI

The objective is to retrieve input values from a material UI component and transmit them to an action creator within a handleSubmit function. <Field name='email' component={email => <TextField fullWidth autoComplete='off' clas ...

Tips for accessing the height property of an image

Is there a way to determine if an image lacks the height style property? Exploring CSS in HTML <img id="image" src="images/sports/sports9.png" style="width:100px"> Using jQuery if($('#image').css('height') == 0) { var ima ...

Tips on showing the "Clear" text on the left side of the calendar in MUI DatePicker

My challenge involves using DesktopDatePicker from material-ui(version 5.0.0) and attempting to show the text "Clear" on the left side of the calendar. import * as React from "react"; import dayjs from "dayjs"; import TextField from &qu ...

What is the best way to transfer user input data from a Form component to the state of its parent component in react hooks before submitting?

Currently, I am in the process of setting up a multi-step form for facilitating sign-ins using Next.js and Material-UI. The core functionality of the multi-step form is implemented within the signup.js page located at pages/signup.js. I have created child ...

Unable to load the Bootstrap CSS file from the specified import path: "bootstrap/dist/css/bootstrap.min.css"

I am currently working on a React application where I have a page that utilizes components from the react-bootstrap library. The issue I'm facing is related to styling, even though I have already imported the necessary bootstrap CSS file: import "boot ...

Menu Design Inspired by Amazon Using jQuery

Can someone please assist me in locating a jQuery Amazon-style menu example? I would like to implement something similar and am hoping to avoid having to write it from scratch. Thank you! ...

Having trouble loading the linked CSS file in the Jade template

My directory structure is organized as follows: --votingApp app.js node_modules public css mystyle.css views test.jade mixins.jade In the file mixins.jade, I have created some general purpose blocks like 'bo ...

Designing php/mysql data in a container

After successfully converting an ordered list output into a div output, I now face the challenge of stacking arrays on top of each other (and side by side with the two divs) like they would in an ordered list. Here is the original code snippet: <?php ...

How can I fix the position of the close button when using the paper component of a modal in material ui to ensure responsiveness on the screen

I recently created a cards page where multiple cards are displayed. Each card opens a modal component when clicked, but unfortunately, the close button is not functioning properly. Here's an image showing the issue with the button's position whe ...