Skip to content

Commit

Permalink
Fix option handling logic for legacy adater and update test to reflec…
Browse files Browse the repository at this point in the history
…t the option with custom property scenario
  • Loading branch information
fullofcaffeine committed May 10, 2024
1 parent b9ad34c commit e019e2f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function CustomSelectControl( props: LegacyCustomSelectProps ) {
selectedItem: option!,
type: '',
};
debugger;
onChange( changeObject );
},
} );
Expand Down Expand Up @@ -131,7 +132,6 @@ export default CustomSelectControl;

// for backwards compatibility
export function ClassicCustomSelectControl( props: LegacyCustomSelectProps ) {
console.debug( props );
return (
<CustomSelectControl
{ ...props }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ describe.each( [
expect.objectContaining( {
inputValue: '',
isOpen: false,
selectedItem: { key: 'violets', name: 'violets' },
selectedItem: { key: 'flower1', name: 'violets' },
type: '',
} )
);
Expand All @@ -302,8 +302,17 @@ describe.each( [
expect.objectContaining( {
inputValue: '',
isOpen: false,
// Some consumers don't use the value but expect the whole option object to be available and will access
// custom properties on it. Here's an example of such a consumer:
// - https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/font-appearance-control/index.js#L216
// This should only be supported for the legacy adapter, and when we change the implementation with the new V2 one, we will (ideally)
// also refactor consumers to not rely on custom properties, but only on the pre-defined key,value structure.
selectedItem: expect.objectContaining( {
name: 'aquamarine',
style: {
backgroundColor: 'rgb(127, 255, 212)',
rotate: '13deg',
},
} ),
type: '',
} )
Expand All @@ -328,7 +337,7 @@ describe.each( [
await type( 'p' );
await press.Enter();

expect( mockOnChange ).toHaveReturnedWith( 'poppy' );
expect( mockOnChange ).toHaveReturnedWith( 'flower1' );
} );

describe( 'Keyboard behavior and accessibility', () => {
Expand Down

0 comments on commit e019e2f

Please sign in to comment.