Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- `RangeControl`: do not tooltip contents to the DOM when not shown ([#65875](https://github.com/WordPress/gutenberg/pull/65875)).
- `Tabs`: fix skipping indication animation glitch ([#65878](https://github.com/WordPress/gutenberg/pull/65878)).

### Deprecations

- `SearchControl`: Soft deprecate `onClose` prop ([#65988](https://github.com/WordPress/gutenberg/pull/65988)).

### Enhancements

- `Tabs`: revamped vertical orientation styles ([#65387](https://github.com/WordPress/gutenberg/pull/65387)).
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/search-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ A function that receives the value of the input.

#### onClose

_Note: this prop is deprecated._

When an `onClose` callback is provided, the search control will render a close button that will trigger the given callback.

Use this if you want the button to trigger your own logic to close the search field entirely, rather than just clearing the input value.
Expand Down
7 changes: 7 additions & 0 deletions packages/components/src/search-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useInstanceId, useMergeRefs } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { Icon, search, closeSmall } from '@wordpress/icons';
import { forwardRef, useMemo, useRef } from '@wordpress/element';
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
Expand All @@ -31,6 +32,12 @@ function SuffixItem( {
return <Icon icon={ search } />;
}

if ( onClose ) {
deprecated( '`onClose` prop in wp.components.SearchControl', {
since: '6.8',
} );
}

const onReset = () => {
onChange( '' );
searchRef.current?.focus();
Expand Down
15 changes: 0 additions & 15 deletions packages/components/src/search-control/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,3 @@ Default.args = {
help: 'Help text to explain the input.',
__nextHasNoMarginBottom: true,
};

/**
* When an `onClose` callback is provided, the search control will render a close button
* that will trigger the given callback.
*
* Use this if you want the button to trigger your own logic to close the search field entirely,
* rather than just clearing the input value.
*/
export const WithOnClose = Template.bind( {} );
WithOnClose.args = {
...Default.args,
};
WithOnClose.argTypes = {
onClose: { action: 'onClose' },
};
5 changes: 4 additions & 1 deletion packages/components/src/search-control/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ describe( 'SearchControl', () => {
expect( onChangeSpy ).toHaveBeenLastCalledWith( '' );
} );

it( 'should should render a Close button (instead of Reset) when onClose function is provided', async () => {
Comment thread
Vrishabhsk marked this conversation as resolved.
Resolved
it( 'should render a Close button (instead of Reset) when onClose function is provided', async () => {
const onChangeSpy = jest.fn();
const onCloseSpy = jest.fn();
render(
<Component onChange={ onChangeSpy } onClose={ onCloseSpy } />
);

expect( console ).toHaveWarnedWith(
'`onClose` prop in wp.components.SearchControl is deprecated since version 6.8.'
);
expect(
screen.queryByRole( 'button', { name: 'Close search' } )
).toBeVisible();
Expand Down
3 changes: 3 additions & 0 deletions packages/components/src/search-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export type SearchControlProps = Pick< InputControlProps, 'help' | 'value' > & {
*
* Use this if you want the button to trigger your own logic to close the search field entirely,
* rather than just clearing the input value.
*
* @deprecated
Comment thread
Vrishabhsk marked this conversation as resolved.
Resolved
* @ignore
*/
onClose?: () => void;
/** @ignore */
Expand Down