Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions browser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ This changelog covers all five packages, as they are (for now) updated as a whol

## UNRELEASED

- The role picker next to the email field in the share dialog opens again. A
click on it also focused the email field, which closed its option list right
after it opened. The email field also asks password managers (Bitwarden,
1Password, LastPass, Dashlane) not to fill it, since it holds other people's
addresses.
- Pasting an agent secret that opens a different agent than the signed-in
account no longer signs that account out on its own. The app now says which
account is signed in, shows both agents, and lets the user stay signed in or
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// @vitest-environment jsdom
// @wc-ignore-file
import React from 'react';
import { afterEach, expect, it } from 'vitest';
import { cleanup, fireEvent, render } from '@testing-library/react';
import { ThemeProvider, type DefaultTheme } from 'styled-components';
import { EmailInviteInput } from './EmailInviteInput';
import type { ShareRole } from './RoleSelect';

afterEach(cleanup);

const theme = { colors: {} } as unknown as DefaultTheme;
const writeRole: ShareRole = 'write';

const renderInput = () =>
render(
<ThemeProvider theme={theme}>
<EmailInviteInput
emails={[]}
onEmailsChange={() => undefined}
draft=''
onDraftChange={() => undefined}
role={writeRole}
onRoleChange={() => undefined}
/>
</ThemeProvider>,
);

it('leaves focus on the role select when it is clicked', () => {
const { getByLabelText } = renderInput();
const input = getByLabelText('Add people by email');
const select = getByLabelText('Role for invited people');

select.focus();
fireEvent.click(select);

// Focusing the input here would blur the select and close its option list.
expect(document.activeElement).toBe(select);
expect(document.activeElement).not.toBe(input);
});

it('focuses the input when the empty part of the field is clicked', () => {
const { getByLabelText } = renderInput();
const input = getByLabelText('Add people by email');
const field = input.closest('div')!.parentElement!;

fireEvent.click(field);

expect(document.activeElement).toBe(input);
});

it('asks password managers not to fill the invite field', () => {
const { getByLabelText } = renderInput();
const input = getByLabelText('Add people by email');

expect(input.getAttribute('type')).toBe('email');
expect(input.getAttribute('autocomplete')).toBe('off');
expect(input.hasAttribute('data-bwignore')).toBe(true);
expect(input.hasAttribute('data-1p-ignore')).toBe(true);
expect(input.getAttribute('data-lpignore')).toBe('true');
});
22 changes: 20 additions & 2 deletions browser/data-browser/src/components/Share/EmailInviteInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,20 @@ export function EmailInviteInput({
inputRef.current?.focus();
};

/**
* Clicking the empty part of the field focuses the input, like a textbox.
* Clicks on the controls inside it (the role select, the chip buttons, the
* input itself) are left alone: moving focus away from a native select right
* after it opened blurs it, which closes its option list again.
*/
const handleFieldClick = (e: React.MouseEvent<HTMLDivElement>) => {
if ((e.target as Element).closest('select, button, input')) return;

inputRef.current?.focus();
};

return (
<Field onClick={() => inputRef.current?.focus()}>
<Field onClick={handleFieldClick}>
<Chips>
{emails.map(email => (
<Chip key={email}>
Expand All @@ -101,7 +113,13 @@ export function EmailInviteInput({
ref={inputRef}
type='email'
multiple
autoComplete='email'
// These are other people's addresses, not the user's own, so
// neither the browser nor a password manager should fill them in.
autoComplete='off'
data-bwignore
data-1p-ignore
data-lpignore='true'
data-form-type='other'
disabled={disabled}
aria-label='Add people by email'
placeholder={emails.length === 0 ? 'Add people by email' : undefined}
Expand Down