Combine and interchange horizontal and vertical form designs within antd 5 for a personalized touch

I need to customize the layout of a form to display checkboxes in vertical mode. Specifically, there is a row of checkboxes that I want to appear vertically aligned rather than horizontally.

In the past, I was able to achieve this in antd 4 by applying a custom CSS class as an override.

Below is a snippet of how the form items are structured within the vertical form:

<Row className="horizontal-override">
          <Form.Item name="Available" label="Available" valuePropName="checked">
            <Checkbox onChange={onInputChange} />
          </Form.Item>
          <Divider type="vertical" />
          <Form.Item name="ShipHomeOnly" label="ShipHome Only" valuePropName="checked">
            <Checkbox onChange={onInputChange} />
          </Form.Item>
          ...//More of the same
</Row>

The previous CSS override used in antd 4 looked like this:

.ant-form{
  .horizontal-override{
    .ant-form-item{
      flex-direction: inherit;
      label{
        display: inline-flex;
        height: 32px;
        margin-right: 4px;
        align-items: center;
      }
    }
  }
}

This CSS class was able to replicate the horizontal styling for the row of checkboxes within the form.

However, with antd version 5, the styling has undergone significant changes, and I am currently unable to find a solution to achieve the same effect.

Answer №1

If you're using antd and need to customize styles with CSS, you'll have to find the specific classes within the dev console. It can be a bit tedious, but currently that's the only method available.

In your situation, try modifying ant-form-item-row instead. It seems like in version 5, developers included an additional div in the layout:

.horizontal-override > .ant-form-item {
  flex-direction: inherit;

  .ant-form-item-row {
    display: inline-flex;
    height: 32px;
    flex-direction: row,
    flex-wrap: nowrap;
  }
}

I recommend adding !important after each style declaration to ensure that antd does not override these styles.

You can also check out a working example on codesandbox here.

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

What is the best method for setting the height of an empty inline block element to match the line height of its container?

By default, inline-block elements adjust their height based on the container's line height only when they have content. However, I've noticed that empty or whitespace-only inline block elements default to a height of 0 (observed in Firefox). Is ...

Mastering the Art of Defining JavaScript Classes in React-Native

In my React Native project, I am faced with a situation where I need to create a new class: class customClass { email: string; name: string; constructor() { setUser(fbid: string, token: string): boolean { To keep things organized, I decide ...

Ways to adjust the color of a navbar link according to the current page you are visiting?

I'm looking to implement a feature on my website where the area around the nav-link darkens when someone navigates to a certain page, making it easier for them to see which page they are currently on. I am working with Bootstrap v4.3.1 and Razor Pages ...

Positioning the subheading "perfectly beneath the main heading" for a clean and professional look

I'm feeling a bit lost when it comes to tasks like this. While I can easily design an entire website using html and css, I start to question my approach when faced with challenges like these. Could someone offer some guidance? My goal is to have a H1 ...

Is there a way to decrease these values in my firestore using a loop?

My goal was to decrease the quantities of the color upon form submission. The setup includes forms where users can select a product, enter quantity, choose colors, and add more products. Upon submitting the data, it looks like this: The Firestore documen ...

The method continues to receive null values from Ajax despite successfully retrieving the data from Facebook

My current challenge involves creating a login using Facebook. The console indicates that the requested data (email, first_name, etc.) is being retrieved successfully, but for some reason, the AJAX request keeps sending null data to the PHP method. Below ...

Manage and modify data values

Currently, I am developing a weather forecast app and facing an issue with changing the temperature from Celsius to Fahrenheit upon hovering. Despite my attempts, the changes I make either do not reflect or completely erase the line. I am eager to learn ...

Error: Attempting to access property 'setData' of an undefined object results in a TypeError [Slider]

I encountered an error with my slider that says Uncaught TypeError: Cannot read property 'setData' of undefined. The error occurs when I use material ui as a component along with redux-form. This issue happens specifically when the slider is bein ...

Modify the paragraph's class upon clicking the radio button

I have been struggling with changing the color of <p> based on the radio button selected using two classes, red and blue. However, for some reason, it's not working as expected. If anyone has any insights or suggestions on how to fix this issue ...

What is the best way to create a delay so that it only appears after 16 seconds have elapsed?

Is there a way to delay the appearance of the sliding box until 16 seconds have passed? <script type="text/javascript"> $(function() { $(window).scroll(function(){ var distanceTop = $('#last').offset().top - $(window).height(); ...

Unable to assign image src to a dynamically generated div

My current task involves setting the background URL of a dynamically created div in JavaScript, intended for use with the jQuery Orbit slider. Below is my approach: var content1 = null; $("#featured").html("<div id='content' style='&apos ...

Retrieve the Axios response without interruption, even in the event of an exception, when making API calls with multiple files

Currently, as a beginner diving into Vue.js, I am exploring the world of frontend development by integrating Vue with my Laravel backend. To streamline my API calls and make them more organized for different models, I decided to create a separate file name ...

Enhancing the efficiency of a TypeScript-written file content parsing class

Seeking advice on optimizing a typescript module used by a VSCode extension. This module accepts a directory and parses the content within the files, which can be time-consuming for directories with a large number of files. To avoid copying the entire cla ...

Ensuring the successful execution of all AJAX calls (not just completion)

I've seen this question asked many times about how to trigger a function once all AJAX calls have finished. The typical solution involves using jquery.stop(). However, my situation is unique - I want to display a confirmation banner only after all AJA ...

Unable to initiate npm start due to author problem

I ran into an issue when trying to start npm in the command prompt: package.json: { "name": "reactapp", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "start": "webpack-d ...

Tips on showing a specific div when a button is clicked using jQuery and Bootstrap

In my button group, I have four buttons and I need one specific button to display certain div content when clicked. The displayed content should be based on which button is clicked. Is there a way to achieve this using Twitter Bootstrap jQuery in ASP.NET ...

Refresh the div based on the script's output

Currently, I am struggling to make a password change form work properly as I have limited knowledge of jQuery. The form successfully changes the password, but there is no visual feedback for the user. When I submit the form, it routes to changePassword.php ...

JavaScript is reliant on the presence of the alert() function to properly function

I have a JavaScript function that performs well, except for when I remove or comment out the alert() line. This function is designed to calculate the sum of values in up to 30 fields if they are present and contain a value. Here is an example of the HTML ...

Save information entered into dynamically created input boxes in an array

I am currently working on a project to develop a website that generates timetables. However, I have encountered a roadblock in my progress. My issue lies in dynamically generating user-selected text boxes for subjects and faculties using a for loop. Unfor ...

The jQuery response appears blank in the browser, despite the fact that it works fine with

Utilizing jQuery's .ajax() function to communicate with a local Django runserver and retrieve a response. Observing the server console, the JSON request is received properly, a correct JSON response is generated, and all appears in order. However, i ...