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

The skipping of crucial text in tab focus is adversely affecting the accessibility of the website

My appbar contains an image link, a warning indicating the user's current environment, and details about the logged-in user. While testing accessibility with a screen reader, I noticed that tab focus skips over the user details in favor of a link in ...

Utilizing React JS to populate a dropdown list with JSON data - strategies and best practices

I am working on a react JS file where I need to bind data to a dropdown list. The data is coming from a testing API/json file which can be found here: . My initial goal is to map the client name to its corresponding dropdown list option. Example json data ...

A step-by-step guide on adding a table with colored icons (red, green, and blue) to an HTML page using jQuery

I'm working on a project that requires designing an HTML page with three tables containing images, along with a compare button. Initially, only two tables are visible upon page load, but when the user clicks the compare button, the third table should ...

Issue: The number of hooks rendered is lower than expected after resizing the screen

I'm currently working on a responsive navbar that functions properly during rendering. However, I encounter an error every time the screen is resized or switched to mobile view. The error message reads: "Error: Rendered fewer hooks than expected. This ...

The dynamic links in Knockout.js are unresponsive to clicks

I've been working on a new project that utilizes knockout js. The main issue I'm facing is with setting up a table to display images and information from a form, being stored in an observable array. Each image is wrapped in an anchor tag, and the ...

What is the best way to enable an image to be moved on top of another image?

Is there a way to allow users to drag around an image that is positioned on top of another image in an HTML file? I want the superimposed image to stay within the boundaries of the underlying image. Any suggestions on how this can be achieved? <html& ...

If I include the Next.js Image component within a React hook, it may trigger the error message "Attempting to update state on an unmounted component in React."

My UI layout needs to change when the window width changes. However, when I add an Image (Nextjs component) in my hook, I encounter an error message. I am not sure why adding Image (Nextjs component) is causing this problem. The error message is display ...

When attempting to swap out ":customimage:" with an image in a React.js HTML view, the result displayed is [object Object]

I have created a function below: WordColonsToImage(comment) { var newcomment = comment.replace(/:wave:\s*/g, <img src={wavinghand} />) return newcomment } Here is an example: WordColonsToImage("Hi! :wave:") whi ...

Executing a curl POST request within an npm script

I recently added a new script to my npm scripts in the package.json file, but I'm running into issues due to the single and double quotes. The problem seems to be with the internal double quotes within the payload. "slack": "curl -X POST --data-urlen ...

Different ways to restrict Table Header to 2 lines using CSS

When it comes to limiting text to a specific width, using white-space:nowrap is usually the go-to solution. However, I am facing a unique challenge where I need to make sure my header text fits within a specific width. I initially tried adding individual ...

Change the order of the table data elements using the nth-child CSS selector

I need the second td in my table to appear on top of the first one when I resize the screen. @media screen and (min-width: 200px) and (max-width: 872px) { td :nth-child(1) {display:bottom} td :nth-child(2) {display:top} } <table border="0" cell ...

Having trouble replacing scss variables in react-h5-audio-player

I recently integrated react-h5-audio-player into my project and followed the instructions on the README page to customize the styles by updating the SCSS variables that control the colors. However, it appears that my custom styles are not being applied. An ...

Issue with the collapse animation in ReactJS Material UI after implementing a new component

Hello fellow developers! Check out this code example for a smooth collapse using Material UI: Code Example I noticed that when I move JSX to an external component, the smooth effect breaks. I've provided examples with and without smooth collapse for ...

Tips on troubleshooting the issue when attempting to use a hook in your code

I am trying to implement a hook to manage the states and event functions of my menus. However, when I try to import the click function in this component, I encounter the following error: "No overload matches this call. The first of two overloads, '(p ...

Obtaining the calculated background style on Firefox

Back when my userscript was only functional on Chrome, I had a setup where I could copy the entire background (which could be anything from an image to a color) from one element to another. This is how it looked: $(target).css('background', $(so ...

Need help understanding how to use setInterval within a variable and clear it in React while using Hooks?

Here is the progress I have made so far: import React from "react"; import PropTypes from "prop-types"; class ItemList extends React.Component { constructor(props) { super(props); this.state = { percent: ...

Creating a CSV download feature with ReactJS is simple and incredibly useful. Enable users

Despite searching through various posts on this topic, I have yet to find a solution that addresses my specific issue. I've experimented with different libraries and combinations of them in an attempt to achieve the desired outcome, but so far, I have ...

Flexbox - Consistent height image columns

I'm working on a basic flexbox layout that looks something like this: html,body { margin:0; padding:0; } body { height:100%; width:100%; } .panel-grid { -webkit-align-items: flex-start; ...

Encountering a 404 error when trying to navigate to the next route using the Link component

Having issues with my login route. I've added a Link to the login route inside a button tag in my Navbar component, but when I try to access the route, I'm getting a 404 error page. --app ----pages ------component --------Navbar.js ----- ...

What is the reason why the swiper feature is malfunctioning in my React-Vite-TS application?

I encountered an issue when trying to implement Swiper in my React-TS project. The error message reads as follows: SyntaxError: The requested module '/node_modules/.vite/deps/swiper.js?t=1708357087313&v=044557b7' does not provide an export na ...