@@ -50,6 +50,7 @@ export const ListOptionsStandAlone = React.forwardRef(
50
50
const id = props . id ?? _id ;
51
51
const isSelection = type === ListOptionsType . SELECTION ;
52
52
const isNavigation = type === ListOptionsType . NAVIGATION ;
53
+ const hasOptions = props . options && props . options . length > 0 ;
53
54
54
55
return (
55
56
< ListOptionsWrapperStyled styles = { props . styles } >
@@ -65,64 +66,66 @@ export const ListOptionsStandAlone = React.forwardRef(
65
66
</ TitleWrapperStyled >
66
67
) }
67
68
{ props . content }
68
- < OptionsWrapperStyled
69
- ref = { listEl as React . RefObject < HTMLUListElement > }
70
- aria-label = { props . optionsContainerArias ?. [ 'aria-label' ] }
71
- aria-labelledby = { props . optionsContainerArias ?. [ 'aria-labelledby' ] }
72
- as = { 'ul' }
73
- id = { id }
74
- role = { isSelection ? ROLES . LISTBOX : ROLES . MENU }
75
- styles = { props . styles }
76
- >
77
- { props . options . map ( ( option , index ) => {
78
- const selected = isSelected (
79
- option ,
80
- props . selectedValue ,
81
- props . multiSelect ,
82
- props . caseSensitive
83
- ) ;
84
- const optionComponent = (
85
- < Option
86
- key = { `${ id } Option${ index } ` }
87
- aria-selected = { isSelection ? selected : undefined }
88
- as = { isNavigation ? 'div' : 'li' }
89
- checkedIcon = { props . checkedIcon }
90
- dataTestId = { `${ dataTestId } Option${ index } ` }
91
- focus = { focus === index }
92
- labelCharsHighlighted = { props . charsHighlighted }
93
- multiSelect = { props . multiSelect }
94
- role = { isSelection ? ROLES . OPTION : ROLES . MENUITEM }
95
- selected = { selected }
96
- tabIndex = { isNavigation ? 0 : - 1 }
97
- variant = { getOptionVariant (
98
- option . highlighted ,
99
- props . hightlightedOptionVariant ,
100
- props . optionVariant
101
- ) }
102
- { ...option }
103
- onClick = { e => {
104
- setFocus ( index ) ;
105
- props . onOptionClick ?.( option . value , e ) ;
106
- option . onClick ?.( e ) ;
107
- } }
108
- onFocus = { e => {
109
- if ( index !== focus ) {
69
+ { hasOptions && (
70
+ < OptionsWrapperStyled
71
+ ref = { listEl as React . RefObject < HTMLUListElement > }
72
+ aria-label = { props . optionsContainerArias ?. [ 'aria-label' ] }
73
+ aria-labelledby = { props . optionsContainerArias ?. [ 'aria-labelledby' ] }
74
+ as = { 'ul' }
75
+ id = { id }
76
+ role = { isSelection ? ROLES . LISTBOX : ROLES . MENU }
77
+ styles = { props . styles }
78
+ >
79
+ { props . options . map ( ( option , index ) => {
80
+ const selected = isSelected (
81
+ option ,
82
+ props . selectedValue ,
83
+ props . multiSelect ,
84
+ props . caseSensitive
85
+ ) ;
86
+ const optionComponent = (
87
+ < Option
88
+ key = { `${ id } Option${ index } ` }
89
+ aria-selected = { isSelection ? selected : undefined }
90
+ as = { isNavigation ? 'div' : 'li' }
91
+ checkedIcon = { props . checkedIcon }
92
+ dataTestId = { `${ dataTestId } Option${ index } ` }
93
+ focus = { focus === index }
94
+ labelCharsHighlighted = { props . charsHighlighted }
95
+ multiSelect = { props . multiSelect }
96
+ role = { isSelection ? ROLES . OPTION : ROLES . MENUITEM }
97
+ selected = { selected }
98
+ tabIndex = { isNavigation ? 0 : - 1 }
99
+ variant = { getOptionVariant (
100
+ option . highlighted ,
101
+ props . hightlightedOptionVariant ,
102
+ props . optionVariant
103
+ ) }
104
+ { ...option }
105
+ onClick = { e => {
110
106
setFocus ( index ) ;
111
- }
112
- option . onFocus ?.( e ) ;
113
- } }
114
- />
115
- ) ;
116
- if ( type === ListOptionsType . NAVIGATION ) {
117
- return (
118
- < li key = { ` ${ id } LiOption ${ index } ` } role = "presentation" >
119
- { optionComponent }
120
- </ li >
107
+ props . onOptionClick ?. ( option . value , e ) ;
108
+ option . onClick ?.( e ) ;
109
+ } }
110
+ onFocus = { e => {
111
+ if ( index !== focus ) {
112
+ setFocus ( index ) ;
113
+ }
114
+ option . onFocus ?. ( e ) ;
115
+ } }
116
+ / >
121
117
) ;
122
- }
123
- return optionComponent ;
124
- } ) }
125
- </ OptionsWrapperStyled >
118
+ if ( type === ListOptionsType . NAVIGATION ) {
119
+ return (
120
+ < li key = { `${ id } LiOption${ index } ` } role = "presentation" >
121
+ { optionComponent }
122
+ </ li >
123
+ ) ;
124
+ }
125
+ return optionComponent ;
126
+ } ) }
127
+ </ OptionsWrapperStyled >
128
+ ) }
126
129
</ ListOptionsWrapperStyled >
127
130
) ;
128
131
}
0 commit comments