Aligning Description Item components horizontally in antdLearn how to easily horizontally align Description

Currently, I am utilizing the `antd` Description components.

In this scenario, when there is no `title` for the items, the value should be aligned to the left. You can see an example of this alignment in the image below: https://i.sstatic.net/Ah70f.png

I have attempted to fix this issue without success. Can you provide guidance on how to resolve it?

Here is a snippet from demo.tsx:

import React from "react";
import "antd/dist/antd.css";
import "./index.css";
import { Descriptions } from "antd";

const App: React.FC = () => {
  const items = [
    { title: "title 1", value: "value-1" },
    { title: "title 2", value: "value-2" },
    { value: "value-3" }
  ];
  return (
    <Descriptions column={1} bordered>
      {items.map((description, index) =>
        description.title ? (
          <Descriptions.Item
            key={index}
            label={description.title}
            labelStyle={{ width: "25%" }}
          >
            {description.value}
          </Descriptions.Item>
        ) : (
          <div key={index}>{description.value}</div>
        )
      )}
    </Descriptions>
  );
};

export default App;

You can also view the code on Codesandbox:
https://codesandbox.io/s/border-antd-4-23-6-forked-5rr8eh?file=/demo.tsx

Answer №1

To merge the Description Item component, you will need to make some adjustments to its style. There are various methods to customize the CSS of antd - you can either override it using a CSS file or modify their pre-existing styles. Below is a possible solution, although not perfect, it may get the job done.

<Descriptions column={1} bordered>
  {items.map((description, index) => (
    <Descriptions.Item
      key={index}
      label={description.title ? description.title : description.value}
      labelStyle={
        description.title
          ? { width: "30%" }
          : { backgroundColor: "white", borderRight: "none" }
      }
    >
      {description.title && description.value}
    </Descriptions.Item>
  ))}
</Descriptions>

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

Utilizing the request module in Node.js with ExpressJS

Currently, I am in the process of creating a helper method within my code that will handle user authorization. This function, named "usePermissions", is being developed following the React approach but for backend functionality. Upon implementa ...

Upon loading, the Carousel is visible instead of being hidden, which is contrary to its intended behavior

Any help would be greatly appreciated as I am struggling with creating a web page featuring tabs for "London, New York, Shanghai". The initial page displayed is the "welcome" page with the other tabs hidden on load. I successfully implemented a carousel f ...

What is the method for obtaining the viewModel in a Knockout component?

I need to prepopulate a knockout component when the document is ready. This is the code I have written: function Finding(id, trigger) { var self = this; self.id = ko.observable(id); self.trigger = ko.observable(trigger); } function FindingVi ...

Eliminate unnecessary transparency in React Material UI Tooltip / Popper by adjusting opacity restrictions

Looking to integrate the Tooltip component from the React Material UI Library into my project. The code snippet I am using is as follows: <WhiteOnDarkGreyTooltipWithControls disableTouchListener disableFocusListener title={ <Text selectable ...

Unlocking the potential of nested conditional types in TypeScript

The source of the autogenerated type below stems from a GraphQL query: export type OfferQuery = { __typename?: 'Query' } & { offer: Types.Maybe< { __typename?: 'Offer' } & Pick<Types.Offer, 'id' | 'nam ...

It seems that the req.user object is not defined and the passport.deserializeUser function has not been invoked within the

After extensively researching similar questions, I have not found a useful response for my particular case. I am working on a simple todo app and I wish to integrate passport.js into it. Here is what I currently have: An Express app (PORT 3001) and Reac ...

The tab key seems to be malfunctioning when triggered during a jquery change event

I encountered an unusual issue with my jQuery events, and I'm not entirely sure if it's a problem related to jQuery. In hopes that some jQuery experts can shed some light on this. The code snippet below was included in my HTML page to automatica ...

What is the best way to showcase Json API content on an HTML page?

I possess a strong proficiency in html and css, however I lack experience in utilizing javascript. My aim is to showcase the date received from an API onto an html page Despite several attempts, I have not been able to achieve success yet. var getJSON ...

Associate keys with strings and then map them to a specific type of strings in Typescript

I am endeavoring to develop a React component that extends the Octicons icon library available from Github at @githubprimer/octicons-react. One of the components exported by the library is the iconsByName type, which has the following structure: type ico ...

Creating adaptable breakpoints for content using Bootstrap or pure CSS

I'm trying to create a responsive layout using the Bootstrap "row" and "col" classes, but I'm having trouble figuring out how to structure the content. Here's what I mean: https://i.sstatic.net/WkMmE.png This is my current HTML structure: ...

Click the button to automatically generate a serial number on the form

My form includes three input fields: sl no, stationerytype, and stationeryqty. By clicking the symbols + and -, I can add or delete these fields. I am attempting to automatically generate a Sl no in the sl no field when I click the plus symbol, and adjust ...

JavaScript - Modify the proposed content prior to inserting it into the input field

In my current project, I have implemented a feature using jQuery UI - v1.11.4, where an HTML textbox utilizes a JavaScript autocomplete functionality. The suggested string for the textbox is created by concatenating several columns (patient_no, patient_nam ...

Error in Node application: Cannot search for 'x' in 'y' using the 'in' operator with Express and Nunjucks

Hello everyone, I am a beginner in the world of Nunjucks/Express and Node.js. I have a routes file that is capturing the value of an input from a form field. My goal is to check if this value contains the string 'gov'. Here is what my code look ...

What is causing the CSS3 tabbed area to be restricted?

Experimenting with CSS tabs found at http://css-tricks.com/examples/CSSTabs/: Sample six .w3c { min-height: 250px; position: relative; width: 100%; } .w3c > div { display: inline; } .w3c > div > a { margin-left: -1px; position: relative; left: 1 ...

The Vue component should trigger the display of data in a Bootstrap modal based on the row of the button that was

Here is a sample code snippet demonstrating how data is fetched from the database: <table class="table table-bordered"> <thead> <tr><th>User ID</th><th>Account Number</th><th>Accou ...

The process of removing and appending a child element using WebDriverIO

I am trying to use browser.execute in WebDriverIO to remove a child element from a parent element and then append it back later. However, I keep receiving the error message "stale element reference: stale element not found". It is puzzling because keepin ...

Handling every promise in an array simultaneously

I am facing a problem with my array inside Promise.all. When I try to execute a function for the last iteration of forEach loop, I notice that my count_answers variable is only being set for the last object. This can be seen in the log output; the count_an ...

Troubleshooting Problems with Adjusting Left Margin Using JQuery

function adjust_width() { $('#cont').toggle(function(){ $('#cont').animate({marginLeft:'0%'}); },function(){ $('#cont').animate({marginLeft:'18.4%'}); }); } The code above is in ...

How should event listeners be unbound and child elements removed in single page applications?

I've recently delved into the world of memory leaks in JavaScript while working on a large single-page application. After using Chrome's Profiles (Snapshot) function, I noticed an abundance of detached DOM elements indicating a possible memory le ...

What is the best way to align the 5th and 6th list items to the left using CSS?

I am experimenting with Bootstrap to create a customized navbar. I am encountering difficulties in aligning the login and logout buttons to the right. Is there a way to achieve this? I have included my HTML and CSS code below: HTML code: <body> &l ...