Replacing Material-UI dialog fonts

I have created a unique User Confirmation Dialog using the Material UI Dialog component, similar to the example provided here

While working on customizing the dialog, I encountered an issue with changing the font. Although I was able to change the color and background color successfully, the fonts in the header or buttons of the dialog were still inherited from Material-UI. I have been able to overwrite the fonts in other components, but this particular part with callback posed a challenge:

const UserConfirmation = (
  message: string,
  callback: (shouldNavigate: boolean) => void
) => {
  const container = document.createElement('div')
  container.setAttribute('custom-confirmation-navigation', '')
  document.body.appendChild(container)
  const closeModal = (shouldNavigate: boolean) => {
    ReactDOM.unmountComponentAtNode(container)

    callback(shouldNavigate)
  }
  ReactDOM.render(
    <>
      <Dialog
        fullWidth={true}
        maxWidth="sm"
        open={true}
        aria-labelledby="alert-dialog-title"
        aria-describedby="alert-dialog-description"

      >
        <DialogTitleWrapper
          style={{fontFamily: `BuenosAires !important`, color: `orange`}}
          >
          Discard draft?
        </DialogTitleWrapper>
        <DialogContent>
          <p> {message} </p>
        </DialogContent>
        <DialogActionsWrapper>
          <Button
            onClick={() => closeModal(true)}
            fullWidth={true}
            variant="outlined"
            label="Discard"
          />
          <div style={{ width: '80%' }} />
          <Button
            onClick={() => closeModal(false)}
            fullWidth={true}
            variant="contained"
            label="Cancel"
          />
        </DialogActionsWrapper>
      </Dialog>
    </>,
    container
  )
}
export default UserConfirmation

Answer №1

Hey there Alex

This solution is absolutely perfect for me:

<DialogTitle  disableTypography="true">

In addition, the issue with buttons' labels was resolved by this tweak:

label={<h5 style={{ textTransform: 'none' }}>Cancel</h5>}

Answer №2

Utilize the classes object to customize or expand upon the styles implemented in the component. Click here for more information.

Create your own custom styles as shown below

const useStyles = makeStyles({

  customDialogTitle: {
    fontFamily:'Impact'//sans-serif
  }
    });

Then assign them to the classes attribute

   <DialogTitle disableTypography="true"

       classes={{
                 root: classes.customDialogTitle
                }}
    >
    .....
    </DialogTitle>

Check out this sample sandbox for reference.

Answer №3

Previous solutions are no longer effective (MUI v5).
I stumbled upon this question while searching on Google, so I thought I'd update it in case someone finds it helpful.

To customize the font family, you can use typography.fontFamily.

const theme = createTheme({
  typography: {
    fontFamily: 'Georgia',
  }
})

If you are using next/font, you can specify the font family with font.style.fontFamily (Credit to the comment in the discussion)
Previously, I used inherit and it worked well within the main content area, but not in roles like Dialog or Menu.


import { Inter } from 'next/font/google'
const inter = Inter({ subsets: ['latin'] })

let theme = createTheme({
  typography: {
    fontFamily: inter.style.fontFamily,
  }
})

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

Tips for executing nrwl/nx production build of web app on localhost with NextJS

Is there a way to host an nrwl/nx Next.js built app for production locally? I attempted running npm i -g serve, followed by serve -s within the directory of the Next.js application, but it seems that the styles and navigation are not displaying correctly. ...

Discrepancy detected in AGM Map printout

When attempting to print my Angular AGM Map from Chrome, I noticed a large grey gap in the map. This gap is visible even when "background graphics" are turned off and it causes the map image below it to shift downwards. If you want to reproduce this issue ...

Set a default value for a FormControl within react-bootstrap

When working with my email address, I utilized the <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="44362125273069262b2b30373036253404746a76706a71">[email protected]</a>. In order to specify the initial value chosen ...

What could be causing this error to occur in my JavaScript React code?

ERROR - '}' expected. Parse error. I'm experiencing issues with this code snippet where I try to fetch data for a graph using React, but I keep getting the parse error mentioned above. vehiculoPorColores = () => { const _this = this fet ...

Numerous hyperlinks leading to different products within the same image

