Skip to content

Commit a16a268

Browse files
authored
Fix long text causing the search box and selections to overflow on multiple selects (select2#5964)
* Switch clear button to no longer be floated This also adds a consistent padding to the right side of the selection area to allow the clear button to be absolutely positioned on the right side without having to worry about it colliding with one of the selected elements. This is not ideal since it always shows up, even when the clear button is not enabled. This is also not ideal since it maintains the padding for the second row and beyond, even though the clear button is not visible on those rows. We can see if we can work through those issues later. But for now it's working consistent in both Chrome and IE. * Set max-width to 100% on search box This should keep the search box set so it does not overflow the container that it is held within. So when people search for incredibly long strings, it properly maintains width and does not break out of the container and cause rendering issues. * Set max-width on the individual selections This sets the max width on the individual selections such that selections with abnormally long width will not exceed the size of the container and break rendering. In order to remain consistent with how the display is done for a single select, we do not allow the contents of selection in a multiple select to break across lines. In order to fix a rendering issue that occurs when the `overflow` is set to anything other than `visible` on the list item, we set `vertical-align` to `baseline` to ensure that all of the list items are vertically aligned to the same location. If we don't set this, a channel that is roughly 5px tall starts to form between the rows. It's not clear what causes this channel to form but the current solution for working around it is to correct the vertical alignment which appears to cause it to collapse and not form. * Fix remove icon on selection pushing long text This fixes an issue we saw with long text where if the text of the] selection was long enough, the close icon for the selection would be pushed to a second row. This is because the close icon was set to display as a block-like element and that will cause it to take it's own row when it needs to. Now we are absolutely positioning the clear icon with a padding applied so it always renders where we would normally expect it to.
1 parent 83f288d commit a16a268

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

dist/css/select2.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
font-size: 100%;
4747
margin-top: 5px;
4848
margin-left: 5px;
49-
padding: 0; }
49+
padding: 0;
50+
max-width: 100%; }
5051
.select2-container .select2-search--inline .select2-search__field::-webkit-search-cancel-button {
5152
-webkit-appearance: none; }
5253

src/scss/_multiple.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
margin-top: 5px;
3131
margin-left: 5px;
3232
padding: 0;
33+
max-width: 100%;
3334

3435
&::-webkit-search-cancel-button {
3536
-webkit-appearance: none;

src/scss/theme/default/_multiple.scss

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
border-radius: 4px;
55
cursor: text;
66
padding-bottom: 5px;
7-
padding-right: 5px;
7+
padding-right: 25px;
8+
position: relative;
89

910
.select2-selection__clear {
1011
cursor: pointer;
11-
float: right;
1212
font-weight: bold;
1313
height: 20px;
1414
margin-right: 10px;
1515
margin-top: 5px;
1616

17+
position: absolute;
18+
right: 0;
19+
1720
// This padding is to account for the bottom border for the first
1821
// selection row and the top border of the second selection row.
1922
// Without it, selections on the first row may be offset incorrectly
@@ -25,11 +28,21 @@
2528
background-color: #e4e4e4;
2629
border: 1px solid #aaa;
2730
border-radius: 4px;
31+
box-sizing: border-box;
2832

2933
display: inline-block;
3034
margin-left: 5px;
3135
margin-top: 5px;
3236
padding: 0;
37+
padding-left: 20px;
38+
39+
position: relative;
40+
41+
max-width: 100%;
42+
overflow: hidden;
43+
text-overflow: ellipsis;
44+
vertical-align: bottom;
45+
white-space: nowrap;
3346
}
3447

3548
.select2-selection__choice__display {
@@ -54,6 +67,10 @@
5467

5568
padding: 0 4px;
5669

70+
position: absolute;
71+
left: 0;
72+
top: 0;
73+
5774
&:hover, &:focus {
5875
background-color: #f1f1f1;
5976
color: #333;

0 commit comments

Comments
 (0)