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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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))

### Internal

Expand Down
5 changes: 1 addition & 4 deletions packages/components/src/unit-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ function UnforwardedUnitControl(
: undefined;
const changeProps = { event, data };

onChangeProp?.(
`${ validParsedQuantity ?? '' }${ validParsedUnit }`,
changeProps
);
// The `onChange` callback already gets called, no need to call it explicitely.
onUnitChange?.( validParsedUnit, changeProps );

setUnit( validParsedUnit );
Expand Down
3 changes: 1 addition & 2 deletions packages/components/src/unit-control/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ describe( 'UnitControl', () => {
// Clicking document.body to trigger a blur event on the input.
await user.click( document.body );

// TODO: investigate why `onChange` gets called twice instead of once
expect( onChangeSpy ).toHaveBeenCalledTimes( 2 );
expect( onChangeSpy ).toHaveBeenCalledTimes( 1 );
expect( onChangeSpy ).toHaveBeenLastCalledWith( '41vh' );

expect( onUnitChangeSpy ).toHaveBeenCalledTimes( 1 );
Expand Down