Skip to content

Commit

Permalink
Add back SuffixItem
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Feb 13, 2024
1 parent fb7130b commit 396d61c
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions packages/components/src/search-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,45 @@ import classnames from 'classnames';
*/
import { useInstanceId, useMergeRefs } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { Icon, search, closeSmall } from '@wordpress/icons';
import { forwardRef, useMemo, useRef } from '@wordpress/element';

/**
* Internal dependencies
*/
import Button from '../button';
import type { WordPressComponentProps } from '../context/wordpress-component';
import type { SearchControlProps } from './types';
import type { SearchControlProps, SuffixItemProps } from './types';
import type { ForwardedRef } from 'react';
import { ContextSystemProvider } from '../context';
import { SuffixItemWrapper } from './styles';
import InputControl from '../input-control';

function SuffixItem( {
searchRef,
value,
onChange,
onClose,
}: SuffixItemProps ) {
if ( ! onClose && ! value ) {
return <Icon icon={ search } />;
}

const onReset = () => {
onChange( '' );
searchRef.current?.focus();
};

return (
<Button
size="small"
icon={ closeSmall }
label={ onClose ? __( 'Close search' ) : __( 'Reset search' ) }
onClick={ onClose ?? onReset }
/>
);
}

function UnforwardedSearchControl(
{
__nextHasNoMarginBottom = false,
Expand Down Expand Up @@ -80,16 +108,16 @@ function UnforwardedSearchControl(
autoComplete="off"
placeholder={ placeholder }
value={ value ?? '' }
// suffix={
// <SuffixItemWrapper size={ size }>
// <SuffixItem
// searchRef={ searchRef }
// value={ value }
// onChange={ onChange }
// onClose={ onClose }
// />
// </SuffixItemWrapper>
// }
suffix={
<SuffixItemWrapper size={ size }>
<SuffixItem
searchRef={ searchRef }
value={ value }
onChange={ onChange }
onClose={ onClose }
/>
</SuffixItemWrapper>
}
{ ...restProps }
/>
</ContextSystemProvider>
Expand Down

0 comments on commit 396d61c

Please sign in to comment.