Open only the info popover when a calendar bar is tapped
On touch screens a tap on a task bar both showed its info popover and opened the schedule dialog. A tap now only opens the popover, which stays open until something else is tapped, and the popover's own "Open schedule" button opens the dialog. Mouse clicks and Enter still open the dialog directly. The popover is no longer a tooltip since it holds a button, and the bar's aria-describedby points only at the details. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -552,6 +552,7 @@ new class extends Component
|
||||
x-on:pointermove.window="track($event)"
|
||||
x-on:pointerup.window="drop($event)"
|
||||
x-on:keydown.escape.window="cancel(); closeInfo()"
|
||||
x-on:pointerdown.window="dismissInfo($event)"
|
||||
x-on:task-calendar-place.window="begin($event.detail.event, 'place', $event.detail.bar)"
|
||||
>
|
||||
<div class="grid border-b border-zinc-300 text-sm dark:border-zinc-600" style="{{ $columns }}" aria-hidden="true">
|
||||
@@ -641,13 +642,14 @@ new class extends Component
|
||||
id="bar-{{ $bar->key() }}"
|
||||
wire:key="bar-{{ $bar->key() }}"
|
||||
aria-label="{{ $this->barLabel($bar) }}"
|
||||
aria-describedby="bar-info-{{ $bar->key() }}"
|
||||
aria-describedby="bar-info-{{ $bar->key() }}-details"
|
||||
data-calendar-bar
|
||||
x-on:mouseenter="showInfo($el, 'bar-info-{{ $bar->key() }}')"
|
||||
x-on:mouseleave="hideInfo('bar-info-{{ $bar->key() }}')"
|
||||
x-on:focus="showInfo($el, 'bar-info-{{ $bar->key() }}')"
|
||||
x-on:blur="hideInfo('bar-info-{{ $bar->key() }}', 0)"
|
||||
x-on:blur="blurBar($event, 'bar-info-{{ $bar->key() }}')"
|
||||
x-on:pointerdown="begin($event, 'move', @js(['task' => $bar->task->taskId, 'job' => $bar->task->jobId, 'user' => $bar->userId, 'from' => $bar->from, 'to' => $bar->to]))"
|
||||
x-on:click="if (! consumeDrag()) $wire.openDialog({{ $bar->task->taskId }}, {{ $bar->userId ?? 'null' }})"
|
||||
x-on:click="clickBar($el, 'bar-info-{{ $bar->key() }}', () => $wire.openDialog({{ $bar->task->taskId }}, {{ $bar->userId ?? 'null' }}))"
|
||||
@class([
|
||||
'relative z-10 mx-0.5 my-1 flex min-w-0 touch-none flex-col justify-center overflow-hidden border px-2 text-left text-xs leading-tight select-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:focus-visible:outline-blue-300',
|
||||
'cursor-grab' => $canManage,
|
||||
@@ -682,17 +684,19 @@ new class extends Component
|
||||
@endif
|
||||
</button>
|
||||
|
||||
{{-- The job's basic details on hover and focus (WCAG 1.4.13: hoverable, Escape closes it). --}}
|
||||
{{-- The job's basic details on hover, focus and tap (WCAG 1.4.13: hoverable, Escape closes it), with a button to the dialog for touch screens. --}}
|
||||
<div
|
||||
id="bar-info-{{ $bar->key() }}"
|
||||
wire:key="bar-info-{{ $bar->key() }}"
|
||||
popover="manual"
|
||||
role="tooltip"
|
||||
x-on:mouseenter="keepInfo()"
|
||||
x-on:mouseleave="hideInfo('bar-info-{{ $bar->key() }}')"
|
||||
x-on:pointerdown="holdInfo()"
|
||||
x-on:focusout="leaveInfo($event, 'bar-info-{{ $bar->key() }}')"
|
||||
class="m-0 w-80 max-w-[calc(100vw-1rem)] rounded-lg border border-zinc-300 bg-white p-3 text-left text-sm text-zinc-900 shadow-lg dark:border-zinc-600 dark:bg-zinc-800 dark:text-white"
|
||||
style="inset: auto;"
|
||||
>
|
||||
<div id="bar-info-{{ $bar->key() }}-details">
|
||||
<p class="font-semibold break-words">{{ $bar->task->title }}</p>
|
||||
<dl class="mt-2 grid grid-cols-[max-content_1fr] gap-x-3 gap-y-1">
|
||||
<dt class="font-medium">{{ __('jobs.calendar.info.job') }}</dt>
|
||||
@@ -723,6 +727,16 @@ new class extends Component
|
||||
<p class="mt-2 line-clamp-3 break-words whitespace-pre-line text-zinc-700 dark:text-zinc-200">{{ $bar->task->description }}</p>
|
||||
@endif
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
<x-button
|
||||
sm
|
||||
id="bar-info-{{ $bar->key() }}-open"
|
||||
x-on:click="openFromInfo(() => $wire.openDialog({{ $bar->task->taskId }}, {{ $bar->userId ?? 'null' }}))"
|
||||
:text="__('jobs.calendar.info.open_schedule')"
|
||||
:aria-label="__('jobs.calendar.info.open_schedule_named', ['title' => $bar->task->title])"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</section>
|
||||
@endforeach
|
||||
|
||||
@@ -235,6 +235,8 @@ return [
|
||||
'work_type' => 'Work type',
|
||||
'due_on' => 'Task due date',
|
||||
'schedule' => 'Schedule',
|
||||
'open_schedule' => 'Open schedule',
|
||||
'open_schedule_named' => 'Open schedule: task :title',
|
||||
],
|
||||
'unscheduled' => 'Unscheduled tasks',
|
||||
'unscheduled_intro' => 'Open tasks without a schedule. Drag a task onto the calendar or choose Schedule.',
|
||||
|
||||
@@ -235,6 +235,8 @@ return [
|
||||
'work_type' => 'Työtehtävä',
|
||||
'due_on' => 'Tehtävän määräpäivä',
|
||||
'schedule' => 'Aikataulu',
|
||||
'open_schedule' => 'Avaa aikataulu',
|
||||
'open_schedule_named' => 'Avaa aikataulu: tehtävä :title',
|
||||
],
|
||||
'unscheduled' => 'Aikatauluttamattomat tehtävät',
|
||||
'unscheduled_intro' => 'Avoimet tehtävät ilman aikataulua. Vedä tehtävä kalenteriin tai valitse Aikatauluta.',
|
||||
|
||||
@@ -9,7 +9,10 @@
|
||||
* the same changes with the keyboard. Escape cancels a drag.
|
||||
*
|
||||
* Hovering or focusing a bar shows its info popover (the job's basic
|
||||
* details); the pointer may move onto it, and Escape closes it.
|
||||
* details); the pointer may move onto it, and Escape closes it. A mouse
|
||||
* click or Enter on a bar opens its dialog. On a touch screen a tap only
|
||||
* opens the popover (a tap would otherwise both show it and open the
|
||||
* dialog), and the popover's own button opens the dialog.
|
||||
*/
|
||||
const DRAG_THRESHOLD_PX = 5;
|
||||
const DAY_MS = 24 * 60 * 60 * 1000;
|
||||
@@ -40,6 +43,8 @@ export function taskCalendar(canManage) {
|
||||
|
||||
info: null,
|
||||
infoTimer: null,
|
||||
infoHeld: false,
|
||||
touched: false,
|
||||
|
||||
/**
|
||||
* Shows the info popover of a bar next to it. Not while dragging.
|
||||
@@ -86,6 +91,10 @@ export function taskCalendar(canManage) {
|
||||
this.infoTimer = setTimeout(() => {
|
||||
const popover = document.getElementById(id);
|
||||
|
||||
if (this.infoHeld && this.info === popover) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (popover?.matches(':popover-open')) {
|
||||
popover.hidePopover();
|
||||
}
|
||||
@@ -103,6 +112,7 @@ export function taskCalendar(canManage) {
|
||||
|
||||
closeInfo() {
|
||||
this.keepInfo();
|
||||
this.infoHeld = false;
|
||||
|
||||
if (this.info?.matches(':popover-open')) {
|
||||
this.info.hidePopover();
|
||||
@@ -111,8 +121,80 @@ export function taskCalendar(canManage) {
|
||||
this.info = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* A tap on a popover keeps it open until something outside it is tapped.
|
||||
*/
|
||||
holdInfo() {
|
||||
this.keepInfo();
|
||||
this.infoHeld = true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Closes the popover when a tap or click lands outside it and its bar.
|
||||
*/
|
||||
dismissInfo(event) {
|
||||
if (this.info && !this.info.contains(event.target) && !event.target.closest?.('[data-calendar-bar]')) {
|
||||
this.closeInfo();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Keyboard focus leaving the popover (not back to its bar) closes it.
|
||||
*/
|
||||
leaveInfo(event, id) {
|
||||
const next = event.relatedTarget;
|
||||
|
||||
if (next && (next.closest?.(`#${id}`) || next.getAttribute?.('aria-describedby') === `${id}-details`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.hideInfo(id, 0);
|
||||
},
|
||||
|
||||
/**
|
||||
* A bar's own blur closes its popover unless focus moves into it.
|
||||
*/
|
||||
blurBar(event, id) {
|
||||
if (event.relatedTarget?.closest?.(`#${id}`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.hideInfo(id, 0);
|
||||
},
|
||||
|
||||
/**
|
||||
* A mouse click or Enter opens the dialog; a tap shows the popover,
|
||||
* whose button opens the dialog.
|
||||
*/
|
||||
clickBar(bar, id, open) {
|
||||
const touched = this.touched;
|
||||
this.touched = false;
|
||||
|
||||
if (this.consumeDrag()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (touched) {
|
||||
this.showInfo(bar, id);
|
||||
this.holdInfo();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
open();
|
||||
},
|
||||
|
||||
/**
|
||||
* The popover's button: close it and open the dialog.
|
||||
*/
|
||||
openFromInfo(open) {
|
||||
this.closeInfo();
|
||||
open();
|
||||
},
|
||||
|
||||
begin(event, mode, bar) {
|
||||
this.closeInfo();
|
||||
this.touched = event.pointerType === 'touch' || event.pointerType === 'pen';
|
||||
|
||||
if (!canManage || event.button !== 0 || event.pointerType === 'touch') {
|
||||
return;
|
||||
|
||||
@@ -97,6 +97,30 @@ it('shows the job details of a bar on hover and focus, and closes them with Esca
|
||||
->assertNoJavaScriptErrors();
|
||||
})->with(['light', 'dark']);
|
||||
|
||||
it('opens only the popover on a tap, and the dialog from its button', function () {
|
||||
$key = $this->task->id.'-'.$this->user->id;
|
||||
$open = "document.getElementById('bar-info-{$key}').matches(':popover-open')";
|
||||
$tap = <<<JS
|
||||
(() => {
|
||||
const bar = document.getElementById('bar-{$key}');
|
||||
const options = { bubbles: true, pointerType: 'touch', isPrimary: true, button: 0 };
|
||||
bar.dispatchEvent(new PointerEvent('pointerdown', options));
|
||||
bar.dispatchEvent(new PointerEvent('pointerup', options));
|
||||
bar.dispatchEvent(new MouseEvent('mouseenter'));
|
||||
bar.click();
|
||||
})()
|
||||
JS;
|
||||
|
||||
$visit = visit(route('jobs.calendar'))->on()->desktop();
|
||||
$visit->script($tap);
|
||||
$visit->assertScript($open, true)
|
||||
->assertScript("document.getElementById('task-schedule-dialog').open", false)
|
||||
->click('#bar-info-'.$key.'-open')
|
||||
->assertSee('Tehtävän aikataulu')
|
||||
->assertScript("document.getElementById('task-schedule-dialog').open", true)
|
||||
->assertScript($open, false);
|
||||
});
|
||||
|
||||
it('moves a task to another person by dragging its bar', function () {
|
||||
// The bar (today – today + 2) is grabbed at its middle day, so dropping it
|
||||
// on today + 4 moves it three days later.
|
||||
|
||||
@@ -179,7 +179,8 @@ it('shows the job details in the info popover of a bar', function () {
|
||||
$task = TaskModel::query()->sole();
|
||||
|
||||
Livewire::test('jobs::calendar')
|
||||
->assertSee('aria-describedby="bar-info-'.$task->id.'-'.$this->other->id.'"', escape: false)
|
||||
->assertSee('aria-describedby="bar-info-'.$task->id.'-'.$this->other->id.'-details"', escape: false)
|
||||
->assertSee('Avaa aikataulu: tehtävä Mainoskuvat')
|
||||
->assertSeeInOrder([
|
||||
'Työ', $this->job->number, 'Kampanja',
|
||||
'Asiakas', CustomerModel::query()->findOrFail($this->job->customer_id)->name,
|
||||
|
||||
Reference in New Issue
Block a user