Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 2ed6dd1

Browse files
Brian OchanTigge
authored andcommitted
fix(select): provide max width for select popover with long labels.
- provide an upper bound max width for select popover if the label is very long.
1 parent d6de26f commit 2ed6dd1

File tree

7 files changed

+82
-357
lines changed

7 files changed

+82
-357
lines changed

packages/core/src/Input/__snapshots__/index.test.tsx.snap

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4379,21 +4379,12 @@ exports[`TextInput TimeInput 1`] = `
43794379
}
43804380
43814381
.c12 {
4382-
display: -webkit-box;
4383-
display: -webkit-flex;
4384-
display: -ms-flexbox;
4385-
display: flex;
4386-
-webkit-flex-direction: row;
4387-
-ms-flex-direction: row;
4388-
flex-direction: row;
4382+
display: grid;
4383+
grid-template-columns: 1fr auto;
43894384
-webkit-align-items: center;
43904385
-webkit-box-align: center;
43914386
-ms-flex-align: center;
43924387
align-items: center;
4393-
-webkit-box-pack: justify;
4394-
-webkit-justify-content: space-between;
4395-
-ms-flex-pack: justify;
4396-
justify-content: space-between;
43974388
height: 100%;
43984389
width: 100%;
43994390
}

packages/core/src/Select/BaseSelect.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ const SelectItem = styled.li<{
9494
}
9595
`};
9696
`
97+
const Item = styled.span`
98+
overflow: hidden;
99+
text-overflow: ellipsis;
100+
`
97101

98102
const NoOptionsText = styled(Typography)`
99103
display: flex;
@@ -169,7 +173,7 @@ const SelectOptionComponent: React.FC<SelectOption> = ({
169173
selected={selected && selectMarker === 'background'}
170174
ref={ref}
171175
>
172-
{item}
176+
<Item>{item}</Item>
173177
</SelectItem>
174178
)
175179
}
@@ -214,6 +218,7 @@ export const SelectPopover: React.FC<SelectPopoverProps> = ({
214218

215219
const MAX_HEIGHT = 320
216220
const MIN_HEIGHT = 160
221+
const MAX_MIN_WIDTH = 300
217222

218223
const onDropdownPosition = useCallback(
219224
(anchorElement, popOverContainerEl) => {
@@ -224,6 +229,10 @@ export const SelectPopover: React.FC<SelectPopoverProps> = ({
224229
const anchorBBox = anchorElement.getBoundingClientRect()
225230
const { top, bottom, left, right } = anchorBBox
226231
popOverContainerEl.style.minWidth = `${right - left}px`
232+
popOverContainerEl.style.maxWidth = `${Math.max(
233+
right - left,
234+
MAX_MIN_WIDTH
235+
)}px`
227236

228237
// Calculate available space above and below
229238
const { clientHeight } = document.documentElement

packages/core/src/Select/BaseSelectSelector.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ interface SelectInputProps {
1717
}
1818

1919
export const SelectInsideContainer = styled.div`
20-
display: flex;
21-
flex-direction: row;
20+
display: grid;
21+
grid-template-columns: 1fr auto;
2222
align-items: center;
23-
justify-content: space-between;
2423
height: 100%;
2524
width: 100%;
2625
`

packages/core/src/Select/__snapshots__/MultiSelect.test.tsx.snap

Lines changed: 14 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,12 @@ exports[`Select Direction 1`] = `
6363
}
6464
6565
.c5 {
66-
display: -webkit-box;
67-
display: -webkit-flex;
68-
display: -ms-flexbox;
69-
display: flex;
70-
-webkit-flex-direction: row;
71-
-ms-flex-direction: row;
72-
flex-direction: row;
66+
display: grid;
67+
grid-template-columns: 1fr auto;
7368
-webkit-align-items: center;
7469
-webkit-box-align: center;
7570
-ms-flex-align: center;
7671
align-items: center;
77-
-webkit-box-pack: justify;
78-
-webkit-justify-content: space-between;
79-
-ms-flex-pack: justify;
80-
justify-content: space-between;
8172
height: 100%;
8273
width: 100%;
8374
}
@@ -463,21 +454,12 @@ exports[`Select Direction 2`] = `
463454
}
464455
465456
.c5 {
466-
display: -webkit-box;
467-
display: -webkit-flex;
468-
display: -ms-flexbox;
469-
display: flex;
470-
-webkit-flex-direction: row;
471-
-ms-flex-direction: row;
472-
flex-direction: row;
457+
display: grid;
458+
grid-template-columns: 1fr auto;
473459
-webkit-align-items: center;
474460
-webkit-box-align: center;
475461
-ms-flex-align: center;
476462
align-items: center;
477-
-webkit-box-pack: justify;
478-
-webkit-justify-content: space-between;
479-
-ms-flex-pack: justify;
480-
justify-content: space-between;
481463
height: 100%;
482464
width: 100%;
483465
}
@@ -863,21 +845,12 @@ exports[`Select Other 1`] = `
863845
}
864846
865847
.c5 {
866-
display: -webkit-box;
867-
display: -webkit-flex;
868-
display: -ms-flexbox;
869-
display: flex;
870-
-webkit-flex-direction: row;
871-
-ms-flex-direction: row;
872-
flex-direction: row;
848+
display: grid;
849+
grid-template-columns: 1fr auto;
873850
-webkit-align-items: center;
874851
-webkit-box-align: center;
875852
-ms-flex-align: center;
876853
align-items: center;
877-
-webkit-box-pack: justify;
878-
-webkit-justify-content: space-between;
879-
-ms-flex-pack: justify;
880-
justify-content: space-between;
881854
height: 100%;
882855
width: 100%;
883856
}
@@ -1270,21 +1243,12 @@ exports[`Select Other 2`] = `
12701243
}
12711244
12721245
.c5 {
1273-
display: -webkit-box;
1274-
display: -webkit-flex;
1275-
display: -ms-flexbox;
1276-
display: flex;
1277-
-webkit-flex-direction: row;
1278-
-ms-flex-direction: row;
1279-
flex-direction: row;
1246+
display: grid;
1247+
grid-template-columns: 1fr auto;
12801248
-webkit-align-items: center;
12811249
-webkit-box-align: center;
12821250
-ms-flex-align: center;
12831251
align-items: center;
1284-
-webkit-box-pack: justify;
1285-
-webkit-justify-content: space-between;
1286-
-ms-flex-pack: justify;
1287-
justify-content: space-between;
12881252
height: 100%;
12891253
width: 100%;
12901254
}
@@ -1684,21 +1648,12 @@ exports[`Select Width 1`] = `
16841648
}
16851649
16861650
.c5 {
1687-
display: -webkit-box;
1688-
display: -webkit-flex;
1689-
display: -ms-flexbox;
1690-
display: flex;
1691-
-webkit-flex-direction: row;
1692-
-ms-flex-direction: row;
1693-
flex-direction: row;
1651+
display: grid;
1652+
grid-template-columns: 1fr auto;
16941653
-webkit-align-items: center;
16951654
-webkit-box-align: center;
16961655
-ms-flex-align: center;
16971656
align-items: center;
1698-
-webkit-box-pack: justify;
1699-
-webkit-justify-content: space-between;
1700-
-ms-flex-pack: justify;
1701-
justify-content: space-between;
17021657
height: 100%;
17031658
width: 100%;
17041659
}
@@ -2084,21 +2039,12 @@ exports[`Select Width 2`] = `
20842039
}
20852040
20862041
.c5 {
2087-
display: -webkit-box;
2088-
display: -webkit-flex;
2089-
display: -ms-flexbox;
2090-
display: flex;
2091-
-webkit-flex-direction: row;
2092-
-ms-flex-direction: row;
2093-
flex-direction: row;
2042+
display: grid;
2043+
grid-template-columns: 1fr auto;
20942044
-webkit-align-items: center;
20952045
-webkit-box-align: center;
20962046
-ms-flex-align: center;
20972047
align-items: center;
2098-
-webkit-box-pack: justify;
2099-
-webkit-justify-content: space-between;
2100-
-ms-flex-pack: justify;
2101-
justify-content: space-between;
21022048
height: 100%;
21032049
width: 100%;
21042050
}
@@ -2516,21 +2462,12 @@ exports[`Select Width 3`] = `
25162462
}
25172463
25182464
.c5 {
2519-
display: -webkit-box;
2520-
display: -webkit-flex;
2521-
display: -ms-flexbox;
2522-
display: flex;
2523-
-webkit-flex-direction: row;
2524-
-ms-flex-direction: row;
2525-
flex-direction: row;
2465+
display: grid;
2466+
grid-template-columns: 1fr auto;
25262467
-webkit-align-items: center;
25272468
-webkit-box-align: center;
25282469
-ms-flex-align: center;
25292470
align-items: center;
2530-
-webkit-box-pack: justify;
2531-
-webkit-justify-content: space-between;
2532-
-ms-flex-pack: justify;
2533-
justify-content: space-between;
25342471
height: 100%;
25352472
width: 100%;
25362473
}

0 commit comments

Comments
 (0)