Troubleshooting: Border not showing up in Tailwind CSS (React JS)

Below is the code snippet from my JSX file:

import { useState, useEffect } from "react";
import { PropTypes } from "prop-types";
import { HashtagIcon } from "@heroicons/react/24/outline";

// Function to fetch categories from the API (temporary replaced with hardcoded values)
const fetchCategories = () => {
  return new Promise((resolve) => {
    setTimeout(() => {
      const categories = [
        { id: 1, name: "Human Resources", icon: "icon" },
        { id: 2, name: "Technological Innovation", icon: "icon" },
        { id: 3, name: "Marketing Strategies", icon: "icon" },
        // More category objects...
      ];
      resolve(categories);
    }, 1000);
  });
};

function CategoryList({ onCategorySelect }) {
  const [categoryList, setCategoryList] = useState([]);

  useEffect(() => {
    // Load categories on component mount
    fetchCategories().then((categories) => {
      setCategoryList(categories);
    });
  }, []);

  function handleCategorySelect(categoryId) {
    // Function to filter ideas based on selected category
    onCategorySelect(categoryId);
  }

  return (
    <div className="flex flex-wrap">
      {categoryList.map((category) => (
        <div
          key={category.id}
          className="flex items-center justify-center w-1/3 md:w-1/4 lg:w-1/6 p-1 md:p-2 cursor-pointer"
          onClick={() => handleCategorySelect(category.id)}
          onKeyDown={(e) => {
            if (e.key === "Enter" || e.key === " ") {
              handleCategorySelect(category.id);
            }
          }}
          role="button"
          tabIndex={0}
        >
          <div className="flex flex-col items-center bg-orange-500 rounded-lg h-20 border-2 border-gray-700">
            <div className="flex items-center justify-center h-12 w-12 bg-indigo-200 rounded-full mb-2 mt-1">
              <HashtagIcon className="h-5 w-6" />
            </div>
            <div className="text-xs font-sans font-semibold truncate w-20 text-center">
              <span className="ml-1">{category.name}</span>
            </div>
          </div>
        </div>
      ))}
    </div>
  );
}

CategoryList.propTypes = {
  onCategorySelect: PropTypes.func.isRequired, // Callback function for category selection
};

export default CategoryList;

Issue: The borders are not showing in the specific line. Even after trying different div classNames, the borders still do not appear. I have tested it on a codesandbox file and the borders work fine there. I suspect it could be related to the functions used in my code, but I'm unsure of the exact cause.

I experimented with applying borders to other div classNames, but faced the same issue of borders not appearing. Therefore, I decided to test it out on a codesandbox file where the borders worked perfectly. I believe the problem might be due to the complexity of my functions, but I am unable to pinpoint the exact reason behind this issue.

Answer №1

I have a quick fix for this issue. Simply duplicate the CSS code I'm proposing

border-solid border (border-*color*-*number*)
, and you should see the border display properly (for some reason, it seems we need to specify it twice in Tailwind).

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

Issue arises after injecting HTML element into the DOM due to memory constraints and display inconsistencies

Upon executing the following script in Firefox... var d = $("<div class='test'></div>"); d.hide(); $("body").prepend(d); d.show(); ...and examining the HTML, the inserted element will have the style attribute: style="display: blo ...

Should children handle showing/hiding the drawer, or should Redux be used for this task?

<Drawer type='temporary'> <SomeContainer> </Drawer> One option is to: A.) Maintain the state in the main App component, and pass the showDrawer / hideDrawer functions down to the lowest level component. B.) Use Redux to dis ...

Enhancing the appearance of the Switcher by framing it with

I've been working with the component package https://www.npmjs.com/package/react-switch-selector to create a design similar to this https://i.stack.imgur.com/voHqm.png Although I have made some progress, I'm struggling to add a border outline. H ...

Adjusting the height of a vertical slider in Vuetify2 is not customizable

I've been trying to adjust the height of a vertical slider in vuetify2, but setting it to "800px" or using style="height:800px" doesn't seem to work as intended. Even though the box within my grid expands, the height of the slider remains unchan ...

