The Materialize CSS tabs are aligning vertically below each other, but functioning correctly upon refreshing the page

When using materialize css tabs, all the divs load one below the other on the initial page load.

If I refresh the page, it starts behaving properly.

<div class="row">
<div class="col s12">
  <ul class="tabs">
    <li class="tab col s3"><a href="#test1">Test 1</a></li>
    <li class="tab col s3"><a class="active" href="#test2">Test 2</a></li>
    <li class="tab col s3 disabled"><a href="#test3">Disabled Tab</a></li>
    <li class="tab col s3"><a href="#test4">Test 4</a></li>
  </ul>
</div>
<div id="test1" class="col s12">Test 1</div>
<div id="test2" class="col s12">Test 2</div>
<div id="test3" class="col s12">Test 3</div>
<div id="test4" class="col s12">Test 4</div>

This issue occurs initially or after a server restart:

snippet

The problem is resolved upon refreshing the page as expected.

I have included all necessary js (jquery and materialize) and css files with tab initialization.

$(window).on("load", function () {
    $('ul.tabs').tabs();
  });

I have also tried:

$(document).ready(function () {
        $('ul.tabs').tabs();
      });

However, the issue persists.

If anyone knows a solution to this problem, please share.

I encounter several issues like this with materialize.

Additionally, I am using react which may be contributing to the problem.

When using react-materialize, I face the following dilemma:

<Tabs className='tab purple darken-4'>
                <div className="container">
                    <Tab title="All">1</Tab>
                    <Tab title="Ongoing" active>2</Tab>
                    <Tab title="Successful">3</Tab>
                    <Tab title="Failed/Warning">4</Tab>
            </div>
 </Tabs>

React issue on adding divs

Answer №1

Utilizing the Tabs component in react-materialize involves rendering child components accordingly. However, when all components are wrapped within a single div, it causes the render to break.

To address this issue, you can structure your code like so:

<div className="container">
    <Tabs className='tab purple darken-4'>
        <Tab title="All">1</Tab>
        <Tab title="Ongoing" active>2</Tab>
        <Tab title="Successful">3</Tab>
        <Tab title="Failed/Warning">4</Tab>       
    </Tabs>
</div>

Alternatively,

<Tabs className='tab purple darken-4'>
    <Tab title="All">
        <div className="container">
            1
        </div>
    </Tab>
    <Tab title="Ongoing">
        <div className="container">
            2
        </div>
    </Tab>
    <Tab title="Successful">
        <div className="container">
            3
        </div>
    </Tab>
    <Tab title="Failed/Warning">
        <div className="container">
            4
        </div>
    </Tab>    
</Tabs>

If you wish to customize the appearance of the Tabs or an individual Tab component, you can utilize the className prop as well.

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

A more advanced approach to validating form input in React/Next Js

I have designed a basic form for my web application. I am considering adding a feature to validate all fields, ensuring they are not empty and displaying an error message if necessary. Here is the outline of what I have so far: import { useState } from &ap ...

Enhance the appearance of your Table footer with a personalized touch

I have two different Text components that I am working with. You can view some examples of these components here. Here is the scenario: Text1 is located within a form (labeled as text) Text2 is situated in the footer area of a table In each text, I hav ...

MDX is revolutionizing Next app routing with the introduction of 'use client' functionality

After setting up MDX with Next.js 14, I encountered an error when navigating to the mdx page: Error: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. The file mdx-components.tsx is ...

What is the best way to show inline icons within menu items?

Issue Upon selecting an option from the menu, I encounter a problem where the icon (represented by a question mark inside a speech bubble) appears on a different line than the text ("Question"). Fig. 1. Display of menu after selection with the icon and t ...

Exploring Three.js: Meshes, Triangles, and the Beauty of Lambert

