The Chakra Card component is being displayed in a vertical layout instead of the usual horizontal

I'm currently working on rendering a card and organizing each card in rows of three, with the added flexibility of altering this number responsively.

I'm struggling to identify which parts of the code are conflicting with SimpleGrid, and have experimented with using Grid and Flex. Additionally, I don't have any CSS implemented at the moment.

Below is the snippet of code that I am trying to render:

 return (
    <>
      {data.map((item: ICard, index: number) => (
        <SimpleGrid columns={3} minChildWidth="30%" py={6} ml={10} key={index}>
          <Box
            maxW={"445px"}
            w={"full"}
            boxShadow={"2xl"}
            rounded={"md"}
            p={6}
            overflow={"hidden"}
          >
            <Box
              h={"310px"}
              bg={"gray.100"}
              mt={-6}
              mx={-6}
              mb={6}
              pos={"relative"}
            >
              <div
                style={{
                  height: 310,
                  width: 445,
                  backgroundImage: `url(${
                    item.edmIsShownBy ?? item.edmPreview
                  })`,
                  backgroundSize: "cover",
                  backgroundPosition: "middle",
                }}
              ></div>
            </Box>
            <Stack>
              <Text
                color={"green.500"}
                textTransform={"uppercase"}
                fontWeight={800}
                fontSize={"sm"}
                letterSpacing={1.1}
              >
                {item.dcCreator ?? searchTerm ?? "Unknown Artist"} {item.year}
              </Text>
              <Heading fontSize={"2xl"} fontFamily={"body"}>
                {item.title}
              </Heading>
              <Text color={"gray.500"} noOfLines={4}>
                {item.dcDescription ?? item.dcDescriptionLangAware}
              </Text>
            </Stack>
            <Stack mt={6} direction={"row"} spacing={4} align={"center"}>
              <Avatar
                src={item.edmPreview ?? item.edmIsShownBy}
                alt={"Author"}
              />
              <Stack direction={"column"} spacing={0} fontSize={"sm"}>
                <Text fontWeight={600}>
                  {item.dataProvider}, {item.country}
                </Text>
                <Text color={"gray.500"} noOfLines={3} mx={1}>
                  Find {item.title ?? "this artwork"} at{" "}
                  <a href="url">{item.source ?? item.edmIsShownAt}</a>
                </Text>
              </Stack>
            </Stack>
          </Box>
        </SimpleGrid>
      ))}
    </>
  );

Answer №1

Ensure to separate the SimpleGrid from the data.map. Otherwise, a SimpleGrid will be rendered for each record:

Here is a test I conducted (added dummy data) ==>

import * as React from "react";
import {
  Box,
  SimpleGrid,
  Stack,
  Heading,
  Text,
  Avatar
} from "@chakra-ui/react";

export default function Example() {
  const data: any = [
    { id: 1, title: "title1" },
    { id: 2, title: "title2" },
    { id: 3, title: "title3" }
  ];

  return (
    <>
      <SimpleGrid columns={3} minChildWidth="30%" py={6} ml={10}>
        {data.map((item: any, index: number) => {
          return (
            <Box
              maxW={"445px"}
              w={"full"}
              boxShadow={"2xl"}
              rounded={"md"}
              p={6}
              overflow={"hidden"}
            >
              <Box
                h={"310px"}
                bg={"gray.100"}
                mt={-6}
                mx={-6}
                mb={6}
                pos={"relative"}
              >
                <div
                  style={{
                    height: 310,
                    width: 445,
                    backgroundImage: "",
                    backgroundSize: "cover",
                    backgroundPosition: "middle"
                  }}
                ></div>
              </Box>
              <Stack>
                <Text
                  color={"green.500"}
                  textTransform={"uppercase"}
                  fontWeight={800}
                  fontSize={"sm"}
                  letterSpacing={1.1}
                >
                  {"Unknown Artist"} 2008
                </Text>
                <Heading fontSize={"2xl"} fontFamily={"body"}>
                  {item.title}
                </Heading>
                <Text color={"gray.500"} noOfLines={4}>
                  {item.dcDescription ?? item.dcDescriptionLangAware}
                </Text>
              </Stack>
              <Stack mt={6} direction={"row"} spacing={4} align={"center"}>
                <Avatar
                  src={item.edmPreview ?? item.edmIsShownBy}
                  alt={"Author"}
                />
                <Stack direction={"column"} spacing={0} fontSize={"sm"}>
                  <Text fontWeight={600}>
                    {item.dataProvider}, {item.country}
                  </Text>
                  <Text color={"gray.500"} noOfLines={3} mx={1}>
                    Find {item.title ?? "this artwork"} at{" "}
                    <a href="url">{item.source ?? item.edmIsShownAt}</a>
                  </Text>
                </Stack>
              </Stack>
            </Box>
          );
        })}
      </SimpleGrid>
    </>
  );
}

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

Images in CSS not copied to the output directory when using Webpack

Using Webpack to bundle various javascript and css files on a website includes bundling bootstrap.css and chosen.css as part of the bundles. To achieve this, there is a main.js file serving as an entry point for importing all necessary files. The process i ...

