The border radius of MUI 5/6 defaults to a different value compared to when it's used with theme.shape.borderRadius

When I was designing my website using Mui, I specified a border radius in the theme settings:

{
    palette: ...,
    shadows: ...,
    typography: ...,
    shape: {
      borderRadius: 3,
    },
  }

However, when I imported a Button from MUI and used it on my site, the button had a border radius of 3px. On the other hand, I created another box that utilized the theme.shape.borderRadius property, resulting in a more rounded appearance with a border radius of 9px.

Why are the border radii different even though they should be referencing the same value I defined in the theme?

<Button
  variant="contained"
    sx={{
     width: "100px",
     height: "36px",
     color: "black",
     backgroundColor: "white",
    }}
>
 Start now
</Button>
<Box
 sx={{
  width: "100px",
  height: "36px",
  color: "black",
  backgroundColor: "white",
  borderRadius: (theme) => theme.shape.borderRadius,

  display: "flex",
  alignItems: "center",
  justifyContent: "center",
  }}
 >
  Start now
</Box>

Using 'px' explicitly with the value works as intended, but that's not the ideal solution for me.

borderRadius: (theme) => theme.shape.borderRadius+'px'

Answer №1

theme.shape.borderRadius is the specified default value for border radius (measured in pixels)

The property borderRadius, when applied to components, indicates how much the theme's border radius will be increased by

If a component receives borderRadius as a number, it multiplies that number by theme.shape.borderRadius

In a given example, if your theme's border radius is 3 and the Box element's border radius is also set to 3 as a number (since it inherits from the theme), this results in a total of 3x3=9px

To utilize the theme's border radius directly, simply pass 1 as the value

<Box borderRadius={1} /> This informs MUI that you prefer to use the theme's current border radius without needing to access it through a callback

In this specific example, there is a note mentioning theme.shape.borderRadius * 1

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

"Mastering the Art of Patience: Guarding Your Way Through

When I set up three guards on a route, it appears that all guards are assessed right away. {path: '', component: OptionsComponent, canActivate: [ GuardOne, GuardTwo, GuardThree]} The issue is that I need GuardTwo to wait until GuardOne complete ...

Exploring jQuery's parent selector for traversing the DOM

I am currently working with an array that inserts articles into my website. I have a specific requirement where, upon clicking the title (h3), I need to display more information based on the article's index. To achieve this, I believe I should travers ...

Guidelines for redirecting an on-click action to navigate to a link rather than entering text

Using the AJAX Live Search PDO feature, I made a modification to have the displayed words link to their respective URLs. However, clicking on the table does not redirect to the link but instead inputs the text. I am looking for a way to make the entire row ...

Guide to refreshing a page (state) in a react application

As I delve into learning react.js, I decided to develop a basic rock paper scissors game within a react app. However, I've encountered some difficulty in creating a reload button that differs from the standard JavaScript button implementation which ty ...

Images following do not have jQuery hidden

I am facing an issue with a small test script that is designed to hide images on button click. However, the problem I am encountering is that it only hides the first image out of three and then ceases to hide the subsequent ones. Below is the code snippet ...

Provide two instances of xyz along with the timestamp and calculate the speed

Utilizing this script to calculate the distance between two sets of xyz coordinates. function getDistance(x0, y0, z0, x1, y1, z1){ let deltaX = x1 - x0; let deltaY = y1 - y0; let deltaZ = z1 - z0; let distance = Math.sqrt(deltaX * deltaX + deltaY ...

Determine if a draggable item is currently positioned over another element

In my body, there are several divs located: <div id="one"></div> <div id="two"></div> <div id="three"></div> All of these divs are draggable using jqueryUI: var $divs = $('#one, #two, #three'); $divs.draggab ...

Angular 2 reactive form throws an error when attempting to reset the form with a custom validator

I have a Data-Driven Form in angular 2 with a custom validator on one of the controls. The issue arises when I use this.myForm.reset() while that control has a value, causing the validator to fail and throw an error. Interestingly, if I avoid using this.m ...

Is it feasible to automatically fill out a separate form by clicking a link?

Seeking help with creating an Android app that can automatically populate the "RFC Emisor" and "RFC Receptor" fields on a specific web page: https://verificacfdi.facturaelectronica.sat.gob.mx. I believe the IDs for these inputs are: ctl00_MainContent_ ...

Transitioning from pop-up modals to AngularJS JSON

I have a table with fields such as: product, lot, input1, input2. It is possible to clone a line or add a new line. The selection of the Product is based on a value from JSON data. The Lot selection initially stays empty and gets filled with sub-arrays rel ...

What are the potential consequences of using outdated npm dependencies?

I encountered an error while trying to run my Gatsby project that was built last November both locally and on Netlify. The error message I received is as follows: Error: [ERR_REQUIRE_ESM]: Must use import to load ES Module: /path/node_modules/dot-prop/in ...

How to delete a specific element from a JSON object using Node.js

I've been trying to figure out how to remove a specific ID from my ids.json file, but I can't seem to get it right. Here's the block of code that I've been working with: { "48515607821312": { "members": [ "23422 ...

`Erase content from a field once text is typed into a different field`

I have a Currency Converter with two input fields and a button. I enter the amount to be converted in the first field, and the result of the conversion appears in the second field. My question is: How can I automatically clear the second field when I type ...

The condition is not established by the Firestore where clause

I'm working on a function that includes two where clauses. My objective is to verify the existence of a document based on the presence of two specific IDs. However, when I execute the function, it retrieves all the records in the collection instead. C ...

Setting up a Vue 3 parent component to emit events to a child component: a step-by-step guide

Seeking assistance with setting up a Vue 3 Tailwind parent component button to trigger a HeadlessUI transition event in a child component. The objective is for the button in the parent to emit an event, which the child will then watch for before triggering ...

Displaying the complete output of news API within a React application

As a newcomer to React, I am currently working on fetching data using the news API. My goal is to display all of the results retrieved from the API, but I am facing some challenges in doing so. At the moment, I have only managed to display one result wit ...

Evaluating the functionality of a deactivated button in ReactJS

I created a React export button component that becomes disabled when the number of totalRecords exceeds ORDER_LIMIT or is equal to 0. Here is the code snippet: interface ExportExcelButtonProps { filterValues: OrderFilter; totalOrders: number; } const ...

Next.js does not recognize the definition of RTCPeerConnection

Looking for a way to utilize the React context API in order to pass an instance of RTCPeerConnection to my React Component tree. Despite being familiar with Next.js SSR feature, which initially renders components on the server side, none of the solutions I ...

Verifying the username's availability through AJAX requests

My registration form utilizing AJAX isn't connecting to the database. It seems like I'm missing something important. Let's focus on validating this particular field: Username:<input type="text" name="user" id="user" maxlength="30"> & ...

Passing React components between components using dot notation

How can I pass a boolean Parent prop into a child component using dot notation with a functional component? The Component structure is: <Dropdown className="float-right"> <Dropdown.Title>Open menu</Dropdown.Title> <Dropd ...