import React, { type HTMLProps } from 'react'; import { classNames } from '../../../utils'; import { useFormFieldContext } from '../../FormField/FormFieldContext'; import { Icon } from '../../Icon'; import { DropdownMenuContentList } from '../../DropdownMenuContent'; import { SkeletonText } from '../../Skeleton'; import type { ComboboxNoDropdownProps, ComboboxOption } from '../types'; import { colors } from '../../../colors'; import styles from './ComboboxNoDropdown.module.css'; export const ComboboxNoDropdown = ( props: ComboboxNoDropdownProps, ) => { const { className, dropdownMenuContentMaxHeight, fit = 'content', options, isDisabled = false, isInvalid, isInputVisible = true, isLoading = false, onClearSelection, // eslint-disable-next-line @typescript-eslint/no-unused-vars hideToggleButton = false, renderSelected = () => null, renderOption, renderOptionGroup, renderNoOptions, renderLoadingOption = ({ key }: { key: string | number }) => ( ), propsGetters: { getInputProps = () => ({}), getItemProps = () => ({}), getMenuProps = () => ({}), } = {}, ...rest } = props; const context = useFormFieldContext(); const isComboboxInvalid = isInvalid === undefined ? context.isInvalid : isInvalid; const inputProps: HTMLProps = { ...getInputProps(), 'aria-invalid': isComboboxInvalid ? ('true' as const) : ('false' as const), ...(isComboboxInvalid && { ['aria-errormessage']: context.errorMessageId }), id: context.inputId, }; return ( {renderSelected()} { return inputProps.onFocus?.(event); }} onBlur={(event) => { return inputProps.onBlur?.(event); }} disabled={isDisabled} /> {onClearSelection && ( )} { const loadingOptionsCount = options.length === 0 ? 5 : options.length; return Array.from({ length: loadingOptionsCount }, (_, i) => renderLoadingOption({ key: i }), ); }} /> ); };