@@ -27,6 +27,21 @@ export interface SelectControlProps extends ChakraSelect.ControlProps {
27
27
type ?: SelectProps [ 'type' ] ;
28
28
}
29
29
30
+ export enum OptionPositions {
31
+ FIRST_ITEM = 'first-item' ,
32
+ LAST_ITEM = 'last-item' ,
33
+ MID_ITEM = 'mid-item' ,
34
+ SINGLE_ITEM = 'single-item' ,
35
+ } ;
36
+
37
+ const getNthItem = ( index : number , size : number ) : OptionPositions => {
38
+ if ( size === 1 ) return OptionPositions . SINGLE_ITEM ;
39
+ if ( index === 0 ) return OptionPositions . FIRST_ITEM ;
40
+ if ( index === size - 1 ) return OptionPositions . LAST_ITEM ;
41
+
42
+ return OptionPositions . MID_ITEM ;
43
+ } ;
44
+
30
45
export const SelectControl = React . forwardRef <
31
46
HTMLButtonElement ,
32
47
SelectControlProps
@@ -307,8 +322,8 @@ export const Select = React.forwardRef<HTMLDivElement, SelectProps>((props, ref)
307
322
/>
308
323
</ SelectControl >
309
324
< SelectContent portalled = { portalled } { ...contentProps } >
310
- { collection . items . map ( ( item : SelectOption ) => (
311
- < SelectItem item = { item } key = { item . value } >
325
+ { collection . items . map ( ( item : SelectOption , index ) => (
326
+ < SelectItem data-position = { getNthItem ( index , collection . items . length ) } item = { item } key = { item . value } >
312
327
{ item . renderLabel ? item . renderLabel ( ) : item . label }
313
328
</ SelectItem >
314
329
) ) }
@@ -339,8 +354,8 @@ export const CompactSelect = React.forwardRef<HTMLDivElement, SelectProps>((prop
339
354
/>
340
355
</ SelectControl >
341
356
< SelectContent portalled = { portalled } { ...contentProps } >
342
- { collection . items . map ( ( item : SelectOption ) => (
343
- < SelectItem item = { item } key = { item . value } >
357
+ { collection . items . map ( ( item : SelectOption , index ) => (
358
+ < SelectItem data-position = { getNthItem ( index , collection . items . length ) } item = { item } key = { item . value } >
344
359
{ item . label }
345
360
</ SelectItem >
346
361
) ) }
@@ -375,9 +390,9 @@ export const InlineSelect = React.forwardRef<HTMLDivElement, SelectProps>((props
375
390
type = "inline"
376
391
/>
377
392
</ SelectControl >
378
- < SelectContent portalled = { portalled } { ...contentProps } >
379
- { collection . items . map ( ( item : SelectOption ) => (
380
- < SelectItem item = { item } key = { item . value } >
393
+ < SelectContent padding = "var(--kda-explorer-navigation-dimensions-select-option-padding)" portalled = { portalled } { ...contentProps } >
394
+ { collection . items . map ( ( item : SelectOption , index ) => (
395
+ < SelectItem data-position = { getNthItem ( index , collection . items . length ) } item = { item } key = { item . value } >
381
396
{ item . label }
382
397
</ SelectItem >
383
398
) ) }
@@ -442,8 +457,8 @@ export const SelectAsync = React.forwardRef<HTMLDivElement, SelectAsyncProps>((p
442
457
/>
443
458
{ extraControls }
444
459
</ Box >
445
- { collection . items . map ( ( item ) => (
446
- < SelectItem item = { item } key = { item . value } >
460
+ { collection . items . map ( ( item , index ) => (
461
+ < SelectItem data-position = { getNthItem ( index , collection . items . length ) } item = { item } key = { item . value } >
447
462
{ item . renderLabel ? item . renderLabel ( ) : item . label }
448
463
</ SelectItem >
449
464
) ) }
0 commit comments