Skip to content

🙌 OpenHands: AI-Driven Development

fix(frontend): accept typed emails without requiring Space in the invite input (#14790)

Alona2c6a456424ef
diff --git a/frontend/__tests__/components/features/org/invite-organization-member-modal.test.tsx b/frontend/__tests__/components/features/org/invite-organization-member-modal.test.tsx
index 19d490a8a6..a8d82e2c7a 100644
--- a/frontend/__tests__/components/features/org/invite-organization-member-modal.test.tsx
+++ b/frontend/__tests__/components/features/org/invite-organization-member-modal.test.tsx
@@ -168,4 +168,29 @@ describe("InviteOrganizationMemberModal", () => {
);
expect(inviteMembersSpy).not.toHaveBeenCalled();
});
+
+ it("should invite a typed email even when it was never committed with space", async () => {
+ const inviteMembersBatchSpy = vi.spyOn(
+ organizationService,
+ "inviteMembers",
+ );
+ const onCloseMock = vi.fn();
+
+ renderInviteOrganizationMemberModal({ onClose: onCloseMock });
+
+ const modal = screen.getByTestId("invite-modal");
+ const badgeInput = within(modal).getByTestId("emails-badge-input");
+ // No trailing space — clicking the button blurs the input, which commits
+ // the pending text. Previously this errored with "press space".
+ await userEvent.type(badgeInput, "[email protected]");
+
+ const submitButton = within(modal).getByRole("button", { name: /add/i });
+ await userEvent.click(submitButton);
+
+ expect(inviteMembersBatchSpy).toHaveBeenCalledExactlyOnceWith({
+ orgId: "1",
+ emails: ["[email protected]"],
+ role: "member",
+ });
+ });
});
diff --git a/frontend/__tests__/components/shared/inputs/badge-input.test.tsx b/frontend/__tests__/components/shared/inputs/badge-input.test.tsx
index 18fff61ee6..33daad453f 100644
--- a/frontend/__tests__/components/shared/inputs/badge-input.test.tsx
+++ b/frontend/__tests__/components/shared/inputs/badge-input.test.tsx
@@ -59,4 +59,55 @@ describe("BadgeInput", () => {
await userEvent.type(input, " ");
expect(onChangeMock).not.toHaveBeenCalled();
});
+
+ it("should render the input as a badge on enter", async () => {
+ const onChangeMock = vi.fn();
+ render(<BadgeInput value={[]} onChange={onChangeMock} />);
+
+ const input = screen.getByTestId("badge-input");
+ await userEvent.type(input, "test{enter}");
+
+ expect(onChangeMock).toHaveBeenCalledWith(["test"]);
+ expect(input).toHaveValue("");
+ });
+
+ it("should render the input as a badge on comma", async () => {
+ const onChangeMock = vi.fn();
+ render(<BadgeInput value={[]} onChange={onChangeMock} />);
+
+ const input = screen.getByTestId("badge-input");
+ await userEvent.type(input, "test,");
+
+ expect(onChangeMock).toHaveBeenCalledWith(["test"]);
+ expect(input).toHaveValue("");
+ });
+
+ it("should commit pending input as a badge on blur", async () => {
+ const onChangeMock = vi.fn();
+ render(<BadgeInput value={[]} onChange={onChangeMock} />);
+
+ const input = screen.getByTestId("badge-input");
+ await userEvent.type(input, "test");
+ await userEvent.tab();
+
+ expect(onChangeMock).toHaveBeenCalledWith(["test"]);
+ expect(input).toHaveValue("");
+ });
+
+ it("should split pasted text into multiple badges", async () => {
+ const onChangeMock = vi.fn();
+ render(<BadgeInput value={[]} onChange={onChangeMock} />);
+
+ const input = screen.getByTestId("badge-input");
+ await userEvent.click(input);
+ await userEvent.tab();
+
+ expect(onChangeMock).toHaveBeenCalledWith([
+ ]);
+ expect(input).toHaveValue("");
+ });
});
diff --git a/frontend/src/components/features/org/invite-organization-member-modal.tsx b/frontend/src/components/features/org/invite-organization-member-modal.tsx
index 3f982d7334..c389315389 100644
--- a/frontend/src/components/features/org/invite-organization-member-modal.tsx
+++ b/frontend/src/components/features/org/invite-organization-member-modal.tsx
@@ -68,7 +68,7 @@ export function InviteOrganizationMemberModal({
<BadgeInput
name="emails-badge-input"
value={emails}
- placeholder={t(I18nKey.COMMON$TYPE_EMAIL_AND_PRESS_SPACE)}
+ placeholder={t(I18nKey.COMMON$ENTER_EMAIL_ADDRESSES)}
onChange={handleEmailsChange}
/>
<label className="flex flex-col gap-1 text-sm capitalize">
diff --git a/frontend/src/components/shared/inputs/badge-input.tsx b/frontend/src/components/shared/inputs/badge-input.tsx
index cc34db4293..0ce7112d85 100644
--- a/frontend/src/components/shared/inputs/badge-input.tsx
+++ b/frontend/src/components/shared/inputs/badge-input.tsx
@@ -22,6 +22,13 @@ export function BadgeInput({
}: BadgeInputProps) {
const [inputValue, setInputValue] = React.useState("");
+ const commitInput = (text: string) => {
+ // Pasted lists may hold several values split by whitespace/commas/semicolons
+ const newBadges = text.split(/[\s,;]+/).filter(Boolean);
+ if (newBadges.length > 0) onChange([...value, ...newBadges]);
+ setInputValue("");
+ };
+
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
// If pressing Backspace with empty input, remove the last badge
if (e.key === "Backspace" && inputValue === "" && value.length > 0) {
@@ -31,12 +38,13 @@ export function BadgeInput({
return;
}
- // If pressing Space or Enter with non-empty input, add a new badge
- if (e.key === " " && inputValue.trim() !== "") {
+ // If pressing Space, Enter or comma with non-empty input, add a new badge
+ if (
+ (e.key === " " || e.key === "Enter" || e.key === ",") &&
+ inputValue.trim() !== ""
+ ) {
e.preventDefault();
- const newBadge = inputValue.trim();
- onChange([...value, newBadge]);
- setInputValue("");
+ commitInput(inputValue);
}
};
@@ -74,6 +82,7 @@ export function BadgeInput({
placeholder={value.length === 0 ? placeholder : ""}
onChange={(e) => setInputValue(e.target.value)}
onKeyDown={handleKeyDown}
+ onBlur={() => commitInput(inputValue)}
className={cn("flex-grow outline-none bg-transparent", inputClassName)}
/>
</div>
diff --git a/frontend/src/i18n/declaration.ts b/frontend/src/i18n/declaration.ts
index be241fb797..ba31d0da4e 100644
--- a/frontend/src/i18n/declaration.ts
+++ b/frontend/src/i18n/declaration.ts
@@ -1342,7 +1342,7 @@ export enum I18nKey {
HOOK$ERROR = "HOOK$ERROR",
HOOK$OUTPUT = "HOOK$OUTPUT",
HOOK$STDERR = "HOOK$STDERR",
- COMMON$TYPE_EMAIL_AND_PRESS_SPACE = "COMMON$TYPE_EMAIL_AND_PRESS_SPACE",
+ COMMON$ENTER_EMAIL_ADDRESSES = "COMMON$ENTER_EMAIL_ADDRESSES",
ORG$INVITE_ORG_MEMBERS = "ORG$INVITE_ORG_MEMBERS",
ORG$MANAGE_ORGANIZATION = "ORG$MANAGE_ORGANIZATION",
ORG$ORGANIZATION_MEMBERS = "ORG$ORGANIZATION_MEMBERS",
diff --git a/frontend/src/i18n/translation.json b/frontend/src/i18n/translation.json
index 9dc2ffd35c..7ab5637b4a 100644
--- a/frontend/src/i18n/translation.json
+++ b/frontend/src/i18n/translation.json
@@ -21284,21 +21284,21 @@
"ca": "No s'admeten adreces de correu electrònic duplicades"
},
"ORG$NO_EMAILS_ADDED_HINT": {
- "en": "Please type emails and then press space.",
- "ja": "メールアドレスを入力してからスペースを押してください。",
- "zh-CN": "请输入邮箱然后按空格键。",
- "zh-TW": "請輸入電子郵件然後按空白鍵。",
- "ko-KR": "이메일을 입력한 후 스페이스바를 눌러주세요.",
- "no": "Skriv inn e-post og trykk mellomrom.",
- "it": "Digita le email e poi premi spazio.",
- "pt": "Digite os e-mails e pressione espaço.",
- "es": "Escriba los correos electrónicos y luego presione espacio.",
- "ar": "يرجى كتابة البريد الإلكتروني ثم الضغط على مفتاح المسافة.",
- "fr": "Veuillez saisir les e-mails puis appuyer sur espace.",
- "tr": "Lütfen e-postaları yazın ve ardından boşluk tuşuna basın.",
- "de": "Bitte geben Sie E-Mails ein und drücken Sie dann die Leertaste.",
- "uk": "Будь ласка, введіть електронні адреси та натисніть пробіл.",
- "ca": "Escriviu els correus electrònics i premeu espai."
+ "ar": "يرجى إدخال عنوان بريد إلكتروني واحد على الأقل.",
+ "ca": "Introduïu almenys una adreça de correu electrònic.",
+ "de": "Bitte geben Sie mindestens eine E-Mail-Adresse ein.",
+ "en": "Please enter at least one email address.",
+ "es": "Introduce al menos una dirección de correo electrónico.",
+ "fr": "Veuillez saisir au moins une adresse e-mail.",
+ "it": "Inserisci almeno un indirizzo email.",
+ "ja": "メールアドレスを少なくとも1つ入力してください。",
+ "ko-KR": "이메일 주소를 하나 이상 입력해 주세요.",
+ "no": "Vennligst skriv inn minst én e-postadresse.",
+ "pt": "Insira pelo menos um endereço de e-mail.",
+ "tr": "Lütfen en az bir e-posta adresi girin.",
+ "uk": "Будь ласка, введіть принаймні одну адресу електронної пошти.",
+ "zh-CN": "请至少输入一个电子邮件地址。",
+ "zh-TW": "請至少輸入一個電子郵件地址。"
},
"ORG$ACCOUNT": {
"en": "Account",
@@ -22813,22 +22813,22 @@
"uk": "Стандартна помилка",
"ca": "Stderr"
},
- "COMMON$TYPE_EMAIL_AND_PRESS_SPACE": {
- "en": "Type email and press Space",
- "ja": "メールアドレスを入力してスペースキーを押してください",
- "zh-CN": "输入邮箱并按空格键",
- "zh-TW": "輸入電子郵件並按空白鍵",
- "ko-KR": "이메일을 입력하고 스페이스바를 누르세요",
- "no": "Skriv inn e-post og trykk på mellomromstasten",
- "it": "Digita l'e-mail e premi Spazio",
- "pt": "Digite o e-mail e pressione Espaço",
- "es": "Escribe el correo electrónico y pulsa Espacio",
- "ar": "اكتب البريد الإلكتروني واضغط على مفتاح المسافة",
- "fr": "Tapez l'e-mail et appuyez sur Espace",
- "tr": "E-postu yazıp Boşluk tuşuna basın",
- "de": "E-Mail eingeben und Leertaste drücken",
- "uk": "Введіть e-mail і натисніть Пробіл",
- "ca": "Escriviu el correu electrònic i premeu Espai"
+ "COMMON$ENTER_EMAIL_ADDRESSES": {
+ "ar": "أدخل عناوين البريد الإلكتروني",
+ "ca": "Introduïu adreces de correu electrònic",
+ "de": "E-Mail-Adressen eingeben",
+ "en": "Enter email addresses",
+ "es": "Introduce direcciones de correo electrónico",
+ "fr": "Saisissez des adresses e-mail",
+ "it": "Inserisci indirizzi email",
+ "ja": "メールアドレスを入力",
+ "ko-KR": "이메일 주소를 입력하세요",
+ "no": "Skriv inn e-postadresser",
+ "pt": "Digite endereços de e-mail",
+ "tr": "E-posta adreslerini girin",
+ "uk": "Введіть адреси електронної пошти",
+ "zh-CN": "输入电子邮件地址",
+ "zh-TW": "輸入電子郵件地址"
},
"ORG$INVITE_ORG_MEMBERS": {
"en": "Invite Organization Members",