Antd how to fixe the size of the multi selection component?
Asked Answered
A

3

10

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.

Afflictive answered 14/6, 2017 at 15:54 Comment(2)
what is the expected behavior when the row is full then?Scamp
The behavior that I want was to obtain a div looking like input text field, where there is a scroll and the div do not change the size when the text inside begin longer than the line. I found the solution by adding this css style : .ant-select-selection--multiple { white-space: nowrap; height: 30px; overflow: auto }Afflictive
A
8

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.

Afflictive answered 15/6, 2017 at 7:31 Comment(1)
Wow, amazing solution!!! Thank you, much appreciate that.Carmancarmarthen
A
10

You can specify maxTagCount

 <Select
  mode="multiple"
  maxTagCount={1}
>
  // here is rendering of the Opitons
</Select>
Attis answered 27/8, 2020 at 14:0 Comment(0)
A
8

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.

Afflictive answered 15/6, 2017 at 7:31 Comment(1)
Wow, amazing solution!!! Thank you, much appreciate that.Carmancarmarthen
F
2

You could also set maxTagCount to 'responsive' and this will automatically determine that tags that can be shown on one line

<Select
  mode="multiple"
  maxTagCount={'responsive'}
>
  // here is rendering of the Opitons
</Select>
Firedrake answered 8/8, 2023 at 17:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.