Is the Material-UI 1.3 font size failing to adapt to varying screen widths?

Looking to create an app with responsive font sizes using material-ui (v1.3)? Also, want the font size to shrink when the screen size is smaller and adjust automatically. However, the current code doesn't update the font size dynamically as the screen size changes. Need help to figure out why it's not working?

class App extends Component {
constructor(props) {
    super(props);
    this.state = {
        open: false,
    };
}


getDrawerFontSize() {
    if (window.innerWidth <= 575) {
        return '10px';
    } else if (window.innerWidth <= 767) {
        return '11px';
    } else if (window.innerWidth <= 991) {
        return '12px';
    } else if (window.innerWidth <= 1199) {
        return '13px';
    }
    return '14px';
}

render() {
    const drawerFontSize = this.getDrawerFontSize();
    const { open } = this.state;

    const theme = createMuiTheme({
        overrides: {...}
    });

    const styles = {...};

return (

    <MuiThemeProvider theme={theme}>
    ...
    ...
    ... // The rest of the code goes here

} }

export default withRouter(connect( mapStateToProps, mapDispatchToProps)(App));

Answer №1

Creating responsive fonts can be achieved in various ways:
1) Utilizing JavaScript :
- One option is to utilize a JavaScript library (e.g. )
2) Using CSS :
- Instead of using pixels, consider using vw or vh units:
- 1vw equals 1% of viewport width
- 1vh equals 1% of viewport height
- 1vmin equals the smaller of 1vw or 1vh
- 1vmax equals the larger of 1vw or 1vh

OR
You can also employ Media Queries in CSS
https://www.w3schools.com/css/css_rwd_mediaqueries.asp

Thank you! I hope this information proves helpful.

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

Ways to identify whether a user is navigating through options in Material-UI Autocomplete using arrow keys?

I am working on a ReactJS application with a material UI autocomplete component and I want to achieve the following functionality: When the user types input into the autocomplete and presses enter without scrolling through suggested choices, event A shoul ...

Steps for displaying the contents of a file from Firebase storage on a React component

I uploaded a file to Firebase storage, and I want my app to be able to access and display the contents of that file within my class component div. Currently, when I try to access the file, it just opens in a new tab instead. class ScanResult extends Comp ...

It is necessary to render React Native text strings within a text component

Greetings! The React Native code snippet below is responsible for rendering a user interface. However, upon running the code, an error occurred. How can I resolve this issue? The error message indicates that text strings must be rendered within a text comp ...

Material UI offers a feature that allows for the grouping and auto-completion sorting

I am currently utilizing Material UI Autocomplete along with React to create a grouped autocomplete dropdown feature. Here is the dataset: let top100Films = [ { title: "The Shawshank Redemption", genre: "thriller" }, { title: " ...

Encountering difficulties while trying to set up the Stripe npm package

I'm encountering a problem while attempting to add the Stripe NPM Package to my React project using npm. The terminal is showing this error message. PS C:\Users\adity\OneDrive\Desktop\stripe-payments> npm i @stripe/react-st ...

Using jQuery to load and parse a JSON file stored on a local system

I am a beginner in scripting languages and recently searched for ways to load and parse JSON files using jQuery. I found helpful resources on Stack Overflow. The JSON file I am working with is called new.json. { "a": [ {"name":"avc"}, ...

Looking for help in resolving console error displaying 'Uncaught (in promise)' notification

I've encountered an issue while trying to troubleshoot a problem that involves using the find() method, which is causing an error. import { CART_ADD_ITEM, CART_REMOVE_ITEM } from '../constants/cartConstant'; const cartReducers = (state = { ...

The MUI multiple select feature is experiencing issues following the addition of a new button

I'm having trouble adding buttons below a select dropdown menu with a specific height. When I try to put the menu item inside a div, the multiple select stops working and I have no idea why. Can someone help me figure this out? Check out my CodeSandb ...

What could be preventing the jQuery from showing the JSON response?

I am having an issue with a jQuery script that is supposed to pull a quote from an API in JSON format and display it on the page. However, for some reason, I am unable to retrieve data from the API. Can you help me figure out what is wrong here? Thank yo ...

The bundle.js file encountered an issue while running UglifyJs, expecting a name

I have been attempting to utilize UglifyJS to compress/minimize my bundle.js file. However, when executing webpack -p, I encountered the following error message: ERROR in bundle.js from UglifyJs Name expected [bundle.js:105519,6] The line causing the iss ...

managing static assets within a storybook monorepo

I have a lerna + yarn workspaces monorepo with multiple packages and components, each one containing its own /assets folder with static images: /packages      /component1             /assets ...

Is it possible to utilize material-ui's FloatingActionButton component as the submit and reset buttons for my redux-form?

Trying to implement a basic redux form with Material UI components. I've followed the example on their website and got the redux Field components to render as material-ui fields easily. However, I want to use material-ui buttons as my Submit and Rese ...

What steps can I take to ensure my React js Material-UI table is both responsive and evenly spaced?

Currently utilizing the MaterialTable component sourced from material-ui, I've encountered two issues that require resolution. 1. Is there a way to ensure equal spacing of columns? Currently, there seems to be an unnecessary amount of space between t ...

Authenticate through navigation on an alternate component

I am in the process of developing a user interface that includes a side navigation and header bar. However, if the user is not logged in, I wish to redirect them to the login page. The primary component structure is as follows: class App extends Componen ...

The issue of CSS3 Grid-gap not functioning properly on iPhone devices

I've been working on creating a CSS template and everything seems to be functioning correctly, except for the grid gap which doesn't seem to work properly on my iPhone. Here's the code I have so far: <div class="grid"> <h1 ...

Is it possible to use JavaScript to load, edit, and store text files?

Hey there, I have a text file that needs some find and replace operations done on it within the browser. My coding skills are still in the beginner stage, so creating web apps from scratch feels overwhelming right now. All I want to do is upload the file, ...

Updating a legacy Handlebars application with React for a more modern user experience

Recently, I've come across my old Node, Mongo, Express, and Handlebars app which appears to be a bit outdated. The static nature of the app's data being fetched locally from the same domain and rendered on the server side with Handlebars is no lo ...

Executing SQL Query on Button Click Event

I am working with PHP and trying to execute a SQL query when a button is pressed. However, the issue I'm facing is that nothing happens when I click the button! I checked the developer console but there doesn't seem to be any action detected when ...

Revamp the sequence of divs using jQuery

<div class="example first">111</div> <div class="example second">222</div> <div class="example third">333</div> Can the order of these divs be changed using jQuery? I am looking to get: <div class="example second"&g ...

How to Remove onFocus Warning in React TypeScript with Clear Input Type="number" and Start without a Default Value

Is there a way to either clear an HTML input field of a previous set number when onFocus is triggered or start with an empty field? When salary: null is set in the constructor, a warning appears on page load: Warning: The value prop on input should not ...