Skip to content

Commit 8d35d92

Browse files
author
Hector Arce De Las Heras
committed
Add optionals options on section props
1 parent e97780d commit 8d35d92

File tree

1 file changed

+59
-56
lines changed

1 file changed

+59
-56
lines changed

src/components/listOptions/listOptionsStandAlone.tsx

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export const ListOptionsStandAlone = React.forwardRef(
5050
const id = props.id ?? _id;
5151
const isSelection = type === ListOptionsType.SELECTION;
5252
const isNavigation = type === ListOptionsType.NAVIGATION;
53+
const hasOptions = props.options && props.options.length > 0;
5354

5455
return (
5556
<ListOptionsWrapperStyled styles={props.styles}>
@@ -65,64 +66,66 @@ export const ListOptionsStandAlone = React.forwardRef(
6566
</TitleWrapperStyled>
6667
)}
6768
{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 => {
110106
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+
/>
121117
);
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+
)}
126129
</ListOptionsWrapperStyled>
127130
);
128131
}

0 commit comments

Comments
 (0)