Skip to content

Commit f255b84

Browse files
Replace old CustomSelectControl select control with the V2 legacy adapter and fix selectedItem handling onChange
1 parent db07eaf commit f255b84

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

packages/block-editor/src/components/font-appearance-control/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ export default function FontAppearanceControl( props ) {
203203
);
204204
};
205205

206+
console.debug( 'selectOptions: ', selectOptions );
207+
206208
return (
207209
hasStylesOrWeights && (
208210
<CustomSelectControl
@@ -212,9 +214,11 @@ export default function FontAppearanceControl( props ) {
212214
describedBy={ getDescribedBy() }
213215
options={ selectOptions }
214216
value={ currentSelection }
215-
onChange={ ( { selectedItem } ) =>
216-
onChange( selectedItem.style )
217-
}
217+
onChange={ ( { selectedItem } ) => {
218+
console.debug( 'selectedItem:' );
219+
console.debug( selectedItem );
220+
onChange( selectedItem.style );
221+
} }
218222
/>
219223
)
220224
);

packages/block-editor/src/components/global-styles/typography-panel.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ export default function TypographyPanel( {
223223
fontStyle: newFontStyle,
224224
fontWeight: newFontWeight,
225225
} ) => {
226+
console.debug(fontStyle);
227+
console.debug(fontWeight);
226228
onChange( {
227229
...value,
228230
typography: {

packages/components/src/custom-select-control-v2/legacy-component/index.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,22 @@ function CustomSelectControl( props: LegacyCustomSelectProps ) {
3030
// Forward props + store from v2 implementation
3131
const store = Ariakit.useSelectStore( {
3232
async setValue( nextValue ) {
33-
if ( ! onChange ) {
34-
return;
35-
}
33+
if ( ! onChange ) return;
3634

3735
// Executes the logic in a microtask after the popup is closed.
3836
// This is simply to ensure the isOpen state matches that in Downshift.
3937
await Promise.resolve();
4038
const state = store.getState();
4139

40+
const option = options.find( ( item ) => item.name === nextValue );
41+
4242
const changeObject = {
4343
highlightedIndex: state.renderedItems.findIndex(
4444
( item ) => item.value === nextValue
4545
),
4646
inputValue: '',
4747
isOpen: state.open,
48-
selectedItem: {
49-
name: nextValue as string,
50-
key: nextValue as string,
51-
},
48+
selectedItem: option!,
5249
type: '',
5350
};
5451
onChange( changeObject );
@@ -131,3 +128,14 @@ function CustomSelectControl( props: LegacyCustomSelectProps ) {
131128
}
132129

133130
export default CustomSelectControl;
131+
132+
// for backwards compatibility
133+
export function ClassicCustomSelectControl( props: LegacyCustomSelectProps ) {
134+
console.debug( props );
135+
return (
136+
<CustomSelectControl
137+
{ ...props }
138+
__experimentalShowSelectedHint={ false }
139+
/>
140+
);
141+
}

packages/components/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export {
6363
useCompositeState as __unstableUseCompositeState,
6464
} from './composite';
6565
export { ConfirmDialog as __experimentalConfirmDialog } from './confirm-dialog';
66-
export { StableCustomSelectControl as CustomSelectControl } from './custom-select-control';
66+
export { ClassicCustomSelectControl as CustomSelectControl } from './custom-select-control-v2/legacy-component';
67+
export { default as CustomSelectControlV2 } from './custom-select-control-v2';
6768
export { default as Dashicon } from './dashicon';
6869
export { default as DateTimePicker, DatePicker, TimePicker } from './date-time';
6970
export { default as __experimentalDimensionControl } from './dimension-control';

0 commit comments

Comments
 (0)