import classNames from 'classnames'; import * as React from 'react'; import { FieldClearButton } from '../Field'; import { FieldGroupIcon } from '../FieldGroupIcon'; import { IconSearch } from '../Icon/internal'; import { SearchFieldButton } from './SearchFieldButton'; import { TextField } from '../TextField'; import { useSearchField } from './useSearchField'; import { ComponentClassNames } from '../shared/constants'; import { strHasLength } from '../shared/utils'; import type { BaseSearchFieldProps, SearchFieldProps, ForwardRefPrimitive, Primitive, } from '../types'; const SearchFieldPrimitive: Primitive = ( { autoComplete = 'off', className, isDisabled, clearButtonLabel, labelHidden = true, name = 'q', hasSearchButton = true, hasSearchIcon = false, onChange, onClear, onSubmit, searchButtonRef, size, defaultValue, value, ...rest }, ref ) => { const { composedValue, onClearHandler, onKeyDown, onClick, handleOnChange, composedRefs, } = useSearchField({ defaultValue, value, onChange, onClear, onSubmit, externalRef: ref, }); const SearchButton = hasSearchButton ? ( ) : undefined; const SearchIcon = hasSearchIcon ? ( ) : undefined; return ( } isDisabled={isDisabled} name={name} onChange={handleOnChange} onKeyDown={onKeyDown} outerEndComponent={SearchButton} ref={composedRefs} size={size} value={composedValue} {...rest} /> ); }; /** * [📖 Docs](https://ui.docs.amplify.aws/react/components/searchfield) */ export const SearchField: ForwardRefPrimitive = React.forwardRef(SearchFieldPrimitive); SearchField.displayName = 'SearchField';