From a65222b35bba467bd4112202e700290889d96073 Mon Sep 17 00:00:00 2001 From: Vrishabhsk Date: Wed, 9 Oct 2024 15:38:44 +0400 Subject: [PATCH 1/5] Soft deprecate onClose function prop and execute deprecated --- packages/components/src/search-control/index.tsx | 9 +++++++++ packages/components/src/search-control/types.ts | 2 ++ 2 files changed, 11 insertions(+) diff --git a/packages/components/src/search-control/index.tsx b/packages/components/src/search-control/index.tsx index c41eda9b209b6c..fa8bbbdd833024 100644 --- a/packages/components/src/search-control/index.tsx +++ b/packages/components/src/search-control/index.tsx @@ -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 @@ -31,6 +32,14 @@ function SuffixItem( { return ; } + if ( onClose ) { + deprecated( 'onClose function prop', { + since: '6.7', + version: '', + plugin: 'wp.components.SearchControl', + } ); + } + const onReset = () => { onChange( '' ); searchRef.current?.focus(); diff --git a/packages/components/src/search-control/types.ts b/packages/components/src/search-control/types.ts index 1bf38d1c25f6fb..5c730063f87ade 100644 --- a/packages/components/src/search-control/types.ts +++ b/packages/components/src/search-control/types.ts @@ -40,6 +40,8 @@ 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 */ onClose?: () => void; /** @ignore */ From 78d93150dee2aa294545c8045ec346afdfffe86b Mon Sep 17 00:00:00 2001 From: Vrishabhsk Date: Wed, 9 Oct 2024 15:40:31 +0400 Subject: [PATCH 2/5] Update README and StoryBook JSDoc --- packages/components/src/search-control/README.md | 2 ++ packages/components/src/search-control/stories/index.story.tsx | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/components/src/search-control/README.md b/packages/components/src/search-control/README.md index 52513ab47f582e..3945f451d6dcf7 100644 --- a/packages/components/src/search-control/README.md +++ b/packages/components/src/search-control/README.md @@ -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. diff --git a/packages/components/src/search-control/stories/index.story.tsx b/packages/components/src/search-control/stories/index.story.tsx index 215288bb67c9b6..24f340a73d1153 100644 --- a/packages/components/src/search-control/stories/index.story.tsx +++ b/packages/components/src/search-control/stories/index.story.tsx @@ -52,6 +52,8 @@ Default.args = { }; /** + * _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. * From e809cd566f42a5f7337914422227dc49f095ecca Mon Sep 17 00:00:00 2001 From: Vrishabhsk Date: Wed, 9 Oct 2024 15:40:57 +0400 Subject: [PATCH 3/5] Expect console.warn due to deprecated func call and fix typo --- packages/components/src/search-control/test/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/components/src/search-control/test/index.tsx b/packages/components/src/search-control/test/index.tsx index c6637945adcf63..bd1040d564d230 100644 --- a/packages/components/src/search-control/test/index.tsx +++ b/packages/components/src/search-control/test/index.tsx @@ -72,13 +72,14 @@ describe( 'SearchControl', () => { expect( onChangeSpy ).toHaveBeenLastCalledWith( '' ); } ); - it( 'should should render a Close button (instead of Reset) when onClose function is provided', async () => { + it( 'should render a Close button (instead of Reset) when onClose function is provided', async () => { const onChangeSpy = jest.fn(); const onCloseSpy = jest.fn(); render( ); + expect( console ).toHaveWarned(); expect( screen.queryByRole( 'button', { name: 'Close search' } ) ).toBeVisible(); From 0494d8a66933e5d494d9dfadaf5c66dacb7e5d66 Mon Sep 17 00:00:00 2001 From: Vrishabhsk Date: Thu, 10 Oct 2024 11:22:23 +0400 Subject: [PATCH 4/5] Address PR feedback Remove WithOnClose storybook variation. Refactor deprecation message. Add @ignore for onClose in types.ts. Add deprecations section in CHANGELOG.md --- packages/components/CHANGELOG.md | 4 ++++ .../components/src/search-control/index.tsx | 6 ++---- .../src/search-control/stories/index.story.tsx | 17 ----------------- packages/components/src/search-control/types.ts | 1 + 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 4ae124347187e7..84a51e0f3597ad 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -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)). diff --git a/packages/components/src/search-control/index.tsx b/packages/components/src/search-control/index.tsx index fa8bbbdd833024..0a1b821a0a079a 100644 --- a/packages/components/src/search-control/index.tsx +++ b/packages/components/src/search-control/index.tsx @@ -33,10 +33,8 @@ function SuffixItem( { } if ( onClose ) { - deprecated( 'onClose function prop', { - since: '6.7', - version: '', - plugin: 'wp.components.SearchControl', + deprecated( '`onClose` prop in wp.components.SearchControl', { + since: '6.8', } ); } diff --git a/packages/components/src/search-control/stories/index.story.tsx b/packages/components/src/search-control/stories/index.story.tsx index 24f340a73d1153..59618dd7e0913b 100644 --- a/packages/components/src/search-control/stories/index.story.tsx +++ b/packages/components/src/search-control/stories/index.story.tsx @@ -50,20 +50,3 @@ Default.args = { help: 'Help text to explain the input.', __nextHasNoMarginBottom: true, }; - -/** - * _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. - */ -export const WithOnClose = Template.bind( {} ); -WithOnClose.args = { - ...Default.args, -}; -WithOnClose.argTypes = { - onClose: { action: 'onClose' }, -}; diff --git a/packages/components/src/search-control/types.ts b/packages/components/src/search-control/types.ts index 5c730063f87ade..e4117e5ed57ffb 100644 --- a/packages/components/src/search-control/types.ts +++ b/packages/components/src/search-control/types.ts @@ -42,6 +42,7 @@ export type SearchControlProps = Pick< InputControlProps, 'help' | 'value' > & { * rather than just clearing the input value. * * @deprecated + * @ignore */ onClose?: () => void; /** @ignore */ From 413ff799b1f887f0568317e4f76532e5d78b8bd4 Mon Sep 17 00:00:00 2001 From: Vrishabhsk Date: Thu, 10 Oct 2024 13:17:27 +0400 Subject: [PATCH 5/5] Replace toHaveWarned with toHaveWarnedWith --- packages/components/src/search-control/test/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/components/src/search-control/test/index.tsx b/packages/components/src/search-control/test/index.tsx index bd1040d564d230..5250a531f58d09 100644 --- a/packages/components/src/search-control/test/index.tsx +++ b/packages/components/src/search-control/test/index.tsx @@ -79,7 +79,9 @@ describe( 'SearchControl', () => { ); - expect( console ).toHaveWarned(); + expect( console ).toHaveWarnedWith( + '`onClose` prop in wp.components.SearchControl is deprecated since version 6.8.' + ); expect( screen.queryByRole( 'button', { name: 'Close search' } ) ).toBeVisible();