Compare commits

..

3 Commits

Author SHA1 Message Date
Gregor Vostrak
104d9ee3c2 fix e2e submit focus test behaviour 2026-09-22 12:57:35 +02:00
Gregor Vostrak
c1e2ccb495 move project reset button into mass update modal and fix
TimeTrackerProjectTaskDropdown trigger focus
2026-09-16 17:51:10 +02:00
Gregor Vostrak
c1dce20902 fix cmd+enter submit shortcut on modals #1238 2026-09-04 17:33:01 +02:00
39 changed files with 888 additions and 1024 deletions

View File

@@ -9,9 +9,9 @@
"ext-zip": "*", "ext-zip": "*",
"brick/money": "^0.10.0", "brick/money": "^0.10.0",
"datomatic/laravel-enum-helper": "^2.0.0", "datomatic/laravel-enum-helper": "^2.0.0",
"dedoc/scramble": "^0.13.43", "dedoc/scramble": "^0.12.2",
"filament/filament": "^3.2", "filament/filament": "^3.2",
"flowframe/laravel-trend": "^0.5.0", "flowframe/laravel-trend": "^0.4.0",
"gotenberg/gotenberg-php": "^2.8", "gotenberg/gotenberg-php": "^2.8",
"guzzlehttp/guzzle": "^7.2", "guzzlehttp/guzzle": "^7.2",
"inertiajs/inertia-laravel": "^2.0.3", "inertiajs/inertia-laravel": "^2.0.3",

1457
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1579,6 +1579,57 @@ 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();
// The menu that opened the modal animates out and only then hands focus back to its
// own trigger.
await expect(page.locator('[role="menu"]')).toHaveCount(0);
// 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');
const projectTrigger = page.getByRole('dialog').getByRole('button', { name: projectName });
await expect(projectTrigger).toBeVisible();
// The trigger label updates on the next tick, but the dropdown keeps focus until its
// exit animation has finished and reka-ui hands focus back to the trigger.
await expect(projectTrigger).toBeFocused();
// 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();
const newTimeEntry = page.locator('[data-testid="time_entry_row"]').first();
await expect(newTimeEntry.getByTestId('time_entry_description').first()).toHaveValue(
'Keyboard submit test'
);
});
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);

View File

@@ -9,6 +9,6 @@
}, },
"Invoicing": { "Invoicing": {
"repository": "solidtime-io/extension-invoicing", "repository": "solidtime-io/extension-invoicing",
"ref": "v0.0.6" "ref": "v0.0.5"
} }
} }

2
package-lock.json generated
View File

