diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 81ced7373fe2df..5c43f778a1d8ee 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -20,6 +20,7 @@ - The `Button` component now displays the label as the tooltip for icon only buttons. ([#40716](https://github.com/WordPress/gutenberg/pull/40716)) - Use fake timers and fix usage of async methods from `@testing-library/user-event`. ([#40790](https://github.com/WordPress/gutenberg/pull/40790)) - UnitControl: avoid calling onChange callback twice when unit changes. ([#40796](https://github.com/WordPress/gutenberg/pull/40796)) +- `UnitControl`: show unit label when units prop has only one unit. ([#40784](https://github.com/WordPress/gutenberg/pull/40784)) - `AnglePickerControl`: Fix closing of gradient popover when the angle control is clicked. ([#40735](https://github.com/WordPress/gutenberg/pull/40735)) ### Internal diff --git a/packages/components/src/unit-control/index.tsx b/packages/components/src/unit-control/index.tsx index 3296438b04b8c4..440dc11b94e8b9 100644 --- a/packages/components/src/unit-control/index.tsx +++ b/packages/components/src/unit-control/index.tsx @@ -88,7 +88,7 @@ function UnforwardedUnitControl( ); const [ unit, setUnit ] = useControlledState< string | undefined >( - unitProp, + units.length === 1 ? units[ 0 ].value : unitProp, { initial: parsedUnit, fallback: '', diff --git a/packages/components/src/unit-control/stories/index.tsx b/packages/components/src/unit-control/stories/index.tsx index 5fdace14370ea6..87dfd3a84c602d 100644 --- a/packages/components/src/unit-control/stories/index.tsx +++ b/packages/components/src/unit-control/stories/index.tsx @@ -109,40 +109,10 @@ TweakingTheNumberInput.args = { /** * When only one unit is available, the unit selection dropdown becomes static text. */ -export const WithSingleUnitControlled: ComponentStory< +export const WithSingleUnit: ComponentStory< typeof UnitControl -> = ( { onChange, ...args } ) => { - // Starting value is `undefined` - const [ value, setValue ] = useState< string | undefined >( undefined ); - - return ( -