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

Event fails to trigger when attached to different elements

Currently, I have an onchange event linked to the input text box and an onclick event attached to a text link. Interestingly, when I click on the link after editing the textbox, the click event does not trigger - instead, the change event is fired. If you ...

Verify if a certain value exists in an array while using ng-if inside ng-repeat

Currently, I have a loop using ng-repeat that goes through a list of wines obtained from an API. Alongside this, there is an array variable containing all the IDs of wines that have been marked as favorites and retrieved from the database. My goal is to sh ...

Insert text within the switch component using Material-UI

Looking to customize Material UI's Switch component with text inside? Check out the image below for an idea of what I'm going for. https://i.stack.imgur.com/KadRZ.png Take a look at my code snippet: import React from 'react'; import S ...

Default Value for Null in Angular DataTable DTColumnBuilder

What is the best way to define a default value in case of null? $scope.dtOptions = DTOptionsBuilder .fromSource('api/Restt/List'); $scope.dtColumns = [ DTColumnBuilder.newColumn('modi ...

Tips for inserting a Vue.js variable into a window.open event

Within this snippet of code: <tr v-for="person, index in People" :key='index'> <td> <button type="button" onclick="window.open('/details/'+person.id,'_blank')"> details</butto ...

The AJAX request encountered an error while trying to send a POST request to the http://localhost/upload/undefined endpoint. The

I've been scouring the internet and testing for hours, but I'm still unable to identify the source of the error. I could really use some assistance here. I meticulously followed a tutorial on multiple file uploads with drag & drop functionali ...

Sequentially loading Bootstrap columns as the page loads

Is there a way to load columns one by one with a time gap when the page is loaded? Here's the code snippet that can achieve this: setTimeout(function() { $("#box1").removeClass("noDisplay"); },1000); setTimeout(function() { ...

Using React-Router v6 to pass parameters with React

My App.js file contains all the Routes declarations: function App() { return ( <div className="App"> <Routes> <Route path="/"> <Route index element={<Homepage />} /> ...

Scrolling to a specific position on a page when a Vue 3 component appears is a must-do for

When I click a button, my basic form component appears without using the router. I would like the scroll position of the form to automatically move down slightly (for example, on the y-axis at 40) once it is displayed. However, I am unsure of how to achi ...

Express.js is still displaying the 'Not Found' message even after deleting the initial code

Despite multiple attempts to resolve what I initially thought was a caching issue by completely removing all code from my server, I am still facing the same problem: The default error handling provided by Express Generator in the app.js file contains the ...

How can you activate a prop in react native based on a certain condition?

To add a border to a native base button only if the menu index is equal to the house menu, use prop bordered. <Button bordered> <Text uppercase={false}>House</Text> </Button> My attempt: <Button {menuIndex == menus.house? ...

What is the proper method for utilizing assignments instead of simply assigning values directly?

In the process of developing a markdown editor, I am currently focusing on the functionality of the B (bold) button which needs to toggle. It's important to mention that I am utilizing this library to handle highlighted text in a textarea. Below is t ...

Set up an array data by extracting values from an array prop within a Vue component

Within my Vue component, I am dealing with an array prop called selectedSuppliers that consists of objects. My goal is to set up a data property named suppliers and initialize it with the values from selectedSuppliers. However, I do not want any modificati ...

The hover effect for a :before class is not functioning as intended

I have created a dropdown menu with a triangle at the top in this style: When the cursor hovers over only the triangle, it appears like this: However, when the cursor is over the div, the hover effect for both elements is activated as shown here: I am t ...

What is the best way to access a reference to the xgrid component in @material-ui?

Is there a way to obtain a global reference to the xgrid component in order to interact with it from other parts of the page? The current code snippet only returns a reference tied to the html div tag it is used in, and does not allow access to the compo ...

The current state has been refreshed, yet console.log continues to display the original value

'use client' import React, { useCallback, useEffect, useRef, useState } from 'react' import { Observer } from 'gsap-trial/Observer' import gsap from '@/utils/gsap' type Props = {} const TestPage = (props: Props) = ...

When a UI side makes a restApi call and subsequently closes the UI screen, the expected outcome will occur

Exploring the Interaction Between ReactJS Front End and Java 1.8 Spring Rest API When a call is made from the Front End UI to the REST API on the Backend Server, a delay in receiving the status is observed. What occurs on the server side in this scenario ...

Does the frame take precedence over the button?

const div = document.createElement('div'); // creating a dynamic div element div.setAttribute('id', "layer1"); // setting an id for the div div.className = "top"; // applying a customized CSS class div.style.position = "absolute"; // sp ...

JavaScript hovering drop-down feature

Hi there, I'm just starting out with javascript and could use some help with a simple script. I have a shopping cart drop down that currently activates when clicked. However, I want it to fade in when hovered over instead. I've tried using .hove ...

When using Ajax in Jquery and expecting data of type JSON, the response always seems

Looking to create a basic jQuery Ajax script that checks a user's discount code when the "Check Discount Code" button is clicked? Check out this prototype: <script> jQuery(function($) { $("#btn-check-discount").click(function() { c ...