fix: keep a recipient's closing bracket when Backspace pulls it back to edit

This commit is contained in:
Linus Rath
2026-11-03 07:06:34 +01:00
parent 0444cbd4a2
commit 2af897b223
2 changed files with 10 additions and 0 deletions
@@ -538,6 +538,14 @@ describe('composer with the @ recipient list', () => {
expect(onClose).not.toHaveBeenCalled();
});
it('pulls the last recipient back whole on Backspace, without the key deleting its last character', async () => {
await renderComposer({ to: 'Sarah Kim <sarah@example.com>' });
const to = within(screen.getByTestId('composer-to')).getByRole('combobox') as HTMLInputElement;
// fireEvent returns false when the handler stopped the key's default action.
expect(fireEvent.keyDown(to, { key: 'Backspace' })).toBe(false);
expect(to.value).toBe('Sarah Kim <sarah@example.com>');
});
// The directory picker is drawn inside the composer itself, not portaled.
it('lets Escape in the directory picker leave the composer alone', async () => {
// Every other capability answers nothing.
+2
View File
@@ -5930,6 +5930,8 @@ export function RecipientChipInput({
// Backspace on an empty input pulls the last chip back into the input for
// quick editing.
if (e.key === 'Backspace' && !inputText && chips.length > 0) {
// Or the key goes on to delete the closing ">" of what was just put back.
e.preventDefault();
const lastChip = chips[chips.length - 1];
onChipsChange(chips.slice(0, -1));
onInputChange(formatRecipient(lastChip.name, lastChip.email));