@@ -27,6 +27,21 @@ export interface SelectControlProps extends ChakraSelect.ControlProps {
2727 type ?: SelectProps [ 'type' ] ;
2828}
2929
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+
3045export const SelectControl = React . forwardRef <
3146 HTMLButtonElement ,
3247 SelectControlProps
@@ -307,8 +322,8 @@ export const Select = React.forwardRef<HTMLDivElement, SelectProps>((props, ref)
307322 />
308323 </ SelectControl >
309324 < 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 } >
312327 { item . renderLabel ? item . renderLabel ( ) : item . label }
313328 </ SelectItem >
314329 ) ) }
@@ -339,8 +354,8 @@ export const CompactSelect = React.forwardRef<HTMLDivElement, SelectProps>((prop
339354 />
340355 </ SelectControl >
341356 < 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 } >
344359 { item . label }
345360 </ SelectItem >
346361 ) ) }
@@ -375,9 +390,9 @@ export const InlineSelect = React.forwardRef<HTMLDivElement, SelectProps>((props
375390 type = "inline"
376391 />
377392 </ 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 } >
381396 { item . label }
382397 </ SelectItem >
383398 ) ) }
@@ -442,8 +457,8 @@ export const SelectAsync = React.forwardRef<HTMLDivElement, SelectAsyncProps>((p
442457 />
443458 { extraControls }
444459 </ 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 } >
447462 { item . renderLabel ? item . renderLabel ( ) : item . label }
448463 </ SelectItem >
449464 ) ) }
0 commit comments