I have a function that generates stars, here is the code: function CreateStar( radius, thickness, isWireframe, starColor) { // material var starMaterial = new THREE.MeshLambertMaterial({ color: starColor, ...

Exploring the Interactive Possibilities of CSS3 with Background Tiles

I'm struggling to implement a flip effect where the content of a div changes, but I can't seem to prevent the text from disappearing after a few seconds. I've tried using backface-visibility:hidden with no luck! HTML <div class="cards" ...

Encountering difficulties accessing XML file on server via anchor tag

I have an XML file on the server that I am attempting to open in a browser when the user clicks on a link. Below is how I have set up the link, but it is not opening the file: Code: <a title="View XML" href="file://///90.0.0.15/docmgmtandpub/PublishD ...

Adjust the appearance depending on the React state variable

I am trying to add animation to a search icon when clicked in React. Using the useRef hook, I am able to access the element and applying custom styles to it. const [searchBar, setSearchBar ] = useState(false); const searchIcon = useRef(); const searchIconS ...

Unable to showcase date using react-datepicker when using react-hooks-forms on the interface

I am currently working on a form using next.js, where I need to store date along with other fields. To achieve this, I am utilizing react-form-hooks and react-datepicker Issue: After clicking submit, the date entry is visible in console.log but not appea ...

Troubleshooting async/await issues in certain IDEs

I've been experimenting with aysnc and await in my project. While it worked perfectly in FiddleJS, I encountered an error when trying to implement it in my IDE (PHPSTORM 2017): async function test(url){ ^^^^^^^^ SyntaxError: Unexpected token f ...

React-Troubleshooting list items and keys: A comprehensive guide to resolving common issues

I'm facing a challenge with generating unique key ID's for my list items. Even though I thought I had a good understanding of how unique keys function, it seems that I am mistaken. In the code snippet below, using key={index} or key={item} is no ...

React-vertical-timeline component is failing to display on the webpage. The content in the output HTML remains concealed due to the presence of the "is-hidden"

I am facing an issue while trying to incorporate a vertical timeline into my project. The generated HTML code does not display the timeline as expected. Upon inspection, I noticed that the classes are set to be hidden with "is-hidden". It seems like there ...

"react commands" are not recognized as an internal or external command by any program or batch file

Initially, everything was working smoothly until I decided to download some updates from the git repository. However, upon execution, I encountered an error message stating that "react scripts" are not recognized as an internal or external command, operabl ...

Removing the Tawk.to integration in React Redux using external JavaScript

Seeking help with integrating the Tawk.To Widget into my React APP. The widget (javascript) loads successfully when the page is first opened, but remains present when navigating to another page. How can I properly unmount this script when moving to a diff ...

Is there a way for me to retrieve the data inputted into this form using JavaScript?

Having some trouble with this code. Can someone help me figure out what's going wrong? function displayData() { var userInput; userInput = document.getElementById(userInputs.firstInput); alert ("You entered: " + userInput); } <form ...

parallax scrolling can be a bit bumpy

While working on a website, I've incorporated a slight parallax effect that is functioning almost perfectly. However, I've noticed that the foreground divs tend to jump a little when scrolling down the page. At the top of the page, there is a di ...

The total height of the document's body in jQuery is not equal to the sum of the viewport height and the window's scroll top position at the bottom of the document

Why does the document height appear smaller than the window scroll top value plus the viewport height when I reach the end of the document? Shouldn't they be equal? I've been struggling with this issue for hours and can't seem to figure it o ...

The content generated by Material-UI on the server side does not align with the content rendered

I have integrated MaterialUI with React 16 and implemented server-side rendering. Everything seems to be working fine, but I am getting a warning from React about the server-side and client-side markups not matching. Can someone please point out what I mig ...

Verify if the second list item contains the "current" class

When displaying a list of blog items on the blog page, I am using grid-column: 1 / -2;. In the first row, the first blog item spans two columns while the second and subsequent rows display three items in each row. This setup works well, but when moving to ...

The parameter 'prev: todoType[] => todoType[]' cannot be assigned to the type 'todoType[]'.ts(2345)

An issue has arisen with this.props.update as mentioned in the title import { useState } from "react"; import axios from "axios"; import { todoType } from "../../types/todo"; type sendResponse = { task: string; }; type getRe ...