Skip to content

Commit

Permalink
Render a SelectControl for fields of type text if they define elements
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Aug 5, 2024
1 parent 8b1b939 commit 04039f8
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/dataviews/src/field-types/text.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* WordPress dependencies
*/
import { TextControl } from '@wordpress/components';
import { SelectControl, TextControl } from '@wordpress/components';
import { useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
Expand Down Expand Up @@ -47,6 +48,29 @@ function Edit< Item >( {
[ id, onChange ]
);

if ( field.elements ) {
const elements = [
/*
* Value can be undefined when:
*
* - the field is not required
* - in bulk editing
*
*/
{ label: __( 'Select item' ), value: '' },
...field.elements,
];

return (
<SelectControl
label={ label }
value={ value }
options={ elements }
onChange={ onChangeControl }
/>
);
}

return (
<TextControl
label={ label }
Expand Down

0 comments on commit 04039f8

Please sign in to comment.