@@ -8564,7 +8564,7 @@
}, },
"resources/js/packages/ui": { "resources/js/packages/ui": {
"name": "@solidtime/ui", "name": "@solidtime/ui",
"version": "0.0.23", "version": "0.0.22",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"devDependencies": { "devDependencies": {
"@types/chroma-js": "^3.1.2", "@types/chroma-js": "^3.1.2",

View File

@@ -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>

View File

@@ -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>

View File

@@ -7,7 +7,7 @@ import { type Client } from '@/packages/api/src';
import ClientTableRow from '@/Components/Common/Client/ClientTableRow.vue'; import ClientTableRow from '@/Components/Common/Client/ClientTableRow.vue';
import ClientCreateModal from '@/Components/Common/Client/ClientCreateModal.vue'; import ClientCreateModal from '@/Components/Common/Client/ClientCreateModal.vue';
import ClientTableHeading from '@/Components/Common/Client/ClientTableHeading.vue'; import ClientTableHeading from '@/Components/Common/Client/ClientTableHeading.vue';
import Pagination from '@/packages/ui/src/Pagination.vue'; import Pagination from '@/Components/Common/Pagination.vue';
import { canCreateClients } from '@/utils/permissions'; import { canCreateClients } from '@/utils/permissions';
import { useProjectsQuery } from '@/utils/useProjectsQuery'; import { useProjectsQuery } from '@/utils/useProjectsQuery';
import { import {

View File

@@ -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>

View File

@@ -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>

View File

@@ -16,8 +16,8 @@ import {
ChevronRightIcon, ChevronRightIcon,
EllipsisHorizontalIcon, EllipsisHorizontalIcon,
} from '@heroicons/vue/20/solid'; } from '@heroicons/vue/20/solid';
import { buttonVariants } from './Buttons/index'; import { buttonVariants } from '@/packages/ui/src';
import { cn } from './utils/cn'; import { cn } from '@/lib/utils';
import { computed, watch } from 'vue'; import { computed, watch } from 'vue';
const page = defineModel<number>('page', { default: 1 }); const page = defineModel<number>('page', { default: 1 });

View File

@@ -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>

View File

@@ -6,7 +6,7 @@ import { computed, ref, watch } from 'vue';
import ProjectCreateModal from '@/packages/ui/src/Project/ProjectCreateModal.vue'; import ProjectCreateModal from '@/packages/ui/src/Project/ProjectCreateModal.vue';
import ProjectTableHeading from '@/Components/Common/Project/ProjectTableHeading.vue'; import ProjectTableHeading from '@/Components/Common/Project/ProjectTableHeading.vue';
import ProjectTableRow from '@/Components/Common/Project/ProjectTableRow.vue'; import ProjectTableRow from '@/Components/Common/Project/ProjectTableRow.vue';
import Pagination from '@/packages/ui/src/Pagination.vue'; import Pagination from '@/Components/Common/Pagination.vue';
import LoadingSpinner from '@/packages/ui/src/LoadingSpinner.vue'; import LoadingSpinner from '@/packages/ui/src/LoadingSpinner.vue';
export type SortColumn = export type SortColumn =

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -63,7 +63,7 @@ const max = computed(() => {
}); });
const backgroundColor = useCssVariable('--theme-color-card-background'); const backgroundColor = useCssVariable('--theme-color-card-background');
const borderColor = useCssVariable('--color-border-secondary'); const borderColor = useCssVariable('--color-border');
const labelColor = useCssVariable('--color-text-secondary'); const labelColor = useCssVariable('--color-text-secondary');
const chartColorRaw = useCssVariable('--theme-color-chart'); const chartColorRaw = useCssVariable('--theme-color-chart');

View File

@@ -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" />

View File

@@ -9,7 +9,7 @@ import {
ArrowDownTrayIcon, ArrowDownTrayIcon,
LockClosedIcon, LockClosedIcon,
} from '@heroicons/vue/20/solid'; } from '@heroicons/vue/20/solid';
import Pagination from '@/packages/ui/src/Pagination.vue'; import Pagination from '@/Components/Common/Pagination.vue';
import { import {
DropdownMenu, DropdownMenu,
DropdownMenuContent, DropdownMenuContent,

View File

@@ -1,6 +1,6 @@
{ {
"name": "@solidtime/ui", "name": "@solidtime/ui",
"version": "0.0.23", "version": "0.0.22",
"description": "Package containing the solidtime ui components", "description": "Package containing the solidtime ui components",
"main": "./dist/solidtime-ui-lib.umd.cjs", "main": "./dist/solidtime-ui-lib.umd.cjs",
"module": "./dist/solidtime-ui-lib.js", "module": "./dist/solidtime-ui-lib.js",

View File

@@ -11,7 +11,6 @@ import {
CommandShortcut, CommandShortcut,
} from '../command'; } from '../command';
import { cn } from '../utils/cn'; import { cn } from '../utils/cn';
import { useDialogFocusRestore } from '../utils/useDialogFocusRestore';
import type { import type {
CommandPaletteCommand, CommandPaletteCommand,
CommandPaletteGroup, CommandPaletteGroup,
@@ -37,8 +36,6 @@ const emit = defineEmits<{
select: [command: CommandPaletteCommand | EntitySearchResult]; select: [command: CommandPaletteCommand | EntitySearchResult];
}>(); }>();
const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
// Non-empty groups for rendering // Non-empty groups for rendering
const nonEmptyGroups = computed(() => props.groups.filter((g) => g.commands.length > 0)); const nonEmptyGroups = computed(() => props.groups.filter((g) => g.commands.length > 0));
@@ -74,9 +71,7 @@ watch(open, (isOpen) => {
) )
"> ">
<DialogContent <DialogContent
class="pointer-events-auto bg-default-background w-full max-w-lg border border-border-tertiary shadow-lg sm:rounded-lg outline-none overflow-hidden p-0 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95" class="pointer-events-auto bg-default-background w-full max-w-lg border border-border-tertiary shadow-lg sm:rounded-lg outline-none overflow-hidden p-0 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95">
@open-auto-focus="onOpenAutoFocus"
@close-auto-focus="onCloseAutoFocus">
<CommandRoot <CommandRoot
v-model:search-term="searchTerm" v-model:search-term="searchTerm"
class="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5"> class="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">

View File

@@ -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" />

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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" />

View File

@@ -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>

View File

@@ -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>

View File

@@ -16,6 +16,7 @@ import {
} from '@/packages/api/src'; } from '@/packages/api/src';
import { Checkbox } from '@/packages/ui/src'; import { Checkbox } from '@/packages/ui/src';
import { TagIcon, ExclamationTriangleIcon } from '@heroicons/vue/20/solid'; import { TagIcon, ExclamationTriangleIcon } from '@heroicons/vue/20/solid';
import { XMarkIcon } from '@heroicons/vue/16/solid';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '..'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '..';
import { Button } from '@/packages/ui/src/Buttons'; import { Button } from '@/packages/ui/src/Buttons';
import TagDropdown from '@/packages/ui/src/Tag/TagDropdown.vue'; import TagDropdown from '@/packages/ui/src/Tag/TagDropdown.vue';
@@ -60,6 +61,13 @@ const projectId = ref<string | null>(null);
const billable = ref<boolean | undefined>(undefined); const billable = ref<boolean | undefined>(undefined);
const selectedTags = ref<string[]>([]); const selectedTags = ref<string[]>([]);
// Clearing the project puts both fields back to "leave unchanged", the same state the form
// returns to after a successful submit.
function resetProject() {
projectId.value = null;
taskId.value = undefined;
}
const timeEntryBillable = computed({ const timeEntryBillable = computed({
get: () => { get: () => {
if (billable.value === undefined) { if (billable.value === undefined) {
@@ -147,7 +155,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>
@@ -182,42 +190,59 @@ const showBreakWarning = computed(
</Field> </Field>
<Field> <Field>
<FieldLabel for="project">Project</FieldLabel> <FieldLabel for="project">Project</FieldLabel>
<TimeTrackerProjectTaskDropdown <div class="flex items-center gap-1 min-w-0">
v-model:project="projectId" <!-- the dropdown declares its own `class` prop, which goes to the
v-model:task="taskId" trigger button, so the growing has to happen on a wrapper -->
variant="input" <div class="flex-1 min-w-0">
align="start" <TimeTrackerProjectTaskDropdown
size="default" v-model:project="projectId"
:clients v-model:task="taskId"
:create-project variant="input"
:create-client align="start"
:currency="currency" size="default"
:organization-billable-rate="organizationBillableRate" :clients
:can-create-project :create-project
empty-placeholder="Select project..." :create-client
allow-reset :currency="currency"
:enable-estimated-time :organization-billable-rate="organizationBillableRate"
:projects="projects" :can-create-project
:tasks="tasks"></TimeTrackerProjectTaskDropdown> empty-placeholder="Select project..."
:enable-estimated-time
:projects="projects"
:tasks="tasks"></TimeTrackerProjectTaskDropdown>
</div>
<button
v-if="projectId !== null"
type="button"
data-testid="project_reset_button"
class="p-1 rounded hover:bg-quaternary text-text-tertiary hover:text-text-primary"
@click="resetProject">
<XMarkIcon class="w-4 h-4" />
</button>
</div>
</Field> </Field>
<Field> <Field>
<FieldLabel>Tag</FieldLabel> <FieldLabel>Tag</FieldLabel>
<div class="flex space-x-5"> <div class="flex items-center space-x-5">
<TagDropdown <!-- the dropdown root is `min-w-0`, so as a flex item it would shrink
v-model="selectedTags" below its trigger and let the button overflow into the checkbox -->
:create-tag <div class="shrink-0">
:tags="tags" <TagDropdown
:show-no-tag-option="false"> v-model="selectedTags"
<template #trigger> :create-tag
<Button variant="input" :disabled="removeAllTags"> :tags="tags"
<TagIcon class="h-4 text-icon-default" /> :show-no-tag-option="false">
<span v-if="selectedTags.length > 0"> <template #trigger>
Set {{ selectedTags.length }} tags <Button variant="input" :disabled="removeAllTags">
</span> <TagIcon class="h-4 text-icon-default" />
<span v-else>Select Tags...</span> <span v-if="selectedTags.length > 0">
</Button> Set {{ selectedTags.length }} tags
</template> </span>
</TagDropdown> <span v-else>Select Tags...</span>
</Button>
</template>
</TagDropdown>
</div>
<Field orientation="horizontal"> <Field orientation="horizontal">
<Checkbox id="no_tags" v-model:checked="removeAllTags"></Checkbox> <Checkbox id="no_tags" v-model:checked="removeAllTags"></Checkbox>
<FieldLabel for="no_tags">Remove all tags</FieldLabel> <FieldLabel for="no_tags">Remove all tags</FieldLabel>

View File

@@ -12,7 +12,7 @@ import type {
Client, Client,
} from '@/packages/api/src'; } from '@/packages/api/src';
import { PlusCircleIcon, MinusIcon, XMarkIcon } from '@heroicons/vue/16/solid'; import { PlusCircleIcon, MinusIcon } from '@heroicons/vue/16/solid';
import ProjectCreateModal from '@/packages/ui/src/Project/ProjectCreateModal.vue'; import ProjectCreateModal from '@/packages/ui/src/Project/ProjectCreateModal.vue';
import { twMerge } from 'tailwind-merge'; import { twMerge } from 'tailwind-merge';
import { Button } from '@/packages/ui/src/Buttons'; import { Button } from '@/packages/ui/src/Buttons';
@@ -58,7 +58,6 @@ const props = withDefaults(
createClient: (client: CreateClientBody) => Promise<Client | undefined>; createClient: (client: CreateClientBody) => Promise<Client | undefined>;
currency: string; currency: string;
emptyPlaceholder?: string; emptyPlaceholder?: string;
allowReset?: boolean;
noProjectValue?: string | null; noProjectValue?: string | null;
enableEstimatedTime: boolean; enableEstimatedTime: boolean;
organizationBillableRate: number | null; organizationBillableRate: number | null;
@@ -70,7 +69,6 @@ const props = withDefaults(
}>(), }>(),
{ {
emptyPlaceholder: 'No Project', emptyPlaceholder: 'No Project',
allowReset: false,
noProjectValue: NO_PROJECT_ID, noProjectValue: NO_PROJECT_ID,
variant: 'ghost', variant: 'ghost',
align: 'center', align: 'center',
@@ -558,12 +556,6 @@ function selectProject(projectId: string) {
emit('changed', project.value, task.value); emit('changed', project.value, task.value);
} }
function resetProject() {
project.value = null;
task.value = null;
emit('changed', project.value, task.value);
}
const showCreateProject = ref(false); const showCreateProject = ref(false);
</script> </script>
@@ -571,40 +563,28 @@ const showCreateProject = ref(false);
<Dropdown v-model="open" :close-on-content-click="false" :align="props.align"> <Dropdown v-model="open" :close-on-content-click="false" :align="props.align">
<template #trigger> <template #trigger>
<slot name="trigger"> <slot name="trigger">
<div class="flex items-center gap-1"> <Button
<Button :variant="props.variant"
:variant="props.variant" :size="props.size"
:size="props.size" :class="twMerge('w-full justify-start overflow-hidden', props.class)">
:class="twMerge('w-full justify-start overflow-hidden', props.class)"> <div
<div class="w-2.5 h-2.5 rounded-full shrink-0"
class="w-2.5 h-2.5 rounded-full shrink-0" :style="{ backgroundColor: selectedProjectColor }"></div>
:style="{ backgroundColor: selectedProjectColor }"></div> <span class="truncate shrink-[1] text-text-primary">{{
<span class="truncate shrink-[1] text-text-primary">{{ selectedProjectName
selectedProjectName }}</span>
}}</span> <template v-if="currentTask">
<template v-if="currentTask"> <ChevronRightIcon class="!size-3 text-text-primary shrink-0 -mx-1" />
<ChevronRightIcon class="!size-3 text-text-primary shrink-0 -mx-1" /> <span class="truncate shrink-[100]">{{ currentTask.name }}</span>
<span class="truncate shrink-[100]">{{ currentTask.name }}</span> </template>
</template> <template v-if="selectedClientName">
<template v-if="selectedClientName"> <span class="dark:text-text-tertiary text-text-quaternary shrink-0">•</span>
<span class="dark:text-text-tertiary text-text-quaternary shrink-0" <span
>•</span class="truncate shrink-[200] dark:text-text-tertiary text-text-quaternary"
> >{{ selectedClientName }}</span
<span >
class="truncate shrink-[200] dark:text-text-tertiary text-text-quaternary" </template>
>{{ selectedClientName }}</span </Button>
>
</template>
</Button>
<button
v-if="allowReset && project !== null"
type="button"
data-testid="project_reset_button"
class="p-1 rounded hover:bg-quaternary text-text-tertiary hover:text-text-primary"
@click.stop="resetProject">
<XMarkIcon class="w-4 h-4" />
</button>
</div>
</slot> </slot>
</template> </template>
<template #content> <template #content>

View File

@@ -1,6 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { cn } from '../utils/cn'; import { cn } from '../utils/cn';
import { useDialogFocusRestore } from '../utils/useDialogFocusRestore';
import { import {
DialogContent, DialogContent,
type DialogContentEmits, type DialogContentEmits,
@@ -21,10 +20,6 @@ const delegatedProps = computed(() => {
}); });
const forwarded = useForwardPropsEmits(delegatedProps, emits); const forwarded = useForwardPropsEmits(delegatedProps, emits);
// Forwarded consumer listeners run first, so a consumer can still take over
// by calling preventDefault() on close-auto-focus.
const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
</script> </script>
<template> <template>
@@ -41,9 +36,7 @@ const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
'my-3 md:my-14 xl:my-24 bg-default-background grid w-full max-w-lg border border-border-tertiary shadow-lg duration-200 rounded-lg outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95', 'my-3 md:my-14 xl:my-24 bg-default-background grid w-full max-w-lg border border-border-tertiary shadow-lg duration-200 rounded-lg outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',
props.class props.class
) )
" ">
@open-auto-focus="onOpenAutoFocus"
@close-auto-focus="onCloseAutoFocus">
<slot /> <slot />
</DialogContent> </DialogContent>
</div> </div>

View File

@@ -1,6 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { cn } from '../utils/cn'; import { cn } from '../utils/cn';
import { useDialogFocusRestore } from '../utils/useDialogFocusRestore';
import { X } from '@lucide/vue'; import { X } from '@lucide/vue';
import { import {
DialogClose, DialogClose,
@@ -23,10 +22,6 @@ const delegatedProps = computed(() => {
}); });
const forwarded = useForwardPropsEmits(delegatedProps, emits); const forwarded = useForwardPropsEmits(delegatedProps, emits);
// Forwarded consumer listeners run first, so a consumer can still take over
// by calling preventDefault() on close-auto-focus.
const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
</script> </script>
<template> <template>
@@ -41,8 +36,6 @@ const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
) )
" "
v-bind="forwarded" v-bind="forwarded"
@open-auto-focus="onOpenAutoFocus"
@close-auto-focus="onCloseAutoFocus"
@pointer-down-outside=" @pointer-down-outside="
(event) => { (event) => {
const originalEvent = event.detail.originalEvent; const originalEvent = event.detail.originalEvent;

View File

@@ -32,7 +32,6 @@ import InputLabel from './Input/InputLabel.vue';
import TextInput from './Input/TextInput.vue'; import TextInput from './Input/TextInput.vue';
import LoadingSpinner from './LoadingSpinner.vue'; import LoadingSpinner from './LoadingSpinner.vue';
import Modal from './Modal.vue'; import Modal from './Modal.vue';
import Pagination from './Pagination.vue';
import ProjectBadge from './Project/ProjectBadge.vue'; import ProjectBadge from './Project/ProjectBadge.vue';
import TimeEntryCreateModal from './TimeEntry/TimeEntryCreateModal.vue'; import TimeEntryCreateModal from './TimeEntry/TimeEntryCreateModal.vue';
import TimeEntryEditModal from './TimeEntry/TimeEntryEditModal.vue'; import TimeEntryEditModal from './TimeEntry/TimeEntryEditModal.vue';
@@ -258,7 +257,6 @@ export {
NumberFieldDecrement, NumberFieldDecrement,
NumberFieldIncrement, NumberFieldIncrement,
NumberFieldInput, NumberFieldInput,
Pagination,
Popover, Popover,
PopoverAnchor, PopoverAnchor,
PopoverContent, PopoverContent,

View File

@@ -1,87 +0,0 @@
import { describe, expect, it, vi } from 'vitest';
import { useDialogFocusRestore } from './useDialogFocusRestore';
function closeEvent() {
return new CustomEvent('focusScope.autoFocusOnUnmount', { cancelable: true });
}
describe('useDialogFocusRestore', () => {
it('restores focus to the element focused when the dialog opened', () => {
vi.useFakeTimers();
const button = document.createElement('button');
document.body.appendChild(button);
button.focus();
const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
onOpenAutoFocus();
button.blur();
const event = closeEvent();
onCloseAutoFocus(event);
expect(event.defaultPrevented).toBe(true);
vi.runAllTimers();
expect(document.activeElement).toBe(button);
button.remove();
vi.useRealTimers();
});
it('focuses nothing when the dialog was opened with nothing focused', () => {
vi.useFakeTimers();
const stale = document.createElement('button');
document.body.appendChild(stale);
const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
// First open from the button, then close
stale.focus();
onOpenAutoFocus();
onCloseAutoFocus(closeEvent());
vi.runAllTimers();
stale.blur();
// Second open from the body must not refocus the stale button
onOpenAutoFocus();
const event = closeEvent();
onCloseAutoFocus(event);
expect(event.defaultPrevented).toBe(true);
vi.runAllTimers();
expect(document.activeElement).toBe(document.body);
stale.remove();
vi.useRealTimers();
});
it('does not restore focus to an element that was removed', () => {
vi.useFakeTimers();
const button = document.createElement('button');
document.body.appendChild(button);
button.focus();
const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
onOpenAutoFocus();
button.remove();
onCloseAutoFocus(closeEvent());
vi.runAllTimers();
expect(document.activeElement).toBe(document.body);
vi.useRealTimers();
});
it('leaves control to a consumer that already prevented the event', () => {
vi.useFakeTimers();
const button = document.createElement('button');
document.body.appendChild(button);
button.focus();
const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
onOpenAutoFocus();
button.blur();
const event = closeEvent();
event.preventDefault();
onCloseAutoFocus(event);
vi.runAllTimers();
expect(document.activeElement).toBe(document.body);
button.remove();
vi.useRealTimers();
});
});

View File

@@ -1,41 +0,0 @@
/**
* Restores focus to the element that was focused when a dialog opened.
*
* reka-ui remembers the active element at content mount as the dialog's
* "trigger" (only when it is not the body) and refocuses it on every close,
* but it never clears that value. A dialog opened while nothing is focused
* (e.g. the command palette via Cmd+K from the body) therefore refocuses
* whatever triggered a *previous* open. Bind these handlers to
* `DialogContent`'s `open-auto-focus` / `close-auto-focus` events to restore
* exactly the previously focused element, or nothing.
*
* A consumer handler that already called `preventDefault()` on
* `close-auto-focus` keeps control; this composable then does nothing.
*/
export function useDialogFocusRestore() {
let previouslyFocused: HTMLElement | null = null;
function onOpenAutoFocus() {
const active = document.activeElement;
previouslyFocused =
active instanceof HTMLElement && active !== document.body ? active : null;
}
function onCloseAutoFocus(event: Event) {
const target = previouslyFocused;
previouslyFocused = null;
if (event.defaultPrevented) {
return;
}
// Prevents both FocusScope's default restore and reka-ui's trigger refocus
event.preventDefault();
// Same tick reka-ui uses, so the dialog content is fully gone first
setTimeout(() => {
if (target?.isConnected) {
target.focus({ preventScroll: true });
}
}, 0);
}
return { onOpenAutoFocus, onCloseAutoFocus };
}