Dynamic styling with jQuery input focus animation

Whenever I interact with the input field, I want my border colors to animate in and fade out smoothly. But I'm facing some challenges. Here is how I've set it up: HTML <input type="text" id="search-input" placeholder=&quo ...

Creating a sort button in HTML that can efficiently sort various divs within a table is a useful tool for enhancing user experience

My HTML table is populated with various <td> elements. How can I arrange these divs based on IMDb rating, TomatoMeter, etc... [ CSS code is not provided below ] <table> <tr class="row"> <td class="column"> <br> ...

Issue with Material-UI TextField not functioning correctly when nested inside Popper component within a Dialog

Issues arise when Material-UI input elements like TextField do not function properly or cannot receive focus when placed within a Popper inside a Dialog. <Dialog open={true}> ... <Popper open={true} style={{zIndex: 1500}}> ... < ...

Utilizing React to retrieve API data and implement search input filtering with autocomplete functionality

Hey there, I have a query regarding a React filter search input component. Currently, I am working with two components: FirstPageComponent.js import React from "react" import AutoComplete from "./AutoComplete" export class FirstPageComponent extends Re ...

Positioning the video tag bar in HTML is a crucial element to

**Take a look at what I'm discussing here(http://jsfiddle.net/VpLyR/). I'm dealing with a simple code that includes a video tag (html) and a menu bar with a fixed position. The issue arises when I scroll down to the point where both the menu bar ...

Encountering a Typescript error while attempting to iterate through Enum keys for generating JSX components

I'm really struggling with this problem. Here's a simple enum I have: export enum depositTypes { ACH = 42, Wire = 36, Check = 3, Credit = 2, } I'm trying to create option tags for a select element, like so: Object.keys(depositTyp ...

Having issues with the `onlyCountries` property in the React phone input 2 component when using

I've integrated the react-phone-input-2 library to include phone number fields in my project. I need to provide selected countries only for the country codes. I'm fetching iso2countrycodes from the server and passing them to my Phone input compon ...

Modern design featuring soft borders that blend into the background

I am in the process of bringing a unique webpage layout to life. The design is a bit unconventional, and I'm not sure if it's feasible. Essentially, I plan to have a fixed-width content box of 900px positioned in the center of the page body. I ai ...

How to place a button in SwiperJs using React

Can anyone provide guidance on how to position the navigation buttons in a manner similar to the image below? The desired layout is for the buttons to appear on the outer edges of the swiper component. You can refer to this demo for more information. htt ...

What is the best method to update numerous low-resolution image sources with higher resolution images once they have finished loading?

I'm currently developing a website that implements a strategy of loading low-resolution images first, and then swapping them for high-resolution versions once they are fully loaded. By doing this, we aim to speed up the initial loading time by display ...

In Next.js, the client-side elements are deferred from loading until the user clicks on the page

Upon the initial page load, client-side elements do not appear until the page is clicked for the first time. Subsequent visits do not experience this issue. The situation arises when using a Next.js app router solution and invoking the API call within the ...

Unable to locate a contact within the state

Currently, I am diving into the world of React by exploring its documentation and challenging myself to build a small chat application. While I have a good grasp on the basics, I am encountering some issues with states. Within my code, there is an object ...

Attempting to enhance a React program by upgrading it from version 16 to 17

Recently, I've inherited an older React app that was developed by a previous developer. The task at hand is to update it from React 16.13.1 to React 17 in order to incorporate Material UI v5 and utilize its latest features. However, every time I attem ...

Swirling hues transforming into #000000 upon second attempt

My goal is to create a button that generates two random color codes. Initially, this button seems to work fine on the first click, but on the second click, both codes turn into #000000. Despite my attempts to troubleshoot the issue, I haven't been ab ...

The JavaScript program for the shopping list is experiencing issues with the formatting of list items

I have been working on developing a shopping list program using JavaScript. The program includes an input box and an "add item" button, which adds the text entered in the input field to an unordered list as a list item. Each list item also contains an imag ...

Notification box appearing at the lower part of the display

I have recently been given the task of updating my company's JavaScript alerts with more customizable bootbox alerts. After playing around with it, I managed to make an alert appear when a button is clicked, but the alert keeps showing up at the botto ...

Navigation Menu Dropdown Present on the Right Side and Arranged in a Horizontal Stack

I'm having trouble with a dropdown menu in my navigation bar. I followed the example on W3Schools but when I hover, the menu appears horizontally instead of vertically and to the far right of the page. I've searched for solutions but can't s ...

The method through which an axios interceptor is activated

I am in the process of creating a response interceptor that will determine the status type and set a flag based on this status. This flag will then be used to load an Ant Design modal popup. I need this Interceptor to be triggered for every HTTP call and I ...

The declaration file for the module 'react-faq-component' was not found

I am encountering an issue while trying to implement the react-faq-component in my project. I've followed a similar example from the provided link, with some additional TypeScript usage. Here is a glimpse of my code so far: index.tsx import React fr ...