diff --git a/packages/ui/report.api.md b/packages/ui/report.api.md index 99516f6e4b..7ef6e2ae51 100644 --- a/packages/ui/report.api.md +++ b/packages/ui/report.api.md @@ -1793,6 +1793,9 @@ export const SearchField: ForwardRefExoticComponent< // @public export const SearchFieldDefinition: { + readonly styles: { + readonly [key: string]: string; + }; readonly classNames: { readonly root: 'bui-SearchField'; readonly clear: 'bui-SearchFieldClear'; @@ -1800,21 +1803,44 @@ export const SearchFieldDefinition: { readonly input: 'bui-SearchFieldInput'; readonly inputIcon: 'bui-SearchFieldInputIcon'; }; - readonly dataAttributes: { - readonly startCollapsed: readonly [true, false]; - readonly size: readonly ['small', 'medium']; + readonly propDefs: { + readonly startCollapsed: { + readonly dataAttribute: true; + readonly default: false; + }; + readonly size: { + readonly dataAttribute: true; + readonly default: 'small'; + }; + readonly className: {}; + readonly icon: {}; + readonly placeholder: { + readonly default: 'Search'; + }; + readonly label: {}; + readonly description: {}; + readonly secondaryLabel: {}; + readonly isRequired: {}; }; }; // @public (undocumented) -export interface SearchFieldProps - extends SearchFieldProps_2, - Omit { +export type SearchFieldOwnProps = { icon?: ReactNode | false; - placeholder?: string; size?: 'small' | 'medium' | Partial>; + placeholder?: string; startCollapsed?: boolean; -} + className?: string; + label?: FieldLabelProps['label']; + description?: FieldLabelProps['description']; + secondaryLabel?: FieldLabelProps['secondaryLabel']; + isRequired?: boolean; +}; + +// @public (undocumented) +export interface SearchFieldProps + extends Omit, + SearchFieldOwnProps {} // @public (undocumented) export interface SearchState { diff --git a/packages/ui/src/components/SearchField/SearchField.tsx b/packages/ui/src/components/SearchField/SearchField.tsx index eea749e46f..846506ff70 100644 --- a/packages/ui/src/components/SearchField/SearchField.tsx +++ b/packages/ui/src/components/SearchField/SearchField.tsx @@ -20,53 +20,39 @@ import { SearchField as AriaSearchField, Button, } from 'react-aria-components'; -import clsx from 'clsx'; import { FieldLabel } from '../FieldLabel'; import { FieldError } from '../FieldError'; import { RiSearch2Line, RiCloseCircleLine } from '@remixicon/react'; -import { useStyles } from '../../hooks/useStyles'; +import { useDefinition } from '../../hooks/useDefinition'; import { SearchFieldDefinition } from './definition'; -import styles from './SearchField.module.css'; import type { SearchFieldProps } from './types'; /** @public */ export const SearchField = forwardRef( (props, ref) => { - const { - label, - 'aria-label': ariaLabel, - 'aria-labelledby': ariaLabelledBy, - } = props; - - useEffect(() => { - if (!label && !ariaLabel && !ariaLabelledBy) { - console.warn( - 'SearchField requires either a visible label, aria-label, or aria-labelledby for accessibility', - ); - } - }, [label, ariaLabel, ariaLabelledBy]); - - const { classNames, dataAttributes, style, cleanedProps } = useStyles( + const { ownProps, restProps, dataAttributes } = useDefinition( SearchFieldDefinition, - { - size: 'small', - placeholder: 'Search', - startCollapsed: false, - ...props, - }, + props, ); - const { - className, - description, + classes, + label, icon, isRequired, secondaryLabel, placeholder, startCollapsed, - ...rest - } = cleanedProps; + description, + } = ownProps; + + useEffect(() => { + if (!label && !restProps['aria-label'] && !restProps['aria-labelledby']) { + console.warn( + 'SearchField requires either a visible label, aria-label, or aria-labelledby for accessibility', + ); + } + }, [label, restProps['aria-label'], restProps['aria-labelledby']]); const [isFocused, setIsFocused] = useState(false); const inputRef = useRef(null); @@ -76,7 +62,7 @@ export const SearchField = forwardRef( secondaryLabel || (isRequired ? 'Required' : null); const handleFocusChange = (isFocused: boolean) => { - props.onFocusChange?.(isFocused); + restProps.onFocusChange?.(isFocused); setIsFocused(isFocused); }; @@ -89,17 +75,17 @@ export const SearchField = forwardRef( const isCollapsed = hasInputRef ? startCollapsed && !hasValue && !isFocused - : startCollapsed && !rest.value && !rest.defaultValue && !isFocused; + : startCollapsed && + !restProps.value && + !restProps.defaultValue && + !isFocused; return ( @@ -109,19 +95,13 @@ export const SearchField = forwardRef( description={description} />
{icon !== false && (