Keep the header at the top of the window on wider screens

The signed-in header is sticky from the md breakpoint up, so only the
page content scrolls; on phones and at high zoom it still scrolls with
the page, where a wrapped sticky header would take too much of the view.
A small layout script sets scroll-padding-top to the header's height
while it is sticky, so focused elements, anchors and the skip link
target land below it (WCAG 2.4.11).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-25 07:18:55 +02:00
co-authored by Claude Opus 5.5
parent 45dbb04344
commit 60cab4b871
3 changed files with 78 additions and 1 deletions
+40
View File
@@ -0,0 +1,40 @@
<?php
use App\Models\User;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$user = User::factory()->management()->create();
$this->actingAs($user);
$this->job = CustomerJobModel::factory()->create([
'customer_id' => CustomerModel::factory()->create()->id,
'responsible_user_id' => $user->id,
'status' => 'order',
'instructions' => str_repeat("Ohjeen rivi.\n", 60),
]);
$workType = WorkTypeModel::query()->where('name', 'videokuvaus')->sole();
TaskModel::factory()->count(12)->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id]);
});
it('keeps the header at the top of the window and focus below it on desktop', function () {
visit(route('jobs.show', $this->job->id))->on()->desktop()
->assertScript('getComputedStyle(document.getElementById("app-header")).position', 'sticky')
->assertScript('getComputedStyle(document.documentElement).scrollPaddingTop === document.getElementById("app-header").offsetHeight + "px"', true)
->assertScript('window.scrollTo(0, document.body.scrollHeight); window.scrollY > 0', true)
->assertScript('document.getElementById("app-header").getBoundingClientRect().top', 0)
// From the bottom of the page, focusing the tasks heading scrolls it back up: it must land below the header.
->assertScript('document.getElementById("tasks-heading").getBoundingClientRect().bottom < 0', true)
->assertScript('(() => { document.getElementById("tasks-heading").focus(); return document.getElementById("tasks-heading").getBoundingClientRect().top >= document.getElementById("app-header").getBoundingClientRect().bottom; })()', true);
});
it('lets the header scroll with the page on a phone', function () {
visit(route('jobs.show', $this->job->id))->on()->mobile()
->assertScript('getComputedStyle(document.getElementById("app-header")).position', 'static')
->assertScript('getComputedStyle(document.documentElement).scrollPaddingTop', '0px');
});