Skip to content
Merged
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
10 changes: 7 additions & 3 deletions frontend/src/components/LandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export const LandingPage: React.FC<LandingPageProps> = ({ className }) => {
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();

if (isLoading || isSubmitted) {
return;
}

const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!email) {
setEmailError(t('hero.emailRequired'));
Expand Down Expand Up @@ -181,9 +185,9 @@ export const LandingPage: React.FC<LandingPageProps> = ({ className }) => {
)}
</div>

<button
type="submit"
disabled={isSubmitted || isLoading}
<button
type="submit"
aria-disabled={isSubmitted || isLoading}
aria-label={
isLoading
? 'Submitting...'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ describe('LandingPage Accessibility Tests', () => {

await waitFor(() => {
expect(emailInput).toBeDisabled();
expect(submitButton).toBeDisabled();
expect(submitButton).toHaveAttribute('aria-disabled', 'true');
});
});

Expand All @@ -326,13 +326,46 @@ describe('LandingPage Accessibility Tests', () => {

await userEvent.type(emailInput, 'test@example.com');
await userEvent.click(submitButton);
expect(submitButton).toBeDisabled();

expect(submitButton).toHaveAttribute('aria-disabled', 'true');
expect(emailInput).toBeDisabled();


resolvePromise!({ success: true, message: 'Subscribed' });
await waitFor(() => {
expect(submitButton).toHaveAttribute('aria-disabled', 'true');
});
});

it('does not trigger a second API call when the submit button is activated again while in-flight', async () => {
let resolvePromise: (value: { success: boolean; message: string }) => void;
const promise = new Promise<{ success: boolean; message: string }>((resolve) => {
resolvePromise = resolve;
});
(global.fetch as jest.Mock).mockReturnValueOnce(
promise.then(() => ({
ok: true,
text: async () => JSON.stringify({ success: true, message: 'Subscribed' }),
}))
);

render(<LandingPage />);

const emailInput = screen.getByLabelText(/email address/i);
const submitButton = screen.getByRole('button', { name: /get early access/i });

await userEvent.type(emailInput, 'test@example.com');
await userEvent.click(submitButton);

expect(global.fetch).toHaveBeenCalledTimes(1);

// Button remains focusable (aria-disabled, not disabled) — re-activating it
// while the request is in-flight must not fire a second request.
await userEvent.click(submitButton, { skipPointerEventsCheck: true });
expect(global.fetch).toHaveBeenCalledTimes(1);

resolvePromise!({ success: true, message: 'Subscribed' });
await waitFor(() => {
expect(submitButton).toBeDisabled();
expect(screen.getByRole('button', { name: /subscribed/i })).toBeInTheDocument();
});
});

Expand Down
20 changes: 20 additions & 0 deletions frontend/src/components/__tests__/LandingPage.keyboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,24 @@ describe('LandingPage handleKeyDown', () => {
screen.queryByRole('button', { name: /subscribed/i }),
).not.toBeInTheDocument();
});

it('keeps keyboard focus on the submit button through loading and success, instead of silently dropping it', async () => {
render(<LandingPage />);
const emailInput = screen.getByLabelText(/email address/i);
const submitButton = screen.getByRole('button', { name: /get early access/i });

await userEvent.type(emailInput, 'test@example.com');
await userEvent.tab();
expect(submitButton).toHaveFocus();

await userEvent.keyboard('{Enter}');

// While the request is in-flight the button is aria-disabled (not natively
// disabled), so it stays in the document and keeps focus.
expect(submitButton).toHaveAttribute('aria-disabled', 'true');
expect(submitButton).toHaveFocus();

await screen.findByRole('button', { name: /subscribed/i });
expect(submitButton).toHaveFocus();
});
});
7 changes: 4 additions & 3 deletions frontend/src/styles/landing.css
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,16 @@ header[role='banner'] {
.hero button[type='submit'] {
flex: 0 0 auto;
}
.hero button[type='submit']:hover:not(:disabled),
.hero button[type='submit']:hover:not(:disabled):not([aria-disabled='true']),
.retry-button:hover {
transform: translateY(-2px) scale(1.01);
box-shadow: var(--shadow-glow-gold), 0 14px 30px -12px rgba(139, 92, 246, 0.5);
}
.hero button[type='submit']:active:not(:disabled) {
.hero button[type='submit']:active:not(:disabled):not([aria-disabled='true']) {
transform: translateY(0) scale(0.98);
}
.hero button[type='submit']:disabled {
.hero button[type='submit']:disabled,
.hero button[type='submit'][aria-disabled='true'] {
cursor: not-allowed;
opacity: 0.6;
box-shadow: none;
Expand Down