mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-07 21:33:18 +01:00
fix cmd+enter submit shortcut on modals #1238
This commit is contained in:
@@ -1579,6 +1579,47 @@ test('test that project selection works in create modal', async ({ page, ctx })
|
|||||||
expect(createBody.data.project_id).not.toBeNull();
|
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 }) => {
|
test('test that tag selection works in create modal', async ({ page }) => {
|
||||||
await goToTimeOverview(page);
|
await goToTimeOverview(page);
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ useFocus(clientNameInput, { initialValue: true });
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span> Create Client </span>
|
<span> Create Client </span>
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ useFocus(clientNameInput, { initialValue: true });
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span> Update Client </span>
|
<span> Update Client </span>
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ const roleDescription = computed(() => {
|
|||||||
v-model:show="showOwnershipTransferConfirmModal"
|
v-model:show="showOwnershipTransferConfirmModal"
|
||||||
:member-name="member.name"
|
:member-name="member.name"
|
||||||
@submit="submit"></MemberOwnershipTransferConfirmModal>
|
@submit="submit"></MemberOwnershipTransferConfirmModal>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="saveWithChecks()">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span> Update Member </span>
|
<span> Update Member </span>
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ useFocus(clientNameInput, { initialValue: true });
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span> Invite Member </span>
|
<span> Invite Member </span>
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ async function submitBillableRate() {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span> Edit Project {{ props.originalProject.name }} </span>
|
<span> Edit Project {{ props.originalProject.name }} </span>
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ useFocus(projectNameInput, { initialValue: true });
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span>Add Project Member</span>
|
<span>Add Project Member</span>
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ useFocus(projectNameInput, { initialValue: true });
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span>Edit Project Member</span>
|
<span>Edit Project Member</span>
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ async function submit() {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span> Create Report </span>
|
<span> Create Report </span>
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ async function submit() {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span> Create Report </span>
|
<span> Create Report </span>
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ useFocus(tagNameInput, { initialValue: true });
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span> Update Tag </span>
|
<span> Update Tag </span>
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ useFocus(taskNameInput, { initialValue: true });
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span> Create Task </span>
|
<span> Create Task </span>
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ useFocus(taskNameInput, { initialValue: true });
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span> Update Task </span>
|
<span> Update Task </span>
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ async function submit() {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="emit('cancel')">
|
<DialogModal closeable :show="show" @close="emit('cancel')" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex items-center space-x-2">
|
<div class="flex items-center space-x-2">
|
||||||
<Coffee class="w-5 h-5 text-text-secondary" />
|
<Coffee class="w-5 h-5 text-text-secondary" />
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Modal from './Modal.vue';
|
import Modal from './Modal.vue';
|
||||||
|
|
||||||
const emit = defineEmits(['close']);
|
const emit = defineEmits(['close', 'submit']);
|
||||||
|
|
||||||
defineProps({
|
defineProps({
|
||||||
show: {
|
show: {
|
||||||
@@ -24,7 +24,12 @@ const close = () => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<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="px-4 lg:px-6 py-4">
|
||||||
<div class="text-lg font-medium text-text-primary" role="heading">
|
<div class="text-lg font-medium text-text-primary" role="heading">
|
||||||
<slot name="title" />
|
<slot name="title" />
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Dialog, DialogContent, DialogFooter } from './dialog/index';
|
import { Dialog, DialogContent, DialogFooter } from './dialog/index';
|
||||||
import { computed } from 'vue';
|
import { computed, nextTick } from 'vue';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
show: {
|
show: {
|
||||||
@@ -17,7 +17,7 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['close']);
|
const emit = defineEmits(['close', 'submit']);
|
||||||
|
|
||||||
const close = () => {
|
const close = () => {
|
||||||
if (props.closeable) {
|
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(() => {
|
const maxWidthClass = computed(() => {
|
||||||
return {
|
return {
|
||||||
sm: 'sm:max-w-sm',
|
sm: 'sm:max-w-sm',
|
||||||
@@ -39,7 +58,7 @@ const maxWidthClass = computed(() => {
|
|||||||
<template>
|
<template>
|
||||||
<Dialog :open="show" @update:open="close">
|
<Dialog :open="show" @update:open="close">
|
||||||
<DialogContent :class="maxWidthClass">
|
<DialogContent :class="maxWidthClass">
|
||||||
<div class="min-w-0">
|
<div class="min-w-0" @keydown.capture="onKeydownCapture">
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ const currentClientName = computed(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span> Create Project </span>
|
<span> Create Project </span>
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ useFocus(tagNameInput, { initialValue: true });
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span> Create Tags </span>
|
<span> Create Tags </span>
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ async function submit() {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex items-center space-x-2 text-amber-600 dark:text-amber-400">
|
<div class="flex items-center space-x-2 text-amber-600 dark:text-amber-400">
|
||||||
<Coffee class="w-5 h-5" />
|
<Coffee class="w-5 h-5" />
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ const billableProxy = computed({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span> Create manual time entry </span>
|
<span> Create manual time entry </span>
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ const typeProxy = computed({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span> Edit time entry </span>
|
<span> Edit time entry </span>
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ const showBreakWarning = computed(
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogModal closeable :show="show" @close="show = false">
|
<DialogModal closeable :show="show" @close="show = false" @submit="submit">
|
||||||
<template #title>
|
<template #title>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<span> Update {{ timeEntries.length }} time entries </span>
|
<span> Update {{ timeEntries.length }} time entries </span>
|
||||||
|
|||||||
Reference in New Issue
Block a user