From 60cab4b8711551dc40e42ecdbb33a4235faad731 Mon Sep 17 00:00:00 2001 From: Petri Saarinen Date: Wed, 25 Nov 2026 07:18:55 +0200 Subject: [PATCH] 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 --- resources/css/app.css | 5 ++++ resources/views/layouts/app.blade.php | 34 ++++++++++++++++++++++- tests/Browser/StickyHeaderTest.php | 40 +++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 tests/Browser/StickyHeaderTest.php diff --git a/resources/css/app.css b/resources/css/app.css index 8104cb1..47726c7 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -34,6 +34,11 @@ --color-primary-800: #312e81; } +/* The sticky header's height (set by the layout), so focus and anchors land below it. */ +html { + scroll-padding-top: var(--app-header-offset, 0px); +} + [x-cloak] { display: none !important; } diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 6990e64..526459e 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -48,7 +48,8 @@ @auth -
+ {{-- Sticky from md up; on narrow screens (and 400 % zoom) the wrapped header would take too much of the view. --}} +
{{ app(\App\Modules\Shared\Application\UseCases\CompanyDetailsStore::class)->menuName() }} @@ -74,6 +75,37 @@ {{ $slot }} + {{-- + While the header is sticky, scroll-padding-top keeps focused elements, anchors (#tasks) and the skip link + target from scrolling under it (WCAG 2.4.11). The offset follows the header's height as it wraps or resizes, + and is set again after wire:navigate swaps the page (data-navigate-once: the listeners are added only once). + --}} + + @livewireScripts diff --git a/tests/Browser/StickyHeaderTest.php b/tests/Browser/StickyHeaderTest.php new file mode 100644 index 0000000..1a9af3a --- /dev/null +++ b/tests/Browser/StickyHeaderTest.php @@ -0,0 +1,40 @@ +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'); +});