Show a task card's actions above tabs for notes, images and materials

The opened task card keeps its details and description at the top, then
the status, book hours, edit and remove actions, and below them tabs:
checklist and comments, images, and materials and machines. The tabs are
a project component (x-tabs) after the WAI-ARIA pattern, because
TallStackUI's tab ties its panels to missing ids and has no arrow keys.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-29 09:58:04 +02:00
co-authored by Claude Sonnet 5.5
parent 701f05780f
commit 87e38260dc
10 changed files with 173 additions and 11 deletions
@@ -272,7 +272,7 @@ new class extends Component
<div>
@if (($this->context?->usesStock ?? false) || $this->movements !== [])
<section aria-label="{{ __('inventory.task.list_of', ['title' => $taskTitle]) }}" class="space-y-3">
<section data-task-section aria-label="{{ __('inventory.task.list_of', ['title' => $taskTitle]) }}" class="space-y-3">
<h4 class="font-medium">{{ __('inventory.task.title') }}</h4>
<p id="task-{{ $taskId }}-materials-status" tabindex="-1" role="status" aria-live="polite" class="text-sm focus:outline-none">{{ $message }}</p>
@@ -470,14 +470,6 @@ new class extends Component
<p class="whitespace-pre-line">{{ $task->description }}</p>
@endif
<livewire:jobs::task-checklist :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'checklist-'.$task->id" />
<livewire:jobs::task-comments :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'comments-'.$task->id" />
<livewire:jobs::task-images :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'images-'.$task->id" />
<livewire:inventory::task-materials :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'materials-'.$task->id" />
<livewire:machines::task-machine :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'machine-'.$task->id" />
<div class="flex flex-wrap items-end gap-3">
@if ($canChangeStatus)
<div class="w-full sm:w-56">
@@ -530,6 +522,33 @@ new class extends Component
/>
@endif
</div>
<x-tabs
id="task-{{ $task->id }}-tabs"
:label="__('jobs.tasks.tabs.label', ['title' => $task->title])"
:tabs="[
'notes' => __('jobs.tasks.tabs.notes'),
'images' => __('jobs.tasks.tabs.images'),
'materials' => __('jobs.tasks.tabs.materials'),
]"
class="pt-2"
>
<x-tabs.panel tabs-id="task-{{ $task->id }}-tabs" name="notes" class="space-y-3">
<livewire:jobs::task-checklist :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'checklist-'.$task->id" />
<livewire:jobs::task-comments :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'comments-'.$task->id" />
</x-tabs.panel>
<x-tabs.panel tabs-id="task-{{ $task->id }}-tabs" name="images">
<livewire:jobs::task-images :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'images-'.$task->id" />
</x-tabs.panel>
{{-- The sections mark themselves data-task-section when they have something to show. --}}
<x-tabs.panel tabs-id="task-{{ $task->id }}-tabs" name="materials" class="group space-y-3">
<livewire:inventory::task-materials :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'materials-'.$task->id" />
<livewire:machines::task-machine :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'machine-'.$task->id" />
<p class="group-has-[[data-task-section]]:hidden">{{ __('jobs.tasks.tabs.no_materials') }}</p>
</x-tabs.panel>
</x-tabs>
</div>
</article>
</li>
@@ -150,7 +150,7 @@ new class extends Component
<div>
@if ($this->canPlan() || $this->row !== null)
<section aria-label="{{ __('machines.task.list_of', ['title' => $taskTitle]) }}" class="space-y-2">
<section data-task-section aria-label="{{ __('machines.task.list_of', ['title' => $taskTitle]) }}" class="space-y-2">
<h4 class="font-medium">{{ __('machines.task.title') }}</h4>
<p id="task-{{ $taskId }}-machine-status" tabindex="-1" role="status" aria-live="polite" class="text-sm focus:outline-none">{{ $message }}</p>
+7
View File
@@ -148,6 +148,13 @@ return [
'not_author' => 'You can edit and remove only your own comments.',
],
],
'tabs' => [
'label' => 'Sections of task :title',
'notes' => 'Checklist and comments',
'images' => 'Images',
'materials' => 'Materials and machines',
'no_materials' => 'This task has no materials or machines.',
],
'images' => [
'title' => 'Images',
'list_of' => 'Images: :title',
+7
View File
@@ -148,6 +148,13 @@ return [
'not_author' => 'Voit muokata ja poistaa vain omia kommenttejasi.',
],
],
'tabs' => [
'label' => 'Tehtävän :title osiot',
'notes' => 'Tarkistuslista ja kommentit',
'images' => 'Kuvat',
'materials' => 'Materiaali ja koneet',
'no_materials' => 'Tällä tehtävällä ei ole materiaaleja eikä koneita.',
],
'images' => [
'title' => 'Kuvat',
'list_of' => 'Kuvat: :title',
+66
View File
@@ -0,0 +1,66 @@
{{--
Tabs after the WAI-ARIA tabs pattern, because TallStackUI's <x-tab> ties its
panels to ids that do not exist and has no arrow keys. Only the selected tab
is in the tab order; arrow keys, Home and End move between the tabs and
select them. Panels are <x-tabs.panel> children with the same id.
$tabs: ['key' => 'title', ...] in display order.
--}}
@props([
'id',
'label',
'tabs',
'selected' => null,
])
@php
$selected ??= array_key_first($tabs);
@endphp
<div
{{ $attributes->class('space-y-3') }}
x-data="{
selected: @js($selected),
select(key) {
this.selected = key;
this.$nextTick(() => document.getElementById(@js($id) + '-tab-' + key)?.focus());
},
move(event) {
const keys = @js(array_keys($tabs));
const index = keys.indexOf(this.selected);
const next = { ArrowRight: index + 1, ArrowLeft: index - 1, Home: 0, End: keys.length - 1 }[event.key];
if (next === undefined) {
return;
}
event.preventDefault();
this.select(keys[(next + keys.length) % keys.length]);
},
}"
>
<div
role="tablist"
aria-label="{{ $label }}"
x-on:keydown="move($event)"
class="flex flex-wrap gap-x-4 gap-y-1 border-b border-zinc-200 dark:border-zinc-700"
>
@foreach ($tabs as $key => $title)
<button
type="button"
role="tab"
id="{{ $id }}-tab-{{ $key }}"
aria-controls="{{ $id }}-panel-{{ $key }}"
aria-selected="{{ $key === $selected ? 'true' : 'false' }}"
tabindex="{{ $key === $selected ? '0' : '-1' }}"
x-bind:aria-selected="(selected === @js($key)).toString()"
x-bind:tabindex="selected === @js($key) ? 0 : -1"
x-on:click="select(@js($key))"
x-bind:class="selected === @js($key)
? 'border-primary-700 font-semibold text-zinc-900 dark:border-primary-400 dark:text-white'
: 'border-transparent text-zinc-700 hover:border-zinc-400 dark:text-zinc-300'"
class="-mb-px min-h-6 rounded-t-md border-b-2 px-1 py-2 text-left text-sm focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:focus-visible:outline-blue-400"
>{{ $title }}</button>
@endforeach
</div>
{{ $slot }}
</div>
@@ -0,0 +1,21 @@
{{--
One panel of <x-tabs>: $tabsId is the id given to <x-tabs>, $name the key of
its tab. The panel is always rendered and only hidden, so Livewire components
in it keep their state.
--}}
@props([
'tabsId',
'name',
])
<div
{{ $attributes->class('rounded-md focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:focus-visible:outline-blue-400') }}
role="tabpanel"
id="{{ $tabsId }}-panel-{{ $name }}"
aria-labelledby="{{ $tabsId }}-tab-{{ $name }}"
tabindex="0"
x-show="selected === @js($name)"
x-cloak
>
{{ $slot }}
</div>
+2 -1
View File
@@ -82,7 +82,8 @@ it('records material on a task card with the keyboard and without accessibility
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee(__('inventory.task.title'))
$visit->click('#task-'.$task->id.'-tabs-tab-materials')
->assertSee(__('inventory.task.title'))
->fill('#task-'.$task->id.'-material-search', 'valoku')
->assertSee('1 osuma')
->click('[wire\:click="selectItem('.$this->item->id.')"]')
+37
View File
@@ -216,6 +216,42 @@ it('changes a task status and removes a task with the keyboard', function () {
->assertScript('document.activeElement.id', 'tasks-heading');
});
it('puts the task actions above the tabs and moves between the tabs with the arrow keys', function (string $device, string $colorScheme) {
$this->job->update(['status' => 'order']);
$workType = WorkTypeModel::query()->where('name', 'videokuvaus')->sole();
$task = TaskModel::factory()
->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Kuvauspäivä']);
$tabs = 'task-'.$task->id.'-tabs';
$visit = visit(route('jobs.show', $this->job->id));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->click('#task-toggle-'.$task->id)
->assertScript("!! (document.getElementById('task-status-{$task->id}').compareDocumentPosition(document.getElementById('{$tabs}-tab-notes')) & Node.DOCUMENT_POSITION_FOLLOWING)", true)
->assertAttribute('#'.$tabs.'-tab-notes', 'aria-selected', 'true')
->assertVisible('#checklist-new-'.$task->id)
->assertMissing('#'.$tabs.'-panel-images')
->keys('#'.$tabs.'-tab-notes', 'ArrowRight')
->assertScript('document.activeElement.id', $tabs.'-tab-images')
->assertAttribute('#'.$tabs.'-tab-images', 'aria-selected', 'true')
->assertAttribute('#'.$tabs.'-tab-notes', 'tabindex', '-1')
->assertVisible('#'.$tabs.'-panel-images')
->assertMissing('#'.$tabs.'-panel-notes')
->keys('#'.$tabs.'-tab-images', 'End')
->assertScript('document.activeElement.id', $tabs.'-tab-materials')
->assertSee('Tällä tehtävällä ei ole materiaaleja eikä koneita.')
->keys('#'.$tabs.'-tab-materials', 'ArrowRight')
->assertScript('document.activeElement.id', $tabs.'-tab-notes')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('shows task cards collapsed, opens several at once and expands or collapses them all', function () {
$this->job->update(['status' => 'order']);
$workType = WorkTypeModel::query()->where('name', 'videokuvaus')->sole();
@@ -348,6 +384,7 @@ it('recaptions and removes a task image with the keyboard', function () {
$page = visit(route('jobs.show', $this->job->id))
->click('#task-toggle-'.$task->id)
->click('#task-'.$task->id.'-tabs-tab-images')
->assertVisible('img[alt="Valot paikallaan"]')
->assertScript("document.querySelector('img[alt=\"Valot paikallaan\"]').naturalWidth > 0", true)
->assertSeeIn('#task-'.$task->id.'-title + dl', 'Kuvat:');
@@ -53,6 +53,10 @@ it('has no accessibility issues on the machine pages', function (string $page, s
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
if ($page === 'job') {
$visit->click('#task-'.$this->task->id.'-tabs-tab-materials');
}
$visit->assertSee($page === 'form' ? __('machines.form.edit_title') : 'Suurkuvatulostin')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);