What is the best way to enhance the appearance of the unordered list within the pagination design?

I'm struggling to apply styles to the ul within the Pagination, no matter what I try, it just doesn't seem to work!
Here is an image for reference:
https://i.sstatic.net/lQvPn.png
I am trying to target the MuiPagination-ul class for styling.
Here are my attempts so far:

const useStyles = makeStyles((theme) => ({
    Pagination: {
        root: {
            MuiPagination: {
                ul: {
                    display: 'inline-flex'
                }
            }   
        }            
    }
}));

<Pagination className={classes.Pagination}/>

I've also tried moving it outside of root and using a string like this:

'MuiPagination-ul': {display: 'inline-flex'}  

Am I missing something here? What could be the issue?

Answer №1

One of the simplest ways to customize a Material-UI component is by using the withStyles method. To understand how to implement custom styles, you can refer to the default Pagination styles.

Below is an example that demonstrates this:

import React from "react";
import { withStyles } from "@material-ui/core/styles";
import Pagination from "@material-ui/lab/Pagination";

const StyledPagination = withStyles({
  ul: {
    display: "inline-flex"
  }
})(Pagination);

export default function BasicPagination() {
  return <StyledPagination count={10} color="primary" />;
}

If you opt for using makeStyles/useStyles, note that you can only utilize the className prop if you are customizing the root CSS class. In scenarios where customization of the ul CSS class is required, as seen in this part of the code compared to the root CSS class, utilizing the classes prop becomes necessary.

import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import Pagination from "@material-ui/lab/Pagination";

const useStyles = makeStyles({
  ul: {
    display: "inline-flex"
  }
});

export default function BasicPagination() {
  const classes = useStyles();
  return <Pagination count={10} color="primary" classes={classes}/>;
}

If your makeStyles call includes additional classes not meant for Pagination, it is advisable to be more specific in defining what goes into the classes prop:

import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import Pagination from "@material-ui/lab/Pagination";

const useStyles = makeStyles({
  paginationUL: {
    display: "inline-flex"
  }
});

export default function BasicPagination() {
  const classes = useStyles();
  return (
    <Pagination
      count={10}
      color="primary"
      classes={{ ul: classes.paginationUL }}
    />
  );
}

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

The current value of React.createRef() is perpetually empty

Ever since I started working on this code, I've been encountering a problem that seems to have no solution. Here's what's going on: import React, { Component } from 'react'; export class InfoPaneArrow extends Component<InfoPane ...

ReactJS problem with dynamically adding input fields

By clicking on the +Add Content button, I am attempting to dynamically add one cascaded form field internally. Although the array for the field is updating, the view remains unchanged. Interestingly, when I try to add the external field by clicking on the ...

Utilizing ReactJS to Transfer States and Props within Reactable Table Rows

I am trying to use the Reactable library for displaying data tables in React. I want the state of my parent component, UsersTable, to be set or changed when a row in the table is clicked so that it remembers the id of the clicked record for future actions. ...

Restricting the download of data in Firebase when using the

I have implemented a Firestore listener in my app that downloads items from the database as they are added. Initially, all documents are downloaded using onSnapshot, but I want to limit this to 12 items as I am using a FlatList to render items as I scroll. ...

What is the best way to declare strings within a Typescript interface?

I have an array of Projects with multiple strings in the stack property const projects: IProject[] = [ {name: '', description: '', stack: {'php', 'sql'}} ] What is the best approach for defining the interface? ...

What is the importance of utilizing clearInterval to restart the timer in ReactJS?

Consider the code snippet provided below: useEffect(() => { const interval = setInterval(() => { setSeconds(seconds => seconds + 1); }, 1000); return () => clearInterval(interval); }, []); What is the purpose of returning ...

Tips for generating more compact CSS files to simplify your development workflow

At the moment, I have included two CSS files within my <head> tags: <link rel="stylesheet" href="/stylesheets/init.css"> <link rel="stylesheet" href="/stylesheets/layout.css"> The init.css file is used for resetting elements and definin ...

Show Excel spreadsheet in a drop-down menu

Seeking assistance - I have an Excel table filled with data that I would like to showcase in a dropdown menu on my website. Here's a more detailed breakdown: Table: | ROW1 | Data | Data | Data | RESULT | RESULT | | ROW2 | Data | Data | Data | RESULT ...

What is the best way to set the background opacity to 0.7 without impacting the content within it?

Currently, I'm facing an issue with two divs - the outer one is identified as "BD" and the inner one as "content". Whenever I attempt to reduce the opacity of BD's background-color, the content inside also becomes less opaque including both image ...

Implementing conditional asynchronous function call with identical arguments in a Typescript React project

Is there a way in React to make multiple asynchronous calls with the same parameters based on different conditions? Here's an example of what I'm trying to do: const getNewContent = (payload: any) => { (currentOption === myMediaEnum.T ...

In Angular, a white screen may suddenly appear if the scrolling speed is too fast

My experience has been primarily on Chrome. I've noticed that when I scroll for a long time, the data on the screen disappears briefly and then reappears after a few seconds. Is there a resolution for this problem? Thank you, ...

Autonomous boundary for list elements

I have a specific issue that can be observed in this fiddle: http://jsfiddle.net/h0qu4ffv/ where I set the margin-top of one list item to 50px, but all list items end up following this style. Is there a way to give each list item an independent margin, or ...

Building a Modal in React and Triggering it for Display, followed by Making an AJAX Request upon Submission

Check out my CodePen snippet (minus delete ajax request): http://codepen.io/martincarlin87/pen/KzPWOw I've been diving into the world of React recently, and I'm working on converting a page in my web application to utilize React instead of just ...

Enhancing the Alignment of a Bootstrap Navbar with CSS

Having trouble centering the listed items (excluding the image and title) in the middle of the navbar. Tried various solutions with no luck! Any suggestions on how to tackle this issue? <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a ...

Filtering data with React's multiselect checkboxes

I have created an amazing app that fetches a list of todos from this incredible source To enhance user experience, I developed a special CheckBoxDropDown component for selecting todo IDs Within the CheckBoxDropDown.js component, I am passing the onChange ...

Adjust the height of the Accordion component in Material UI

I am currently in the process of migrating a JavaFx HMI to a web application that utilizes React.js. To display graphical widgets, I am also working with Material.ui. In order to maintain consistency with the original HMI layout, I need to adjust the layo ...

Import next.js API endpoint directly within the getServerSideProps function

When utilizing getServerSideProps() in Next.js to fetch data, it is advised to directly import the API endpoint rather than using fetch() and triggering another HTTP request. I successfully implemented this approach until incorporating middleware for my AP ...

What is the process for removing filtering options in material-ui Autocomplete?

Currently, I am utilizing the Autocomplete feature from material-ui for my project. The Autocomplete component fetches suggestions from a backend asynchronously as the user changes input values. Here is a snippet of the code in question: const [options, s ...

I am attempting to calculate the quantity of divs with a specific class, but for some reason, the .length method is consistently returning a value of 0

I'm having trouble counting the number of div elements with a specific class. Every time I use .length, it comes back as 0. What could be causing this issue? var keyspressed keyspressed = $('.key').length; console.log(keyspress ...

Tips for aligning a specific section of text in the center

Currently in the process of learning bootstrap for website design, I am working on creating a user profile page. The layout includes fields such as name and email with corresponding values displayed inline when screen size permits. My goal is to align the ...