fix cmd+enter submit shortcut on modals #1238

This commit is contained in:
Gregor Vostrak
2026-09-04 17:33:01 +02:00
parent 45c7377802
commit c1dce20902
22 changed files with 89 additions and 24 deletions

View File

@@ -1579,6 +1579,47 @@ test('test that project selection works in create modal', async ({ page, ctx })
expect(createBody.data.project_id).not.toBeNull();
});
test('test that ctrl+enter submits the create modal after selecting a project via keyboard', async ({
page,
ctx,
}) => {
// Regression test for https://github.com/solidtime-io/solidtime/issues/1238
const projectName = 'Keyboard Submit Project ' + Math.floor(1 + Math.random() * 10000);
await createProjectViaApi(ctx, { name: projectName });
await goToTimeOverview(page);
await page.getByRole('button', { name: 'Time entry actions' }).click();
await page.getByRole('menuitem', { name: 'Manual time entry' }).click();
await expect(page.getByRole('dialog')).toBeVisible();
// Fill the description, then move to the project dropdown and select a project purely via keyboard
const description = page.getByRole('dialog').getByRole('textbox', { name: 'Description' });
await description.fill('Keyboard submit test');
await description.press('Tab');
await expect(
page.getByRole('dialog').getByRole('button', { name: 'No Project' })
).toBeFocused();
await page.keyboard.press('Enter');
await page.getByTestId('client_dropdown_search').fill(projectName);
await expect(page.getByRole('option', { name: projectName })).toBeVisible();
await page.keyboard.press('Enter');
await expect(page.getByRole('dialog').getByRole('button', { name: projectName })).toBeVisible();
// Ctrl+Enter must submit even though focus is no longer on the description input
const [createResponse] = await Promise.all([
page.waitForResponse(
(response) => response.url().includes('/time-entries') && response.status() === 201
),
page.keyboard.press('Control+Enter'),
]);
const createBody = await createResponse.json();
expect(createBody.data.description).toBe('Keyboard submit test');
expect(createBody.data.project_id).not.toBeNull();
await expect(page.getByRole('dialog')).toBeHidden();
await expect(page.getByText('Keyboard submit test')).toBeVisible();
});
test('test that tag selection works in create modal', async ({ page }) => {
await goToTimeOverview(page);

View File

@@ -28,7 +28,7 @@ useFocus(clientNameInput, { initialValue: true });
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span> Create Client </span>

View File

@@ -30,7 +30,7 @@ useFocus(clientNameInput, { initialValue: true });
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span> Update Client </span>

View File

@@ -136,7 +136,7 @@ const roleDescription = computed(() => {
v-model:show="showOwnershipTransferConfirmModal"
:member-name="member.name"
@submit="submit"></MemberOwnershipTransferConfirmModal>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="saveWithChecks()">
<template #title>
<div class="flex space-x-2">
<span> Update Member </span>

View File

@@ -78,7 +78,7 @@ useFocus(clientNameInput, { initialValue: true });
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span> Invite Member </span>

View File

@@ -79,7 +79,7 @@ async function submitBillableRate() {
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span> Edit Project {{ props.originalProject.name }} </span>

View File

@@ -38,7 +38,7 @@ useFocus(projectNameInput, { initialValue: true });
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span>Add Project Member</span>

View File

@@ -63,7 +63,7 @@ useFocus(projectNameInput, { initialValue: true });
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span>Edit Project Member</span>

View File

@@ -79,7 +79,7 @@ async function submit() {
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span> Create Report </span>

View File

@@ -96,7 +96,7 @@ async function submit() {
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span> Create Report </span>

View File

@@ -36,7 +36,7 @@ useFocus(tagNameInput, { initialValue: true });
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span> Update Tag </span>

View File

@@ -50,7 +50,7 @@ useFocus(taskNameInput, { initialValue: true });
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span> Create Task </span>

View File

@@ -35,7 +35,7 @@ useFocus(taskNameInput, { initialValue: true });
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span> Update Task </span>

View File

@@ -179,7 +179,7 @@ async function submit() {
</script>
<template>
<DialogModal closeable :show="show" @close="emit('cancel')">
<DialogModal closeable :show="show" @close="emit('cancel')" @submit="submit">
<template #title>
<div class="flex items-center space-x-2">
<Coffee class="w-5 h-5 text-text-secondary" />

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import Modal from './Modal.vue';
const emit = defineEmits(['close']);
const emit = defineEmits(['close', 'submit']);
defineProps({
show: {
@@ -24,7 +24,12 @@ const close = () => {
</script>
<template>
<Modal :show="show" :max-width="maxWidth" :closeable="closeable" @close="close">
<Modal
:show="show"
:max-width="maxWidth"
:closeable="closeable"
@close="close"
@submit="emit('submit')">
<div class="px-4 lg:px-6 py-4">
<div class="text-lg font-medium text-text-primary" role="heading">
<slot name="title" />

View File

@@ -1,6 +1,6 @@
<script setup lang="ts">
import { Dialog, DialogContent, DialogFooter } from './dialog/index';
import { computed } from 'vue';
import { computed, nextTick } from 'vue';
const props = defineProps({
show: {
@@ -17,7 +17,7 @@ const props = defineProps({
},
});
const emit = defineEmits(['close']);
const emit = defineEmits(['close', 'submit']);
const close = () => {
if (props.closeable) {
@@ -25,6 +25,25 @@ const close = () => {
}
};
// Ctrl+Enter (Cmd+Enter on macOS) submits the modal from any focused element inside it.
// Handled in the capture phase so child elements (buttons, dropdown triggers, inputs with
// their own Enter handlers) never see the keystroke and cannot open or double-submit.
async function onKeydownCapture(event: KeyboardEvent) {
if (event.key !== 'Enter' || !(event.ctrlKey || event.metaKey) || event.isComposing) {
return;
}
event.preventDefault();
event.stopPropagation();
// Inputs like the time and duration fields commit their value on blur, so blur first
// and let the resulting model updates settle before submitting.
const active = document.activeElement;
if (active instanceof HTMLElement) {
active.blur();
}
await nextTick();
emit('submit');
}
const maxWidthClass = computed(() => {
return {
sm: 'sm:max-w-sm',
@@ -39,7 +58,7 @@ const maxWidthClass = computed(() => {
<template>
<Dialog :open="show" @update:open="close">
<DialogContent :class="maxWidthClass">
<div class="min-w-0">
<div class="min-w-0" @keydown.capture="onKeydownCapture">
<slot />
</div>

View File

@@ -72,7 +72,7 @@ const currentClientName = computed(() => {
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span> Create Project </span>

View File

@@ -30,7 +30,7 @@ useFocus(tagNameInput, { initialValue: true });
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span> Create Tags </span>

View File

@@ -78,7 +78,7 @@ async function submit() {
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex items-center space-x-2 text-amber-600 dark:text-amber-400">
<Coffee class="w-5 h-5" />

View File

@@ -126,7 +126,7 @@ const billableProxy = computed({
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span> Create manual time entry </span>

View File

@@ -164,7 +164,7 @@ const typeProxy = computed({
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span> Edit time entry </span>

View File

@@ -147,7 +147,7 @@ const showBreakWarning = computed(
</script>
<template>
<DialogModal closeable :show="show" @close="show = false">
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
<template #title>
<div class="flex space-x-2">
<span> Update {{ timeEntries.length }} time entries </span>