@@ -17,10 +17,12 @@ const defaultItems = [
17
17
function SelectExample ( {
18
18
disabled,
19
19
textOnly,
20
+ classes,
20
21
items = defaultItems ,
21
22
} : {
22
23
disabled ?: boolean ;
23
24
textOnly ?: boolean ;
25
+ classes ?: string ;
24
26
items ?: typeof defaultItems ;
25
27
} ) {
26
28
const [ value , setValue ] = useState < ( typeof items ) [ number ] > ( ) ;
@@ -29,13 +31,17 @@ function SelectExample({
29
31
< SelectNext
30
32
value = { value }
31
33
onChange = { setValue }
34
+ classes = { classes }
32
35
buttonContent = {
33
36
value ? (
34
37
< >
35
- { value . name }
38
+ { textOnly && value . name }
36
39
{ ! textOnly && (
37
- < div className = "rounded px-2 bg-grey-7 text-white" >
38
- { value . id }
40
+ < div className = "flex" >
41
+ < div className = "truncate" > { value . name } </ div >
42
+ < div className = "rounded px-2 ml-2 bg-grey-7 text-white" >
43
+ { value . id }
44
+ </ div >
39
45
</ div >
40
46
) }
41
47
</ >
@@ -56,7 +62,7 @@ function SelectExample({
56
62
< >
57
63
{ item . name }
58
64
< div className = "grow" />
59
- < div className = "rounded px-2 bg-grey-7 text-white" >
65
+ < div className = "rounded px-2 ml-2 bg-grey-7 text-white" >
60
66
{ item . id }
61
67
</ div >
62
68
</ >
@@ -68,7 +74,7 @@ function SelectExample({
68
74
) ;
69
75
}
70
76
71
- function InputGroupSelectExample ( ) {
77
+ function InputGroupSelectExample ( { classes } : { classes ?: string } ) {
72
78
const [ selected , setSelected ] = useState < ( typeof defaultItems ) [ number ] > ( ) ;
73
79
const selectedIndex = useMemo (
74
80
( ) => ( ! selected ? - 1 : defaultItems . findIndex ( item => item === selected ) ) ,
@@ -95,14 +101,15 @@ function InputGroupSelectExample() {
95
101
< SelectNext
96
102
value = { selected }
97
103
onChange = { setSelected }
104
+ classes = { classes }
98
105
buttonContent = {
99
106
selected ? (
100
- < >
101
- { selected . name }
102
- < div className = "rounded px-2 bg-grey-7 text-white" >
107
+ < div className = "flex" >
108
+ < div className = "truncate" > { selected . name } </ div >
109
+ < div className = "rounded px-2 ml-2 bg-grey-7 text-white" >
103
110
{ selected . id }
104
111
</ div >
105
- </ >
112
+ </ div >
106
113
) : (
107
114
< > Select one...</ >
108
115
)
@@ -115,7 +122,9 @@ function InputGroupSelectExample() {
115
122
{ item . name }
116
123
< div className = "grow" />
117
124
< div
118
- className = { classnames ( 'rounded px-2 text-white bg-grey-7' ) }
125
+ className = { classnames (
126
+ 'rounded px-2 ml-2 text-white bg-grey-7' ,
127
+ ) }
119
128
>
120
129
{ item . id }
121
130
</ div >
@@ -152,7 +161,7 @@ export default function SelectNextPage() {
152
161
153
162
< Library . Example >
154
163
< Library . Demo title = "Basic Select" >
155
- < div className = "w-[350px] mx-auto" >
164
+ < div className = "w-96 mx-auto" >
156
165
< SelectExample textOnly />
157
166
</ div >
158
167
</ Library . Demo >
@@ -181,7 +190,7 @@ export default function SelectNextPage() {
181
190
182
191
< Library . Example title = "Select with many options" >
183
192
< Library . Demo title = "Select with many options" >
184
- < div className = "w-[350px] mx-auto" >
193
+ < div className = "w-96 mx-auto" >
185
194
< SelectExample
186
195
items = { [
187
196
...defaultItems . map ( ( { id, name } ) => ( {
@@ -216,11 +225,46 @@ export default function SelectNextPage() {
216
225
217
226
< Library . Example title = "Disabled Select" >
218
227
< Library . Demo title = "Disabled Select" >
219
- < div className = "w-[350px] mx-auto" >
228
+ < div className = "w-96 mx-auto" >
220
229
< SelectExample disabled />
221
230
</ div >
222
231
</ Library . Demo >
223
232
</ Library . Example >
233
+
234
+ < Library . Example title = "Select with long content" >
235
+ < p >
236
+ < code > SelectNext</ code > makes sure the button content never
237
+ overflows, and applies < code > text-overflow: ellipsis</ code > .
238
+ </ p >
239
+ < p >
240
+ If you provide more complex children to < code > buttonContent</ code >
241
+ , and the default hidden overflow logic does not work for your use
242
+ case, it is up to you to handle the overflow logic in your
243
+ components.
244
+ </ p >
245
+ < p >
246
+ On the other hand, the listbox will always grow to fit its
247
+ options.
248
+ </ p >
249
+
250
+ < Library . Demo title = "Plain text" >
251
+ < div className = "mx-auto" >
252
+ < SelectExample textOnly classes = "!w-36" />
253
+ </ div >
254
+ </ Library . Demo >
255
+
256
+ < Library . Demo title = "Custom options" >
257
+ < div className = "mx-auto" >
258
+ < SelectExample classes = "!w-36" />
259
+ </ div >
260
+ </ Library . Demo >
261
+
262
+ < Library . Demo title = "Input group" >
263
+ < div className = "mx-auto" >
264
+ < InputGroupSelectExample classes = "!w-36" />
265
+ </ div >
266
+ </ Library . Demo >
267
+ </ Library . Example >
224
268
</ Library . Pattern >
225
269
226
270
< Library . Pattern title = "Component API" >
@@ -303,7 +347,7 @@ export default function SelectNextPage() {
303
347
value ? (
304
348
<>
305
349
{value.name}
306
- <div className="rounded px-2 bg-grey-7 text-white">
350
+ <div className="rounded px-2 ml-2 bg-grey-7 text-white">
307
351
{value.id}
308
352
</div>
309
353
</>
0 commit comments