Skip to content

Commit

Permalink
Add deprecated legacy props describedBy and __nextUnconstrainedWidth
Browse files Browse the repository at this point in the history
  • Loading branch information
brookewp committed Dec 15, 2023
1 parent 3d010ec commit 79116aa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/components/src/custom-select-control-v2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ export type LegacyCustomSelectProps = {
*
*/
hideLabelFromVision?: boolean;
/**
* Pass in a description that will be shown to screen readers associated with the
* select trigger button. If no value is passed, the text "Currently selected:
* selectedItem.name" will be used fully translated.
*/
describedBy?: string;
/**
* Label for the control.
*/
Expand All @@ -100,6 +106,13 @@ export type LegacyCustomSelectProps = {
*/
value?: Option;
__experimentalShowSelectedHint?: boolean;
/**
* Opt-in prop for an unconstrained width style which became the default in
* WordPress 6.4. The prop is no longer needed and can be safely removed.
*
* @deprecated
*/
__nextUnconstrainedWidth?: boolean;
};

export type CustomSelectItemProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useCallback } from '@wordpress/element';
*/
import { CustomSelectItem } from '.';
import type { CustomSelectProps, LegacyCustomSelectProps } from './types';
import deprecated from '@wordpress/deprecated';

function isLegacyProps( props: any ): props is LegacyCustomSelectProps {
return (
Expand Down Expand Up @@ -60,7 +61,22 @@ export function useDeprecatedProps(
);

if ( isLegacyProps( props ) ) {
if ( props.__nextUnconstrainedWidth ) {
deprecated(
'Constrained width styles for wp.components.CustomSelectControl',
{
hint: 'This behaviour is now built-in.',
since: '6.4',
}
);
}

const legacyProps = {
'aria-describedby': props.describedBy,
};

return {
...legacyProps,
children: transformOptionsToChildren( props ),
label: props.label ?? '',
onChange: legacyChangeHandler,
Expand Down

0 comments on commit 79116aa

Please sign in to comment.