Customize the default tab appearance in bootstrap version 5.2

Is there a way to customize the appearance of these tabs? I'm looking to change the color to match the primary color of Bootstrap. https://i.sstatic.net/6HaUO.png instead of https://i.sstatic.net/qHUZ9.png <!DOCTYPE html> <html> & ...

Tips for customizing scroll bar padding and margin using CSS classes or IDs

I am looking to customize three different types of scrollbars with unique padding and margins. Here is the global style for my scrollbars: /* Modifying the scroll bar across the whole application */ /* width */ ::-webkit-scrollbar { width: 5px; he ...

Strategies for incorporating a design in Next.js

Currently, I'm developing a frontend project using Next.js and Tailwind CSS. I have received a Figma design to incorporate into the project. One of the sections requires me to display a series of steps: https://i.stack.imgur.com/gDmGQ.png Do you hav ...

Resize a span's width using the width of another element using only CSS

Website Development <div class="container"> <div id="setter"> <span>some unique content here</span> </div> <div class="wrap"> <span> different text goes here, different text goes here, diffe ...

Tips for accurately documenting the Props parameter in a React component with Destructuring assignment

Attempting to create JSDocs for a React component using destructuring assignment to access props: const PostComponent: React.FC<IPostComponent> = ({ title, body }) => { ... } The issue arises when trying to document multiple parameters in JSDocs ...

Converting React useState to a JSON object data type

I imported a JSON data file using the following code: import data from "../data.json"; The contents of the file are as follows: [ { "name": "Emery", }, { "name": "Astrid", }, { " ...

Enhance rendering efficiency with a customized tooltip for MUI ratings

Attempting to display tooltips upon selecting a rating star, however the performance is lacking due to large MUI components. I am curious if it's possible to achieve the same effect using IconContainerComponent. <Tooltip title={labels[ratingToolti ...

Unable to get 100% height to work properly in HTML5 ASP.net because of the DOCTYPE

I'm currently working on creating an Asp.net website with a unique single-page portfolio style for the homepage. Each project or section should be 100% height of the viewport, stacked underneath each other to make use of anchor tags. However, I'm ...

Is it possible for me to make the default export anonymous?

Why bother naming the export if you already have a file with the default export name? This seems redundant and goes against the DRY principle. While there is a rule that discourages anonymous default exports, how can we enforce an error when someone does ...

Guide to programmatically closing the TEMPORARY MUI DRAWER when an event finishes in a React application

I am currently implementing the MUI Drawer in my project, and I am facing a challenge with closing the drawer when a user-initiated event is completed. The issue lies in the fact that the component where the event is initiated and the component that render ...

Tips for dynamically expanding the interface or type of an object in TypeScript

Currently, I am exploring the integration of PayPal's Glamorous CSS-in-JS library into a boilerplate project that also utilizes TypeScript. Glamorous provides a way to incorporate props into an element as shown below: const Section = glamorous.secti ...

React issue with no unused expressions

Currently, I am in the process of developing my own eCommerce platform using React. One crucial component of this project is the ProductList.js, which manages the display of various products through the code written in Product.js. To facilitate data manage ...

Is a table cell's border considered as part of its content?

A discrepancy is observed in the rendering of a document on Firefox and Chrome browsers: <!DOCTYPE html> <html> <head> <title>Testing table rendering</title> <style> table { ...

What is the best way to adjust the row and column layout in bootstrap?

As I was creating a layout to showcase all of the bootstrap cards in a neat and organized manner, I noticed a peculiar issue that's been bothering me. Everything looks great when the columns are filled or when there's only one card present. Howev ...

Exploring the process of iterating through fetched arrays and presenting the outcomes using Next.js

I'm encountering an issue while attempting to iterate through an array and display the results individually on my website. The error message that keeps appearing is: TypeError: this.props.fetched.map is not a function I'm unsure of what is caus ...

What is the best way to store a file object in React's state?

I am currently working on setting the state for a file object that is being passed between modals before it is uploaded to the server. Below is the code snippet that demonstrates what I am attempting to achieve. const initialState = { selectedD ...