Skip to content

Commit

Permalink
Try mounting on first render to avoid required defaultValue
Browse files Browse the repository at this point in the history
  • Loading branch information
brookewp committed Feb 1, 2024
1 parent 583d16e commit e3c328f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
13 changes: 11 additions & 2 deletions packages/components/src/custom-select-control-v2/custom-select.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/**
* WordPress dependencies
*/
import { createContext, useMemo, useState } from '@wordpress/element';
import {
createContext,
useEffect,
useMemo,
useState,
} from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { Icon, chevronDown } from '@wordpress/icons';

Expand Down Expand Up @@ -104,7 +109,11 @@ function _CustomSelect( props: _CustomSelectProps & CustomSelectStore ) {
...restProps
} = props;

const [ unmountOnHide, setUnmountOnHide ] = useState( true );
const [ unmountOnHide, setUnmountOnHide ] = useState( false );

useEffect( () => {
setUnmountOnHide( true );
}, [] );

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ function _LegacyCustomSelect( props: LegacyCustomSelectProps ) {
};
onChange( changeObject );
},
defaultValue: options[ 0 ].name,
} );

const children = options.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ const renderControlledValue = ( gravatar: string | string[] ) => {
export const Controlled = ControlledTemplate.bind( {} );
Controlled.args = {
label: 'Default Gravatars',
defaultValue: 'wavatar',
renderSelectedValue: renderControlledValue,
children: (
<>
Expand Down

0 comments on commit e3c328f

Please sign in to comment.