Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
cc17f9f
Replace old `CustomSelectControl` select control with the V2 legacy a…
fullofcaffeine Apr 18, 2024
33bb57d
Fix option handling logic for legacy adater and update test to reflec…
fullofcaffeine May 10, 2024
f2c059c
Remove debug code
fullofcaffeine May 11, 2024
0e83151
Debug why selectedItem is not selected on mount
fullofcaffeine May 14, 2024
db8379a
Ensure correct item is selected upon mount based on the value passed …
fullofcaffeine May 15, 2024
751b295
Add new test case to make sure initial passed value is selected upon …
fullofcaffeine May 16, 2024
d18f88d
CSS tweaks
fullofcaffeine May 16, 2024
218cc67
More CSS adjustments to make the component behave closer to classic
fullofcaffeine May 16, 2024
ee619f0
Remove unused prop
fullofcaffeine May 16, 2024
ac751d9
Fix experimentalHint custom styling on legacy adapter
fullofcaffeine May 17, 2024
0db8e28
Fix width of popover not always matching the width of the select
fullofcaffeine May 17, 2024
98a0fc4
Improve export name
fullofcaffeine May 17, 2024
e88b0c4
Fix label margin not applying in certain contexts
fullofcaffeine May 18, 2024
d2cfd1d
Add a wrapper around the select as it the main container needs to hav…
fullofcaffeine May 18, 2024
e47adcf
Fix withHint handling
fullofcaffeine May 18, 2024
e38a4c8
Fix tests
fullofcaffeine May 18, 2024
17f6bbd
Revert accidental change
fullofcaffeine May 18, 2024
cd537af
Make the select item text non-selectable
fullofcaffeine May 21, 2024
fd5c051
Merge branch 'trunk' into replace/old-custom-select-control-with-v2-l…
fullofcaffeine May 28, 2024
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
Prev Previous commit
Next Next commit
Add new test case to make sure initial passed value is selected upon …
…mount + fix other tests
  • Loading branch information
fullofcaffeine committed May 27, 2024
commit 751b295d9f443b98f8e6fea5100706565b5040b4
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ function CustomSelectControl( props: LegacyCustomSelectProps ) {
return;
}

// @todo add test to verify that a value passed programmatically is
// selected

// Executes the logic in a microtask after the popup is closed.
// This is simply to ensure the isOpen state matches that in Downshift.
await Promise.resolve();

const state = store.getState();

const option = options.find( ( item ) => item.name === nextValue );
Expand All @@ -60,8 +58,11 @@ function CustomSelectControl( props: LegacyCustomSelectProps ) {

useEffect( () => {
// This is a workaround for selecting the right item upon mount
store.setValue( value?.name! );
} );
if ( value ) {
store.setValue( value.name );
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [] );

const children = options.map(
( { name, key, __experimentalHint, ...rest } ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ const ControlledCustomSelectControl = ( {
onChange,
...restProps
}: React.ComponentProps< typeof UncontrolledCustomSelectControl > ) => {
const { value: overrideValue } = restProps;
const [ value, setValue ] = useState( options[ 0 ] );
const initialValue = overrideValue ?? value;
return (
<UncontrolledCustomSelectControl
{ ...restProps }
Expand All @@ -70,7 +72,7 @@ const ControlledCustomSelectControl = ( {
setValue( args.selectedItem );
} }
value={ options.find(
( option: any ) => option.key === value.key
( option: any ) => option.key === initialValue.key
) }
/>
);
Expand Down Expand Up @@ -500,4 +502,22 @@ describe.each( [
} )
);
} );

it( 'Should display the initial value passed as the selected value', async () => {
const initialSelectedItem = legacyProps.options[ 5 ];

const testProps = {
...legacyProps,
value: initialSelectedItem,
};

render( <Component { ...testProps } /> );

const currentSelectedItem = await screen.findByRole( 'combobox', {
expanded: false,
} );

// Verify the initial selected value
expect( currentSelectedItem ).toHaveTextContent( 'aquarela' );
} );
} );