Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Antd how to fixe the size of the multi selection component?

I am using the Ant design components for React. I would like to fixe the size of the multi selection input fields in order to have the selected values into the same line without taking a new line like is the default behavior :

https://ant.design/components/select/#components-select-demo-multiple

I need to have the values ranged into the same line.

I can fixe the size of the input fields by overriding the style

.ant-select-selection--multiple:before, .ant-select-selection--multiple:after  {
display: inline !important;  }

But when I select several values, then they are outside the inputr field.

like image 817
Vicking Avatar asked Jun 14 '17 15:06

Vicking


People also ask

How do I set the width of a react select?

When selected_value changes, so does its length , and therefore the width of the div gets updated with the new total. Example: if the selected value is now Lorem Ipsum dolor sit amet , the length is now 26 . By applying the formula we get a larger width of : (8px * 26 letters) + 100px = 308px . to your component.

Is antd heavy?

antd is 348kB uncompressed.


2 Answers

You can specify maxTagCount

 <Select
  mode="multiple"
  maxTagCount={1}
>
  // here is rendering of the Opitons
</Select>
like image 81
Konstantin Yarish Avatar answered Sep 27 '22 21:09

Konstantin Yarish


Finally I found a solution by adding this css style options :

.ant-select-selection--multiple
{
   white-space: nowrap;
   height: 30px;
   overflow: auto
}

Thus the div is looking like an input text field and when the content ground a scroll appear at the right side of the div field.

like image 39
Vicking Avatar answered Sep 27 '22 22:09

Vicking