MCPcopy Create free account
hub / github.com/adobe/react-spectrum / Option

Function Option

packages/react-aria/stories/combobox/example.tsx:152–183  ·  view source on GitHub ↗
({item, state})

Source from the content-addressed store, hash-verified

150}
151
152function Option({item, state}) {
153 let ref = React.useRef<HTMLLIElement | null>(null);
154 let {optionProps, isSelected, isFocused, isDisabled} = useOption({key: item.key}, state, ref);
155
156 let backgroundColor;
157 let color = 'black';
158
159 if (isSelected) {
160 backgroundColor = 'blueviolet';
161 color = 'white';
162 } else if (isFocused) {
163 backgroundColor = 'gray';
164 } else if (isDisabled) {
165 backgroundColor = 'transparent';
166 color = 'gray';
167 }
168
169 return (
170 <li
171 {...optionProps}
172 ref={ref}
173 style={{
174 background: backgroundColor,
175 color: color,
176 padding: '2px 5px',
177 outline: 'none',
178 cursor: 'pointer'
179 }}>
180 {item.rendered}
181 </li>
182 );
183}

Callers

nothing calls this directly

Calls 1

useOptionFunction · 0.90

Tested by

no test coverage detected