1 import { type FC, type MutableRefObject, useRef } from 'react';
3 import { type FieldProps } from 'formik';
5 import { InputFieldTwo, SelectTwo } from '@proton/components';
6 import { type InputFieldProps } from '@proton/components/components/v2/field/InputField';
7 import clsx from '@proton/utils/clsx';
9 import { useFieldControl } from '../../../hooks/useFieldControl';
10 import { FieldBox, type FieldBoxProps } from './Layout/FieldBox';
12 export type SelectFieldProps = FieldProps &
13 InputFieldProps<typeof SelectTwo> &
14 Omit<FieldBoxProps, 'actions' | 'actionsContainerClassName'> & { selectClassName?: string };
16 const Loader: FC = () => <div className="pass-skeleton pass-skeleton--select" />;
18 export const SelectField: FC<SelectFieldProps> = ({
31 const { error } = useFieldControl({ field, form, meta });
32 const fieldBoxRef = useRef<HTMLDivElement>(null);
35 <FieldBox className={clsx('items-center', className)} icon={icon} ref={fieldBoxRef} unstyled={props.unstyled}>
36 <InputFieldTwo<typeof SelectTwo>
38 assistContainerClassName="empty:hidden"
40 labelContainerClassName="expand-click-area color-weak m-0 text-normal text-sm"
41 originalPlacement="bottom"
42 renderSelected={() => (loading ? <Loader /> : renderSelected?.())}
43 anchorRef={fieldBoxRef as MutableRefObject<any>}
47 className={selectClassName}
49 onValue={(value: unknown) => {
51 return form.setFieldValue(field.name, value);