Halt the Changing of Button and Typography Styles with React Router and MUI

I am currently working on a component that I want to make clickable. However, when I wrap them in a <Link> element (from react-router-dom) or set component={Link} to="" on them, all the text inside them automatically becomes hyperlinks. For example:

https://i.stack.imgur.com/JKUsK.png

In the image above, there are four buttons, with the last three being wrapped in <Link> tags. I do not want the styling of those buttons to change. While I understand that I can remove the underline and other styles using CSS, it seems cumbersome to have to do it for everything inside the link tag.

This issue also arises when I add component={Link} to="" to a container that contains images, Typography, and other elements - causing all text to become hyperlinked as well.

Could you please advise on how to prevent everything inside a Link from being styled as a hyperlink?

Answer №1

When it comes to customizing your site, there are a couple of approaches you can take. For guidance, you can look at MUI: How to customize.

If you want to change the appearance of all Link components on your site, you can use a theme override like this:

const theme = createTheme({
  overrides: {
    MuiLink: {
      root: {
        // ...
      },
    }
  }
});

If you only need certain sections to have different-looking links, you could create a reusable component with custom styles. Here's an example:

import * as React from 'react';
import Link, { LinkProps } from '@mui/material/Link';
import { styled } from '@mui/material/styles';

const SimpleLink = styled(Link)<LinkProps>(({ theme }) => ({
  textDecoration: 'none'
}));

export default function StyledCustomization(url: string) {
  return <SimpleLink url={url} />;
}

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

"Troubles with directing on websites using jQuery, CSS,

I have been struggling with creating this navigation bar for weeks now and I keep running into issues. What I am attempting to achieve is a primary navigation bar that, when hovered over, displays a secondary navigation menu below and slightly to the righ ...

Achieving text center alignment and adding color to text within a header using Bootstrap

I am looking to center the text in a header and apply color to it using Bootstrap. Unfortunately, there is no direct option for font-color or text-color in Bootstrap. Below is my HTML and CSS code: #header { width: 800px; height: 50px; color :whi ...

The argument type 'MouseEvent<HTMLButtonElement, MouseEvent>' cannot be assigned to the parameter type 'HTMLElementEvent<HTMLButton>'

Here is the code snippet that I am currently working on and encountering an error in the console: type HTMLElementEvent<T extends HTMLElement> = Event & { target: T; } toggleHandler = (e: HTMLElementEvent<HTMLButtonElement>) => ...

Manipulate only the elements inside the designated container

My CSS/bootstrap file is quite extensive and the styles are affecting more than just the elements I intended to target. While I want it to have a broad impact, the CSS changes are impacting the entire page. Renaming every element to [name].slider is not ...

Using React components with inline styling

I recently created a custom component named PaddingStyle: class PaddingStyle extends Component { constructor( props ) { super( ...arguments ) } render() { const { paddingTop, paddingRight, paddingBottom, paddingLeft } = this.p ...

Exploring alternative color palettes outside of the traditional primary, secondary, and error schemes

One way to customize a theme and change the default color palette is by using the following code: const theme = createMuiTheme({ primary: { main: '#aa2222', }, extra: { main: '#22aa22', }, }); By applyin ...

What is the best way to retrieve certain items from an array that has been converted into table rows using React?

I'm currently using React.js to develop a feature on our website that displays a list of names. Each person's information is stored as objects within an array. With the help of the .map function, I was able to successfully generate the list in ta ...

Tips for creating a test to choose a movie from the MuiAutocomplete-root interface

I am currently utilizing Material UI with React using Typescript and I am looking to create a test for the autocomplete functionality using Cypress. Here is the approach I have taken: Identifying the Autocomplete component and opening it, Choosing an opti ...

Utilizing environment variables in index.html with Create React App

Is it possible to include environment variables, such as REACT_APP_MY_API, in the index.html file? I came across some information suggesting that it can be done (refer to this link), but I haven't been successful in getting it to work. .env File RE ...

Create custom components by wrapping npm components and exporting them as a single custom component

Encountering issues while installing 3rd party components from npm. For instance, a dropdown react module that can be used easily in my own module; however, I find myself needing to declare its style and other dependencies in multiple modules. For example ...

Difficulty accessing `evt.target.value` with `RaisedButton` in ReactJS Material UI

My goal is to update a state by submitting a value through a button click. Everything works perfectly when using the HTML input element. However, when I switch to the Material UI RaisedButton, the value isn't passed at all. Can someone help me identif ...

When writing CSS, ensure there is no space between selectors and classes of elements

Can you explain the distinction between using a css selector (like p) and assigning a class to an element (.cat)? p.cat{ } Vs. p .cat{ } Appreciate your help! ...

Achieving a smooth transition from a blur-out effect to a blur-in effect on a background Div

I created a blur in/out effect for my landing page, but it's not functioning as expected and I'm not sure why. It blurs out correctly, but the issue arises when I want the underlying Div to fade in. Currently, it just appears abruptly after the ...

Extremely efficient CSS utility classes for supreme performance

I've noticed the rise of CSS utility classes and I'm curious about their impact on performance. Is there a better approach? Option One - creating HTML elements with multiple utility classes like: <div class="padding flex justifyCenter align ...

Introducing a new div element completely disrupts the overall layout

Take a look at the code I have provided below. http://jsfiddle.net/xymgwonu/3/ Everything was working perfectly fine until I introduced a new div with the class name <div class="bubble"></div>. This caused some issues with the overall design. ...

The React front-end struggles to display MongoDB entries and eventually times out after 10 seconds

I am experiencing an issue where my React front-end is unable to fetch details from a MongoDB database and I need assistance debugging the problem. The back-end utilizes a serverless function. Each time I reload the page, my React code fails to locate the ...

Managing CSRF tokens in React Relay: best practices

I have been diligently working on a React Native application that communicates with a GraphQL API from a Django server. Within React Native, I have decided to utilize React Relay for handling my GraphQL requests (following the instructions provided here). ...

Using Conditional Tags for CSS Display

I'm working on implementing Conditional Tags to toggle a CSS class on or off based on the current displayed page. However, I'm running into an issue where the code isn't executing properly. There might be a syntax or logic error causing the ...

What is the best way to close a popup window?

Is there a way to close my popup? function hidePopup(){ document.getElementById("popup-1").classList.remove("active"); } @import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro&display=swap'); .popup .overlay{ positio ...

Whenever I add a new Task in React.js, the date is not visible to me

I'm currently deepening my understanding of React, and I've encountered a roadblock. The issue arises when I attempt to create a Tracking Task - the task is successfully created from the form inputs but the date associated with the new task isn&a ...