Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(combobox): clean up classes and add tests #263

Merged
merged 10 commits into from
Jul 24, 2024
16 changes: 10 additions & 6 deletions packages/combobox/src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ export const Combobox = forwardRef<HTMLInputElement, ComboboxProps>(({ id: pid,

const navigationValueOrInputValue = navigationOption?.value || value;

const optionClasses = (option: OptionWithIdAndMatch) =>
classNames(
ccCombobox.option,
OPTION_CLASS_NAME,
navigationOption?.id === option?.id ? ccCombobox.optionSelected : ccCombobox.optionUnselected,
);

// Set and filter available options based on user input
useEffect(() => {
setCurrentOptions(
Expand All @@ -81,7 +88,7 @@ export const Combobox = forwardRef<HTMLInputElement, ComboboxProps>(({ id: pid,
);

// eslint-disable-next-line
}, [options, disableStaticFiltering]);
}, [options, disableStaticFiltering, value]);

useEffect(() => {
if (disableStaticFiltering && currentOptions.length && currentOptions.length === 1 && !currentOptions.some((o) => o.value === value)) {
Expand Down Expand Up @@ -239,7 +246,7 @@ export const Combobox = forwardRef<HTMLInputElement, ComboboxProps>(({ id: pid,

<div
hidden={!isOpen || !currentOptions.length}
className={classNames(listClassName, ccCombobox.combobox)}
className={classNames(listClassName, ccCombobox.base)}
style={{
zIndex: 3, // Force popover above misc. page content (mobile safari issue)
}}>
Expand Down Expand Up @@ -286,10 +293,7 @@ export const Combobox = forwardRef<HTMLInputElement, ComboboxProps>(({ id: pid,
handleSelect(option);
});
}}
className={classNames({
[`${ccCombobox.option} ${OPTION_CLASS_NAME}`]: true,
[ccCombobox.optionSelected]: navigationOption?.id === option.id,
})}>
className={optionClasses(option)}>
{matchTextSegments || highlightValueMatch ? match : display}
</li>
);
Expand Down
Loading
Loading