Skip to content

Commit

Permalink
RadioGroup: Log deprecation warning (WordPress#68067)
Browse files Browse the repository at this point in the history
* RadioGroup: Log deprecation warning

* Add changelog

* Suppress warning for internal ButtonGroup

Co-authored-by: mirka <[email protected]>
Co-authored-by: jsnajdr <[email protected]>
Co-authored-by: tyxla <[email protected]>
  • Loading branch information
4 people authored Dec 18, 2024
1 parent e9bd750 commit 6154c34
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- `TreeSelect`: Deprecate 36px default size ([#67855](https://github.com/WordPress/gutenberg/pull/67855)).
- `SelectControl`: Deprecate 36px default size ([#66898](https://github.com/WordPress/gutenberg/pull/66898)).
- `InputControl`: Deprecate 36px default size ([#66897](https://github.com/WordPress/gutenberg/pull/66897)).
- `RadioGroup`: Log deprecation warning ([#68067](https://github.com/WordPress/gutenberg/pull/68067)).
- Soft deprecate `ButtonGroup` component. Use `ToggleGroupControl` instead ([#65429](https://github.com/WordPress/gutenberg/pull/65429)).

### Bug Fixes
Expand Down
12 changes: 7 additions & 5 deletions packages/components/src/button-group/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ function UnforwardedButtonGroup(
props: WordPressComponentProps< ButtonGroupProps, 'div', false >,
ref: ForwardedRef< HTMLDivElement >
) {
const { className, ...restProps } = props;
const { className, __shouldNotWarnDeprecated, ...restProps } = props;
const classes = clsx( 'components-button-group', className );

deprecated( 'wp.components.ButtonGroup', {
since: '6.8',
alternative: 'wp.components.ToggleGroupControl',
} );
if ( ! __shouldNotWarnDeprecated ) {
deprecated( 'wp.components.ButtonGroup', {
since: '6.8',
alternative: 'wp.components.__experimentalToggleGroupControl',
} );
}

return (
<div ref={ ref } role="group" className={ classes } { ...restProps } />
Expand Down
7 changes: 7 additions & 0 deletions packages/components/src/button-group/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ export type ButtonGroupProps = {
* The children elements.
*/
children: ReactNode;
/**
* Do not throw a warning for component deprecation.
* For internal components of other components that already throw the warning.
*
* @ignore
*/
__shouldNotWarnDeprecated?: boolean;
};
13 changes: 12 additions & 1 deletion packages/components/src/radio-group/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as Ariakit from '@ariakit/react';
/**
* WordPress dependencies
*/
import deprecated from '@wordpress/deprecated';
import { useMemo, forwardRef } from '@wordpress/element';
import { isRTL } from '@wordpress/i18n';

Expand Down Expand Up @@ -46,11 +47,21 @@ function UnforwardedRadioGroup(
[ radioStore, disabled ]
);

deprecated( 'wp.components.__experimentalRadioGroup', {
alternative:
'wp.components.RadioControl or wp.components.__experimentalToggleGroupControl',
since: '6.8',
} );

return (
<RadioGroupContext.Provider value={ contextValue }>
<Ariakit.RadioGroup
store={ radioStore }
render={ <ButtonGroup>{ children }</ButtonGroup> }
render={
<ButtonGroup __shouldNotWarnDeprecated>
{ children }
</ButtonGroup>
}
aria-label={ label }
ref={ ref }
{ ...props }
Expand Down

0 comments on commit 6154c34

Please sign in to comment.