Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Allow to change custom field type after creation, reusing create modal in browser extension (#2362)

Leendert de Borstf0371f30e698
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Forms/AddFieldMenu.tsx b/apps/browser-extension/src/entrypoints/popup/components/Forms/AddFieldMenu.tsx
index 3ba7282f9..c4c06f4e5 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Forms/AddFieldMenu.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Forms/AddFieldMenu.tsx
@@ -1,11 +1,11 @@
import React, { useState, useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
-import ModalWrapper from '@/entrypoints/popup/components/Dialogs/ModalWrapper';
-
import type { FieldType, SystemFieldDefinition } from '@/utils/dist/core/models/vault';
import { FieldCategories } from '@/utils/dist/core/models/vault';
+import CustomFieldModal from './CustomFieldModal';
+
/**
* Configuration for an optional section (not field-based).
*/
@@ -134,8 +134,6 @@ const AddFieldMenu: React.FC<AddFieldMenuProps> = ({
const { t } = useTranslation();
const [isOpen, setIsOpen] = useState(false);
const [showCustomFieldModal, setShowCustomFieldModal] = useState(false);
- const [customFieldLabel, setCustomFieldLabel] = useState('');
- const [customFieldType, setCustomFieldType] = useState<FieldType>('Text');
/**
* Handle opening the custom field modal.
@@ -145,29 +143,6 @@ const AddFieldMenu: React.FC<AddFieldMenuProps> = ({
setIsOpen(false);
}, []);
- /**
- * Handle adding the custom field.
- */
- const handleAddCustomField = useCallback((): void => {
- if (!customFieldLabel.trim()) {
- return;
- }
-
- callbacks.onAddCustomField(customFieldLabel, customFieldType);
- setCustomFieldLabel('');
- setCustomFieldType('Text');
- setShowCustomFieldModal(false);
- }, [customFieldLabel, customFieldType, callbacks]);
-
- /**
- * Handle closing the custom field modal.
- */
- const handleCloseCustomFieldModal = useCallback((): void => {
- setCustomFieldLabel('');
- setCustomFieldType('Text');
- setShowCustomFieldModal(false);
- }, []);
-
/**
* Handle adding a system field and closing menu.
*/
@@ -274,67 +249,11 @@ const AddFieldMenu: React.FC<AddFieldMenuProps> = ({
</div>
{/* Custom Field Modal */}
- <ModalWrapper
+ <CustomFieldModal
isOpen={showCustomFieldModal}
- onClose={handleCloseCustomFieldModal}
- title={t('itemTypes.addCustomField')}
- footer={
- <div className="flex gap-3">
- <button
- type="button"
- onClick={handleAddCustomField}
- disabled={!customFieldLabel.trim()}
- className="flex-1 px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 disabled:opacity-50 disabled:cursor-not-allowed"
- >
- {t('common.add')}
- </button>
- <button
- type="button"
- onClick={handleCloseCustomFieldModal}
- className="px-4 py-2 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-md hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
- >
- {t('common.cancel')}
- </button>
- </div>
- }
- >
- <div className="space-y-4">
- <div>
- <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
- {t('itemTypes.fieldLabel')}
- </label>
- <input
- type="text"
- value={customFieldLabel}
- onChange={(e) => setCustomFieldLabel(e.target.value)}
- className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white"
- placeholder={t('itemTypes.enterFieldName')}
- autoFocus
- />
- </div>
-
- <div>
- <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
- {t('itemTypes.fieldType')}
- </label>
- <select
- value={customFieldType}
- onChange={(e) => setCustomFieldType(e.target.value as FieldType)}
- className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white"
- >
- <option value="Text">{t('itemTypes.fieldTypes.text')}</option>
- <option value="Password">{t('itemTypes.fieldTypes.password')}</option>
- <option value="Hidden">{t('itemTypes.fieldTypes.hidden')}</option>
- <option value="Email">{t('itemTypes.fieldTypes.email')}</option>
- <option value="URL">{t('itemTypes.fieldTypes.url')}</option>
- <option value="Phone">{t('itemTypes.fieldTypes.phone')}</option>
- <option value="Number">{t('itemTypes.fieldTypes.number')}</option>
- <option value="Date">{t('itemTypes.fieldTypes.date')}</option>
- <option value="TextArea">{t('itemTypes.fieldTypes.textArea')}</option>
- </select>
- </div>
- </div>
- </ModalWrapper>
+ onClose={() => setShowCustomFieldModal(false)}
+ onSubmit={callbacks.onAddCustomField}
+ />
</>
);
};
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Forms/CustomFieldLabel.tsx b/apps/browser-extension/src/entrypoints/popup/components/Forms/CustomFieldLabel.tsx
new file mode 100644
index 000000000..e0ac75072
--- /dev/null
+++ b/apps/browser-extension/src/entrypoints/popup/components/Forms/CustomFieldLabel.tsx
@@ -0,0 +1,54 @@
+import React from 'react';
+import { useTranslation } from 'react-i18next';
+
+type CustomFieldLabelProps = {
+ htmlFor: string;
+ label: string;
+ onEdit: () => void;
+ onDelete?: () => void;
+}
+
+/**
+ * Label row for a custom field with edit and delete buttons.
+ * Editing opens the custom field modal so both the label and the type can be changed.
+ */
+const CustomFieldLabel: React.FC<CustomFieldLabelProps> = ({
+ htmlFor,
+ label,
+ onEdit,
+ onDelete
+}) => {
+ const { t } = useTranslation();
+
+ return (
+ <div className="flex items-center gap-2 mb-2">
+ <label htmlFor={htmlFor} className="text-sm font-medium text-gray-700 dark:text-gray-300">
+ {label}
+ </label>
+ <button
+ type="button"
+ onClick={onEdit}
+ className="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 text-xs"
+ title={t('itemTypes.editCustomField')}
+ >
+ <svg className="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" />
+ </svg>
+ </button>
+ {onDelete && (
+ <button
+ type="button"
+ onClick={onDelete}
+ className="text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 text-xs"
+ title={t('itemTypes.deleteCustomField')}
+ >
+ <svg className="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
+ </svg>
+ </button>
+ )}
+ </div>
+ );
+};
+
+export default CustomFieldLabel;
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Forms/CustomFieldModal.tsx b/apps/browser-extension/src/entrypoints/popup/components/Forms/CustomFieldModal.tsx
new file mode 100644
index 000000000..32151418c
--- /dev/null
+++ b/apps/browser-extension/src/entrypoints/popup/components/Forms/CustomFieldModal.tsx
@@ -0,0 +1,129 @@
+import React, { useCallback, useLayoutEffect, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import ModalWrapper from '@/entrypoints/popup/components/Dialogs/ModalWrapper';
+
+import type { FieldType } from '@/utils/dist/core/models/vault';
+import { FieldTypes } from '@/utils/dist/core/models/vault';
+
+type CustomFieldModalProps = {
+ isOpen: boolean;
+ /** Existing field values when editing, omitted when adding a new field */
+ initialValues?: { label: string; fieldType: FieldType };
+ onClose: () => void;
+ onSubmit: (label: string, fieldType: FieldType) => void;
+};
+
+/**
+ * Modal for creating and editing a custom field.
+ */
+const CustomFieldModal: React.FC<CustomFieldModalProps> = ({
+ isOpen,
+ initialValues,
+ onClose,
+ onSubmit
+}) => {
+ const { t } = useTranslation();
+ const isEditMode = initialValues !== undefined;
+ const [label, setLabel] = useState('');
+ const [fieldType, setFieldType] = useState<FieldType>(FieldTypes.Text);
+
+ /**
+ * Reset the form to the field being edited (or to defaults) whenever the modal opens.
+ */
+ useLayoutEffect(() => {
+ if (isOpen) {
+ setLabel(initialValues?.label ?? '');
+ setFieldType(initialValues?.fieldType ?? FieldTypes.Text);
+ }
+ }, [isOpen, initialValues]);
+
+ /**
+ * Submit the form and close the modal.
+ */
+ const handleSubmit = useCallback((): void => {
+ if (!label.trim()) {
+ return;
+ }
+
+ onSubmit(label.trim(), fieldType);
+ onClose();
+ }, [label, fieldType, onSubmit, onClose]);
+
+ /**
+ * Submit on enter so the label input can be confirmed without reaching for the mouse.
+ */
+ const handleKeyDown = useCallback((e: React.KeyboardEvent): void => {
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ handleSubmit();
+ }
+ }, [handleSubmit]);
+
+ return (
+ <ModalWrapper
+ isOpen={isOpen}
+ onClose={onClose}
+ title={isEditMode ? t('itemTypes.editCustomField') : t('itemTypes.addCustomField')}
+ footer={
+ <div className="flex gap-3">
+ <button
+ type="button"
+ onClick={handleSubmit}
+ disabled={!label.trim()}
+ className="flex-1 px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 disabled:opacity-50 disabled:cursor-not-allowed"
+ >
+ {isEditMode ? t('common.save') : t('common.add')}
+ </button>
+ <button
+ type="button"
+ onClick={onClose}
+ className="px-4 py-2 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-md hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
+ >
+ {t('common.cancel')}
+ </button>
+ </div>
+ }
+ >
+ <div className="space-y-4">
+ <div>
+ <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
+ {t('itemTypes.fieldLabel')}
+ </label>
+ <input
+ type="text"
+ value={label}
+ onChange={(e) => setLabel(e.target.value)}
+ onKeyDown={handleKeyDown}
+ className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white"
+ placeholder={t('itemTypes.enterFieldName')}
+ autoFocus
+ />
+ </div>
+
+ <div>
+ <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
+ {t('itemTypes.fieldType')}
+ </label>
+ <select
+ value={fieldType}
+ onChange={(e) => setFieldType(e.target.value as FieldType)}
+ className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white"
+ >
+ <option value={FieldTypes.Text}>{t('itemTypes.fieldTypes.text')}</option>
+ <option value={FieldTypes.Password}>{t('itemTypes.fieldTypes.password')}</option>
+ <option value={FieldTypes.Hidden}>{t('itemTypes.fieldTypes.hidden')}</option>
+ <option value={FieldTypes.Email}>{t('itemTypes.fieldTypes.email')}</option>
+ <option value={FieldTypes.URL}>{t('itemTypes.fieldTypes.url')}</option>
+ <option value={FieldTypes.Phone}>{t('itemTypes.fieldTypes.phone')}</option>
+ <option value={FieldTypes.Number}>{t('itemTypes.fieldTypes.number')}</option>
+ <option value={FieldTypes.Date}>{t('itemTypes.fieldTypes.date')}</option>
+ <option value={FieldTypes.TextArea}>{t('itemTypes.fieldTypes.textArea')}</option>
+ </select>
+ </div>
+ </div>
+ </ModalWrapper>
+ );
+};
+
+export default CustomFieldModal;
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Forms/DraggableCustomFieldsList.tsx b/apps/browser-extension/src/entrypoints/popup/components/Forms/DraggableCustomFieldsList.tsx
index d63075f14..23186ed79 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Forms/DraggableCustomFieldsList.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Forms/DraggableCustomFieldsList.tsx
@@ -15,12 +15,13 @@ import {
verticalListSortingStrategy,
} from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
-import React, { useCallback } from 'react';
+import React, { useCallback, useMemo, useState } from 'react';
import type { FieldType } from '@/utils/dist/core/models/vault';
import { FieldTypes } from '@/utils/dist/core/models/vault';
-import EditableFieldLabel from './EditableFieldLabel';
+import CustomFieldLabel from './CustomFieldLabel';
+import CustomFieldModal from './CustomFieldModal';
import { FormInput } from './FormInput';
import HiddenField from './HiddenField';
import PasswordField from './PasswordField';
@@ -40,7 +41,7 @@ interface ISortableCustomFieldProps {
field: CustomFieldDefinition;
value: string;
onValueChange: (value: string) => void;
- onLabelChange: (newLabel: string) => void;
+ onEdit: () => void;
onDelete: () => void;
}
@@ -51,7 +52,7 @@ const SortableCustomField: React.FC<ISortableCustomFieldProps> = ({
field,
value,
onValueChange,
- onLabelChange,
+ onEdit,
onDelete,
}) => {
const {
@@ -131,10 +132,10 @@ const SortableCustomField: React.FC<ISortableCustomFieldProps> = ({
{...attributes}
{...listeners}
>
- <EditableFieldLabel
+ <CustomFieldLabel
htmlFor={field.tempId}
label={field.label}
- onLabelChange={onLabelChange}
+ onEdit={onEdit}
onDelete={onDelete}
/>
</div>
@@ -149,7 +150,7 @@ interface IDraggableCustomFieldsListProps {
fieldValues: Record<string, string | string[]>;
onFieldsReorder: (reorderedFields: CustomFieldDefinition[]) => void;
onFieldValueChange: (tempId: string, value: string) => void;
- onFieldLabelChange: (tempId: string, newLabel: string) => void;
+ onFieldUpdate: (tempId: string, label: string, fieldType: FieldType) => void;
onFieldDelete: (tempId: string) => void;
}
@@ -162,9 +163,15 @@ const DraggableCustomFieldsList: React.FC<IDraggableCustomFieldsListProps> = ({
fieldValues,
onFieldsReorder,
onFieldValueChange,
- onFieldLabelChange,
+ onFieldUpdate,
onFieldDelete,
}) => {
+ const [editingFieldId, setEditingFieldId] = useState<string | null>(null);
+ const editingField = customFields.find((f) => f.tempId === editingFieldId);
+ const editingValues = useMemo(
+ () => editingField ? { label: editingField.label, fieldType: editingField.fieldType } : undefined,
+ [editingField]
+ );
const sensors = useSensors(
useSensor(PointerSensor, {
activationConstraint: {
@@ -197,34 +204,52 @@ const DraggableCustomFieldsList: React.FC<IDraggableCustomFieldsListProps> = ({
}
}, [customFields, onFieldsReorder]);
+ /**
+ * Apply the edits made in the custom field modal to the field being edited.
+ */
+ const handleEditSubmit = useCallback((label: string, fieldType: FieldType) => {
+ if (editingFieldId) {
+ onFieldUpdate(editingFieldId, label, fieldType);
+ }
+ }, [editingFieldId, onFieldUpdate]);
+
if (customFields.length === 0) {
return null;
}
return (
- <DndContext
- sensors={sensors}
- collisionDetection={closestCenter}
- onDragEnd={handleDragEnd}
- >
- <SortableContext
- items={customFields.map((f) => f.tempId)}
- strategy={verticalListSortingStrategy}
+ <>
+ <DndContext
+ sensors={sensors}
+ collisionDetection={closestCenter}
+ onDragEnd={handleDragEnd}
>
- <div className="space-y-3">
- {customFields.map((field) => (
- <SortableCustomField
- key={field.tempId}
- field={field}
- value={(fieldValues[field.tempId] as string) || ''}
- onValueChange={(value) => onFieldValueChange(field.tempId, value)}
- onLabelChange={(newLabel) => onFieldLabelChange(field.tempId, newLabel)}
- onDelete={() => onFieldDelete(field.tempId)}
- />
- ))}
- </div>
- </SortableContext>
- </DndContext>
+ <SortableContext
+ items={customFields.map((f) => f.tempId)}
+ strategy={verticalListSortingStrategy}
+ >
+ <div className="space-y-3">
+ {customFields.map((field) => (
+ <SortableCustomField
+ key={field.tempId}
+ field={field}
+ value={(fieldValues[field.tempId] as string) || ''}
+ onValueChange={(value) => onFieldValueChange(field.tempId, value)}
+ onEdit={() => setEditingFieldId(field.tempId)}
+ onDelete={() => onFieldDelete(field.tempId)}
+ />
+ ))}
+ </div>
+ </SortableContext>
+ </DndContext>
+
+ <CustomFieldModal
+ isOpen={editingValues !== undefined}
+ initialValues={editingValues}
+ onClose={() => setEditingFieldId(null)}
+ onSubmit={handleEditSubmit}
+ />
+ </>
);
};
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Forms/EditableFieldLabel.tsx b/apps/browser-extension/src/entrypoints/popup/components/Forms/EditableFieldLabel.tsx
deleted file mode 100644
index 451177f05..000000000
--- a/apps/browser-extension/src/entrypoints/popup/components/Forms/EditableFieldLabel.tsx
+++ /dev/null
@@ -1,114 +0,0 @@
-import React, { useState } from 'react';
-
-type EditableFieldLabelProps = {
- htmlFor: string;
- label: string;
- onLabelChange: (newLabel: string) => void;
- onDelete?: () => void;
-}
-
-/**
- * Editable field label component with edit button.
- * Shows label text with a small edit icon. When clicked, shows an input field.
- */
-const EditableFieldLabel: React.FC<EditableFieldLabelProps> = ({
- htmlFor,
- label,
- onLabelChange,
- onDelete
-}) => {
- const [isEditing, setIsEditing] = useState(false);
- const [editValue, setEditValue] = useState(label);
-
- /**
- * Handle the save action.
- */
- const handleSave = (): void => {
- if (editValue.trim()) {
- onLabelChange(editValue.trim());
- setIsEditing(false);
- }
- };
-
- /**
- * Handle the cancel action.
- */
- const handleCancel = (): void => {
- setEditValue(label);
- setIsEditing(false);
- };
-
- /**
- * Handle the key down event.
- */
- const handleKeyDown = (e: React.KeyboardEvent): void => {
- if (e.key === 'Enter') {
- handleSave();
- } else if (e.key === 'Escape') {
- handleCancel();
- }
- };
-
- if (isEditing) {
- return (
- <div className="flex items-center gap-2 mb-2">
- <input
- type="text"
- value={editValue}
- onChange={(e) => setEditValue(e.target.value)}
- onKeyDown={handleKeyDown}
- onBlur={handleSave}
- className="flex-1 px-2 py-1 text-sm font-medium text-gray-700 dark:text-gray-300 border border-primary-500 rounded focus:outline-none focus:ring-1 focus:ring-primary-500 dark:bg-gray-700 dark:border-primary-400"
- placeholder="Field label"
- autoFocus
- />
- <button
- type="button"
- onClick={handleSave}
- className="text-green-600 dark:text-green-400 hover:text-green-700 dark:hover:text-green-300 text-xs px-2 py-1"
- >
- ✓
- </button>
- <button
- type="button"
- onClick={handleCancel}
- className="text-gray-600 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 text-xs px-2 py-1"
- >
- ✕
- </button>
- </div>
- );
- }
-
- return (
- <div className="flex items-center gap-2 mb-2">
- <label htmlFor={htmlFor} className="text-sm font-medium text-gray-700 dark:text-gray-300">
- {label}
- </label>
- <button
- type="button"
- onClick={() => setIsEditing(true)}
- className="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 text-xs"
- title="Edit label"
- >
- <svg className="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" />
- </svg>
- </button>
- {onDelete && (
- <button
- type="button"
- onClick={onDelete}
- className="text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 text-xs"
- title="Delete field"
- >
- <svg className="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
- </svg>
- </button>
- )}
- </div>
- );
-};
-
-export default EditableFieldLabel;
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx
index 2acef5d06..374b28c95 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx
@@ -67,6 +67,12 @@ type PersistedFormData = {
passwordSettings?: PasswordSettings;
};
+/**
+ * Whether a custom field of the given type should be masked in the UI.
+ */
+const isMaskedFieldType = (fieldType: FieldType): boolean =>
+ fieldType === FieldTypes.Password || fieldType === FieldTypes.Hidden;
+
/**
* Add or edit item page with dynamic field support.
* Shows all applicable system fields for the item type, not just fields with values.
@@ -891,7 +897,7 @@ const ItemAddEdit: React.FC = () => {
tempId,
label,
fieldType,
- isHidden: false,
+ isHidden: isMaskedFieldType(fieldType),
displayOrder: applicableSystemFields.length + customFields.length + 1
};
@@ -911,11 +917,11 @@ const ItemAddEdit: React.FC = () => {
}, []);
/**
- * Update custom field label handler.
+ * Update custom field handler. Both the label and the field type can be changed.
*/
- const handleUpdateCustomFieldLabel = useCallback((tempId: string, newLabel: string) => {
+ const handleUpdateCustomField = useCallback((tempId: string, label: string, fieldType: FieldType) => {
setCustomFields(prev => prev.map(f =>
- f.tempId === tempId ? { ...f, label: newLabel } : f
+ f.tempId === tempId ? { ...f, label, fieldType, isHidden: isMaskedFieldType(fieldType) } : f
));
}, []);
@@ -1522,7 +1528,7 @@ const ItemAddEdit: React.FC = () => {
fieldValues={fieldValues}
onFieldsReorder={handleCustomFieldsReorder}
onFieldValueChange={(tempId, value) => handleFieldChange(tempId, value)}
- onFieldLabelChange={handleUpdateCustomFieldLabel}
+ onFieldUpdate={handleUpdateCustomField}
onFieldDelete={handleDeleteCustomField}
/>
</FormSection>
diff --git a/apps/browser-extension/src/i18n/locales/en.json b/apps/browser-extension/src/i18n/locales/en.json
index 5a51d41a4..a76b8e909 100644
--- a/apps/browser-extension/src/i18n/locales/en.json
+++ b/apps/browser-extension/src/i18n/locales/en.json
@@ -283,6 +283,8 @@
"creating": "Creating",
"editing": "Editing",
"addCustomField": "Add custom field",
+ "editCustomField": "Edit custom field",
+ "deleteCustomField": "Delete custom field",
"fieldLabel": "Field Label",
"enterFieldName": "Enter field name",
"fieldType": "Field Type",