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:

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

Learn the process of implementing an SVG icon in your Angular Material project

I'm currently attempting to incorporate a single icon into my Angular Material application. Following the documentation, I have implemented $mdIconProvider in the following manner: app.config(function($stateProvider, $urlRouterProvider, $mdIconProvid ...

What could be causing the unexpected behavior in my NgMessages form validation?

I have developed a code that incorporates Angular JS form validation methods. There are two separate forms within the codebase, The initial form utilizes basic form validation while the second form employs ng-messages, However, an issue has arisen wher ...

Unexpected behavior observed in while loop with dual conditions

To break the while loop, I need two conditions to be met - res must not be undefined, which only happens when the status code is 200, and obj.owner needs to match a specific value I have set. Since it takes a few seconds for the owner on that page to updat ...

Display information from a specific identifier in a modal popup window after clicking a button using PHP and MySQL

When a button is clicked on my website, a popup window appears using modal functionality. The issue I am facing is not being able to retrieve the correct data based on the id of the button. Below is the HTML table code snippet: <tbody> <?php $cou ...

Using bootstrap's center-block class, you can easily center

I'm attempting to center the content of a form. <div class="login-container"> <div class="center-block"> <form action="/joinChart" method="get"> <input name="username" id="username" type="text"><br><br> ...

Animating CSS styles in Vue.js based on JavaScript triggers

Within my Vue.js application, I've implemented a login form that I'd like to shake whenever a login attempt fails. Though I have achieved the desired shaking effect, I'm not completely satisfied with my current solution. Here's a simpl ...

TypeScript generic types allow you to create reusable components that

function genericIdentity<T>(arg: T): T { return arg; } let myGenericIdentity: <U>(arg: U) => U = genericIdentity; I see that the 'genericIdentity' function is accepting an argument of a generic type. However, I am unsure about ...

Retrieve the chosen selection from a dropdown menu using AngularJS and Ionic

I've been encountering some issues with the select feature in AngularJS. Despite searching extensively for solutions, none seem to be working for me. The JSON structure I'm dealing with is generated from my service.php: [ { "Name": ...

Adding x days to a Unix timestamp can be achieved by converting the Unix timestamp

Currently, I have the following code snippet: let currentTS = Math.floor(+new Date() / 1000) This code successfully retrieves the current date in a unix timestamp. However, my goal now is to append an additional 14 days to this unix timestamp. Could some ...

Need help in NestJS with returning a buffer to a streamable file? I encountered an error stating that a string is not assignable to a buffer parameter. Can anyone provide guidance on resolving this issue?

The issue description: I am having trouble returning a StreamableFile from a buffer. I have attempted to use buffer.from, but it does not seem to work, resulting in the error message below. Concern in French language: Aucune surcharge ne correspond à cet ...

Creating an expandable discussion area (part II)

After checking out this query that was posted earlier, I am interested in implementing a similar feature using AJAX to load the comment box without having to refresh the entire page. My platform of choice is Google App Engine with Python as the primary lan ...

When the state changes in React, the useSelector hook does not provide real-time updates

Currently, I am in the process of implementing a search feature using React and Redux Thunk. The main requirement for this search functionality is to fetch data from an API by calling a thunk action and updating the state accordingly for display on the UI. ...

"Sharing fields between mongoose models: How can I reference a field from one model in another

I am currently working on linking specific fields from the User model to the Card schema using the username as a reference point. Let me provide an example using my Card schema: const CardSchema = new mongoose.Schema({ text: { type: String, ...

"Utilizing jQuery to Send POST Requests on Rails - Dealing

Currently, I am running a JavaScript game from file:// and attempting to send a post request to a localhost Rails server in order to add a new high score. In my JavaScript: highScoresEntryView.keyHandlers = function() { var that = this; this.pa ...

What is the best way to access props from a different file in a React application?

I am facing a challenge with my two files: EnhancedTableHead and OrderDialog. I need to access the props data from EnhancedTabledHead in my OrderDialog file. Is there a way to achieve this? Here is how my files are structured: //OrderDialog.jsx import ...

Using React.js to send an Axios post request to a Node.js API

Hello, I'm facing some issues with sending all the data in my request using axios. I have set up a node.js API and now I am trying to send user registration data from my form using axios and React.js as my front-end technology. After updating my stat ...

Ways to avoid automatic error correction when running npm lint?

Utilizing the Vue CLI, I developed a Vue3 app with a Prettier/Eslint configuration. Upon making changes to the main.ts file as shown below: import { createApp } from "vue"; import App from "./App.vue"; import router from "./router& ...

Update the formatting of the dates in the dateRangePicker

Utilizing a dateRangePicker, I am receiving dates in the format "mm-dd-yyyy". Below is my HTML code: <input type="text" name="TextDate" value="10/24/1984" /> Here is the script being used: <script> $(function() { $(&apos ...

disable any other active toggle in a vue component

Exploring JavaScript and how to accomplish the following tasks Snapshot The issue I am facing is that if I click on a product, and then click on settings, both are open. However, I want only the currently clicked toggle to be open. For instance, if I cl ...

Tips for exporting a variable within the render function in React JS:

class Something extends React.component{ render(){ const a = this.state.details.map((detail) => ( <Home key={detail.id} login={detail} /> )); return(/* Some code */) } Is there a way to export the variable a from the render function and uti ...