File size: 910 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import { SelectControl } from '@wordpress/components';
import { useCallback } from '@wordpress/element';
import type { DataFormControlProps } from '@wordpress/dataviews';
// A verbatim copy of @wordpress/dataviews/src/dataform-controls/select.tsx,
// but without the first placeholder option.
export default function RequiredSelect< Item >( {
data,
field,
onChange,
hideLabelFromVision,
}: DataFormControlProps< Item > ) {
const { id, label } = field;
const value = field.getValue( { item: data } ) ?? '';
const onChangeControl = useCallback(
( newValue: any ) =>
onChange( {
[ id ]: newValue,
} ),
[ id, onChange ]
);
return (
<SelectControl
label={ label }
value={ value }
help={ field.description }
options={ field.elements }
onChange={ onChangeControl }
__next40pxDefaultSize
__nextHasNoMarginBottom
hideLabelFromVision={ hideLabelFromVision }
/>
);
}
|