I am looking for a solution to create clickable links on a picture that contains multiple items (3 in my specific case, as shown in the image above). Currently, I am using position:absolute to place links on each item, but this method is causing overlap ...

Communication Error between Amazon Elastic Beanstalk of express server and Netlify React App

I am encountering an error while attempting to deploy my React application that communicates with a backend hosted on Amazon Elastic Beanstalk. The error I receive is: "Access to XMLHttpRequest at 'https://4bto.sitename.com/api/dashboard/login' f ...

Creating a CSS class dynamically with AngularJS: A step-by-step guide

I'm working on an Angular JS website that pulls data from an API to create a dynamic CSS class. This class will be used to format other data being displayed on the page. Is there a way for Angular JS $scope data to be generated in the Controller whil ...

What is the most efficient way to retrieve a substantial volume of data from Mongodb quickly, especially when the query results require processing before transmitting to the client?

My project involves a large Mongodb database paired with a React front-end and Node back-end, housing around 100000 documents. Indexing has been completed and Redis is already in use. The search feature implemented allows users to find relevant documents b ...

Challenges with Bootstrap input groups

Despite trying various solutions, nothing seems to be working for me. I attempted using width:200px, but the issue persists. Since my form was quite outdated, I decided to switch to a bootstrap version. However, while others are able to resolve the issue w ...

Tips for formatting JSON using jQuery

Imagine my JSON data with 3 different sets of information: [ { "Pair":"", "Id":"8ca2df56-2523-4bc3-a648-61ec4debcaaf", "PubDate":"/Date(1463775846000)/", "Provider":null, "Market":"" }, { "Pair":"", ...

Having trouble updating state in a React Class component while using a customized header in ReactTable

I'm encountering an issue with the setState method and I'm unsure of what mistake I might be making. Below is the complete code snippet: The process begins with a function class that calls my API to fetch data from the database, then passes thi ...

What could be causing the dropdown menu to not display below its container when the overflow:hidden CSS property is applied to the container element

One issue I'm facing is that the dropdown submenu of my navigation menu does not extend beyond its container element when displayed. My code includes main menu items (HOME, ABOUT, SERVICES, PRODUCTS, and CONTACT) along with submenu items (A, B, C, D, ...

Adjust the color of the sidebar's list items when scrolling

How can I change the background color of left sticky sidebars li on scrolling? When scrolling through BMW, BMW's background color in the sidebar should turn green. Please refer to the code snippet provided below. The background color of the li ...

Exploring the intricacies of MUI spacing, such as utilizing the `Box` component with `py={[5, 5, 10]}` to achieve desired padding levels

In the code snippet <Box component="section" py={[5, 5, 10]}>, what does the [5, 5, 10] signify? I know that 'py={5}' denotes padding of 5 units for top and bottom. But what is the significance of the array '[5, 5, 10]'? ...

Overlay a semi-transparent gray layer onto the background color

My Table has various TDs with different background colors, such as yellow, red, green, etc., but these colors are not known beforehand. I am looking to overlay a semi-transparent gray layer on certain TDs so that... The TD with a yellow background will t ...

What is preventing me from being able to reposition certain tables on my site?

I have successfully implemented certain aspects of my responsive website, but I am encountering some difficulties in moving specific tables. I can adjust the table in various directions, except for moving it downwards. Even when adding the word !important ...

The aligning property "justify-content: space around" does not behave as expected on a line and does not provide the desired spacing

Below is the HTML code I am working on: <!DOCTYPE html> <html lang="fr"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta na ...

Create a custom file uploading feature in React with Material-UI

I am currently working on developing a compact file upload component. Previously, I utilized the <input type="file"> tag but due to limited space constraints, I need to display both "Choose file" and the complete file path within a very sma ...

I am looking to dynamically assign CSS classes to elements in my HTML document. Additionally, my project utilizes Angular 5 and Bootstrap version 3.3.7

I am currently in the process of generating a table using data obtained from a JSON. Due to the potential for a large amount of data, I have implemented a loop to create all the rows within the table. My goal is to enable users to click on any specific row ...

Unusual problem encountered with the MUI/Material UI multiselect feature

Looking for a solution: check out this codesandbox multiselect demo Currently trying to extract unique items from an array based on id in order to display them as options. Utilizing the MUI Select component. Successfully creating distinct arrays using di ...