Difficulty in accurately identifying the current page on the appbar

I'm attempting to make the active page in my navbar stand out by giving it a white background color and skyblue text. However, for some reason, I can't get the text color to display as skyblue in the appbar. You can see how it currently looks in the attached image below.

                    <Box>
                        <IconButton>
                            <NavLink to='/' 
                             activeClassName='selected'>
                                <Typography
                                    variant='body1'
                                    style={{
                                        marginRight: "1rem",
                                        color: "white",
                                    }}>
                                    Dashboard
                                </Typography>
                            </NavLink>
                            <NavLink
                                to='/aboutus'
                                activeClassName='selected'>
                                <Typography
                                    variant='body1'
                                    style={{
                                        marginRight: "1rem",
                                        color: "white",
                                    }}>
                                    About Us
                                </Typography>
                            </NavLink>
                            <NavLink
                                to='/contactus'
                                activeClassName='selected'>
                                <Typography
                                    variant='body1'
                                    style={{
                                        marginRight: "1rem",
                                        color: "white",
                                    }}>
                                    Contact Us
                                </Typography>
                            </NavLink>
                        </IconButton>
                    </Box>

The CSS styles being applied here are:

    .selected {
        background-color: white;
        color: skyblue;
    }

https://i.sstatic.net/23dZm.png

Answer №1

Due to the color style added in Typography, the active class is being applied while passing the color specifically to the typography component, resulting in the color being determined by priority.

One possible solution could be:

.nav-link {
  margin-right: "1rem"; 
  color: "white";
}
.selected {
  background-color: white;
  color: skyblue;
}
<Box>
  <IconButton>
    <NavLink to='/' activeClassName='selected' className="nav-link">
      <Typography variant='body1'>
        Dashboard
      </Typography>
    </NavLink>
    <NavLink to='/aboutus' className="nav-link" activeClassName='selected'>
      <Typography variant='body1'>
        About Us
      </Typography>
    </NavLink>
    <NavLink to='/contactus' className="nav-link" activeClassName='selected'>
      <Typography variant='body1'>
        Contact Us
      </Typography>
    </NavLink>
  </IconButton>
</Box>

If this method doesn't work, you can add it as a class and conditionally toggle it with the active state.

UPDATE: Much appreciation to @DBS for highlighting the error in the previous response.

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

What is the best way to incorporate multiple Bootstrap templates into an Angular project without causing conflicts between them?

When incorporating a bootstrap template into the admin interface, it is important to consider that its design may vary from the template used for visitors. Mixing multiple styles based on different templates can lead to conflicting styles and can potenti ...

Customizing Text Placement in HTML Lists with CSS List-Style-Image

Is there a way to adjust the vertical positioning of the "Blahs" in the list so that they appear closer to the center of each list bullet in the image displayed on my HTML code below? Here is the snippet of code: <html> <style> li { margin-to ...

CSS: What causes the gap below my border to appear?

I've noticed an issue in the HTML code snippet below: there seems to be some extra spacing under the border of the 'bucket' div. Despite my attempts, I haven't been able to figure out why this is happening. Can someone provide some ins ...

Utilizing Javascript and CSS for horizontal alignment from left to right

I have a JavaScript function that generates a list of store locations and creates a DIV beneath the map. Currently, the items are displayed top to bottom on the page. However, I would like to change the layout so that the items are shown as 3 in a row fro ...

Encountering npm issues following a git merge tainted by conflicts

Currently utilizing React with create-react-app, and I'm encountering a bit of a roadblock. Primary concern: How can I resolve the issues I'm facing with React? I'm relatively new to npm/React, so troubleshooting this has been a challenge f ...

What causes an undefined error to occur when setting default values after destructuring and assigning props in JavaScript?

Encountering issues with TypeScript in React that have arisen after updating Typescript, ESLint, Prettier, React, and Webstorm to their latest versions. Interestingly, no errors occur when the code is run on the web despite these updates. An example of a ...

Is it possible to modify the color of a mat-progress-bar based on its status?

Within my project, I have implemented a mat-table containing a mat-progress-bar within each row. <mat-cell *matCellDef="let element"> {{element.id}} - {{element.address}} <mat-progress-bar mode="determinate" [v ...

Encountering a 404 error page when attempting to access the NextJs App build, even though it is functioning perfectly in development mode

As a newcomer to React/Next JS, I encountered an issue after purchasing a theme and customizing the configuration and branding. Running the app with "yarn dev" and "yarn start" works fine, and "yarn build" produces an optimized production build. In my atte ...

Implementing Fade Component in Material-UI and React for Smooth Scroll Effects

I'm new to Material-UI and I want to incorporate its Fade component to create a fading effect for an element on my website. Currently, I have successfully implemented it like so: <Fade in timeout={3000}> <Typography variant="h3" classNam ...

Selection of text within a block resembling a bar of buttons

design.css body { background-color: #666666; margin-left:500px; margin-right:500px; margin-top:10px; margin-bottom:20px; font-family:Verdana, Geneva, Tahoma, sans-serif; font-size:12px; color:white; } div.header { bac ...

Intrusive JQuery Code Incorporating Itself into SharePoint 2010's HTML Markup

There seems to be an issue with my content editor web part wherein the menu, which is clickable and hoverable due to the jQuery installed, is causing some unexpected behavior. Whenever the menu is clicked or hovered over, it changes the content in the adja ...

Creating these three functions directly in the Parent Component instead of duplicating code in the child component - ReactJS

I am new to React and currently working on a dashboard page that includes a React Table. The page features a customize button that opens a popup with checkboxes to show/hide columns in the table. By default, all checkboxes are checked but unchecking a colu ...

Encountered an error while using webpack-dev-server on Windows_NT 7601 system,

Encountered an error while trying to run the following command: $ npm run dev I have used nodejs cmd, git, and have administrative privileges with the cmd. The error message is as follows: D:\IIT Samester\KAZ\ReactJSProjects\Git ...

Dynamic Website (Link Relationships / Responsive Design / Content Rendering with CSS and HTML)

Hello everyone! My name is Mauro Cordeiro, and I come from Brazil. I am just diving into the world of coding and have been following various tutorials. Stack Overflow has been an invaluable resource for me in my learning journey! Aside from coding, I am a ...

Concealing excess content in a vertical container with margins

I'm currently working on setting up a grid of thumbnails for my blog posts using Bootstrap 4. The columns have a size of col-md-6. Within each column, there is an anchor with a background image and a gradient overlay that transitions from black to tr ...

Resolve the issue of text overflow in PrimeNG Turbo Table cells

When utilizing Primeng table and enabling the scrollable feature, the table is expected to display a scrollbar while ensuring that the text within the cells does not overflow. Unfortunately, this expected behavior is not occurring. To see an example of th ...

Tips for modifying the border thickness of MUI icons

Is there a way to adjust the thickness of MUI icons' borders? If an icon has thick borders, how can you make the border lighter? https://i.sstatic.net/IGXwN.png ...

Identifying the camera model using getMediaStream

Are there methods available to determine if a user's device has a front, rear, or dual cameras installed? For instance, laptops typically only have a front-facing camera while some devices may have both. I am looking for a way to identify the type of ...

interactive symbols in a reorganizable tree structure

I have been developing a customizable tree list for our users to arrange their website content. It allows them to add and rearrange pages by dragging and dropping. Each list item includes the page name and three icons (lock, visible, and edit). The challe ...

React: Exploring the intricacies of importing components in the component-oriented versus library-oriented approach

Someone mentioned to me that there are two distinct methods for importing components/modules. The component approach The library method Does anyone have insights on these concepts? ...