Draw the timepicker without Tailwind
Plan step 36 (inputs group, last of the "not started" pair): <x-timepicker> renders data-md-timepicker-* throughout (data-md-mode, data-md-cycle, data-md-view, data-md-inner, data-md-dragging, data-md-disabled, data-md-error and data-md-value replace their unprefixed hooks), and timepicker.css moves into material.components, importing field.css, icon.css and button.css. The dialog's Tailwind utility class (position, the scrim, the spatial-fast pop and its @starting-style) becomes plain declarations under data-md-timepicker-dialog, matching the datepicker's modal dialog. The landscape rule stays keyed on orientation and viewport height, in px (560/364/346), never a breakpoint, as M3 asks. The hour and minute boxes and the period buttons swap their Tailwind `state-layer focus-ring` utilities for `md-state-layer md-focus-ring`: same declarations, so nothing else in the stylesheet changes for them. The dial swaps in `md-focus-ring` for its own hand-rolled, byte-identical outline-on-:focus-visible rule, which timepicker.css no longer carries. The period selector was already the radio-in-a-list M3's labelling table asks for (role="radio" in a role="radiogroup", moved by the arrow keys), and Shift+M/Y already reached the date picker's dropdowns — both predate this rewrite. field.css's data-md-field-button note is tidied now that every component that selects it (input, password, datepicker, timepicker) is rewritten. Browser tests written but not run (the inputs group's Chromium run follows this stream): the period radios moving with the arrow keys, and the dial lying on its side below the landscape height threshold. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qwx5USif3wFFmxtHg5U1g9
This commit is contained in:
co-authored by
Claude Opus 5
parent
72d9dbfc89
commit
d46b07c13c
@@ -79,37 +79,37 @@ it('opens the dial on the hour, as the bound time says', function () {
|
||||
->assertScript("document.querySelector('#meeting-dialog').open")
|
||||
->assertAttribute('#meeting', 'aria-expanded', 'true')
|
||||
->assertSeeIn('#meeting-title', 'Select time')
|
||||
->assertAttribute('#meeting-dialog [data-timepicker-box="hour"]', 'aria-pressed', 'true')
|
||||
->assertSeeIn('#meeting-dialog [data-timepicker-box="hour"]', '09')
|
||||
->assertSeeIn('#meeting-dialog [data-timepicker-box="minute"]', '30')
|
||||
->assertAttribute('#meeting-dialog [data-timepicker-display] [data-timepicker-period-option="am"]', 'aria-checked', 'true')
|
||||
->assertAttribute('#meeting-dialog [data-timepicker-dial]', 'aria-valuenow', '9')
|
||||
->assertScript('document.activeElement === '.inPicker('meeting', '[data-timepicker-dial]'));
|
||||
->assertAttribute('#meeting-dialog [data-md-timepicker-box="hour"]', 'aria-pressed', 'true')
|
||||
->assertSeeIn('#meeting-dialog [data-md-timepicker-box="hour"]', '09')
|
||||
->assertSeeIn('#meeting-dialog [data-md-timepicker-box="minute"]', '30')
|
||||
->assertAttribute('#meeting-dialog [data-md-timepicker-display] [data-md-timepicker-period-option="am"]', 'aria-checked', 'true')
|
||||
->assertAttribute('#meeting-dialog [data-md-timepicker-dial]', 'aria-valuenow', '9')
|
||||
->assertScript('document.activeElement === '.inPicker('meeting', '[data-md-timepicker-dial]'));
|
||||
});
|
||||
|
||||
it('writes the hour and the minute pressed on the dial to Livewire on OK', function () {
|
||||
$dial = inPicker('meeting', '[data-timepicker-dial]');
|
||||
$dial = inPicker('meeting', '[data-md-timepicker-dial]');
|
||||
|
||||
$page = timeProbe()
|
||||
->click('#meeting')
|
||||
->click('#meeting-dialog [data-timepicker-label="hour12"][data-value="3"]')
|
||||
->assertSeeIn('#meeting-dialog [data-timepicker-box="hour"]', '03')
|
||||
->assertAttribute('#meeting-dialog [data-timepicker-dial]', 'data-view', 'minute')
|
||||
->assertAttribute('#meeting-dialog [data-timepicker-box="minute"]', 'aria-pressed', 'true')
|
||||
->click('#meeting-dialog [data-md-timepicker-label="hour12"][data-md-value="3"]')
|
||||
->assertSeeIn('#meeting-dialog [data-md-timepicker-box="hour"]', '03')
|
||||
->assertAttribute('#meeting-dialog [data-md-timepicker-dial]', 'data-md-view', 'minute')
|
||||
->assertAttribute('#meeting-dialog [data-md-timepicker-box="minute"]', 'aria-pressed', 'true')
|
||||
// The selector turns to the value it chose: the handle ends over the number.
|
||||
->assertScript(<<<JS
|
||||
(() => {
|
||||
const handle = {$dial}.querySelector('[data-timepicker-handle]').getBoundingClientRect();
|
||||
const label = {$dial}.querySelector('[data-timepicker-label="minute"][data-value="30"]').getBoundingClientRect();
|
||||
const handle = {$dial}.querySelector('[data-md-timepicker-handle]').getBoundingClientRect();
|
||||
const label = {$dial}.querySelector('[data-md-timepicker-label="minute"][data-md-value="30"]').getBoundingClientRect();
|
||||
|
||||
return Math.abs(handle.x - label.x) < 1 && Math.abs(handle.y - label.y) < 1;
|
||||
})()
|
||||
JS);
|
||||
|
||||
$page->click('#meeting-dialog [data-timepicker-label="minute"][data-value="45"]')
|
||||
->assertSeeIn('#meeting-dialog [data-timepicker-box="minute"]', '45')
|
||||
$page->click('#meeting-dialog [data-md-timepicker-label="minute"][data-md-value="45"]')
|
||||
->assertSeeIn('#meeting-dialog [data-md-timepicker-box="minute"]', '45')
|
||||
->assertSeeIn('#meeting-value', '09:30')
|
||||
->click('#meeting-dialog [data-timepicker-confirm]')
|
||||
->click('#meeting-dialog [data-md-timepicker-confirm]')
|
||||
->assertSeeIn('#meeting-value', '03:45')
|
||||
->assertValue('#meeting', '3:45 AM')
|
||||
->assertScript("! document.querySelector('#meeting-dialog').open")
|
||||
@@ -119,9 +119,9 @@ it('writes the hour and the minute pressed on the dial to Livewire on OK', funct
|
||||
it('leaves the time alone when the picker is cancelled', function () {
|
||||
timeProbe()
|
||||
->click('#meeting')
|
||||
->click('#meeting-dialog [data-timepicker-label="hour12"][data-value="7"]')
|
||||
->assertSeeIn('#meeting-dialog [data-timepicker-box="hour"]', '07')
|
||||
->click('#meeting-dialog [data-timepicker-cancel]')
|
||||
->click('#meeting-dialog [data-md-timepicker-label="hour12"][data-md-value="7"]')
|
||||
->assertSeeIn('#meeting-dialog [data-md-timepicker-box="hour"]', '07')
|
||||
->click('#meeting-dialog [data-md-timepicker-cancel]')
|
||||
->assertScript("! document.querySelector('#meeting-dialog').open")
|
||||
->assertSeeIn('#meeting-value', '09:30')
|
||||
->assertValue('#meeting', '9:30 AM');
|
||||
@@ -130,21 +130,21 @@ it('leaves the time alone when the picker is cancelled', function () {
|
||||
it('turns three o\'clock into 15 with PM', function () {
|
||||
timeProbe()
|
||||
->click('#meeting')
|
||||
->click('#meeting-dialog [data-timepicker-display] [data-timepicker-period-option="pm"]')
|
||||
->assertAttribute('#meeting-dialog [data-timepicker-display] [data-timepicker-period-option="pm"]', 'aria-checked', 'true')
|
||||
->click('#meeting-dialog [data-timepicker-label="hour12"][data-value="3"]')
|
||||
->click('#meeting-dialog [data-timepicker-label="minute"][data-value="15"]')
|
||||
->click('#meeting-dialog [data-timepicker-confirm]')
|
||||
->click('#meeting-dialog [data-md-timepicker-display] [data-md-timepicker-period-option="pm"]')
|
||||
->assertAttribute('#meeting-dialog [data-md-timepicker-display] [data-md-timepicker-period-option="pm"]', 'aria-checked', 'true')
|
||||
->click('#meeting-dialog [data-md-timepicker-label="hour12"][data-md-value="3"]')
|
||||
->click('#meeting-dialog [data-md-timepicker-label="minute"][data-md-value="15"]')
|
||||
->click('#meeting-dialog [data-md-timepicker-confirm]')
|
||||
->assertSeeIn('#meeting-value', '15:15')
|
||||
->assertValue('#meeting', '3:15 PM');
|
||||
});
|
||||
|
||||
it('draws a German dial with 24 hours, 12 to 23 on the inner ring', function () {
|
||||
$dial = inPicker('alarm', '[data-timepicker-dial]');
|
||||
$dial = inPicker('alarm', '[data-md-timepicker-dial]');
|
||||
$radius = fn (string $value): string => <<<JS
|
||||
(() => {
|
||||
const dial = {$dial}.getBoundingClientRect();
|
||||
const label = {$dial}.querySelector('[data-timepicker-label="hour24"][data-value="{$value}"]').getBoundingClientRect();
|
||||
const label = {$dial}.querySelector('[data-md-timepicker-label="hour24"][data-md-value="{$value}"]').getBoundingClientRect();
|
||||
|
||||
return Math.round(Math.hypot(label.x + label.width / 2 - dial.x - dial.width / 2, label.y + label.height / 2 - dial.y - dial.height / 2));
|
||||
})()
|
||||
@@ -152,41 +152,41 @@ it('draws a German dial with 24 hours, 12 to 23 on the inner ring', function ()
|
||||
|
||||
$page = timeProbe()
|
||||
->click('#alarm')
|
||||
->assertAttribute('#alarm-dialog [data-timepicker-dial]', 'data-cycle', '24')
|
||||
->assertScript("getComputedStyle(document.querySelector('#alarm-dialog [data-timepicker-period]')).display === 'none'")
|
||||
->assertScript("{$dial}.querySelector('[data-timepicker-label=\"hour24\"][data-value=\"0\"]').textContent.trim() === '00'")
|
||||
->assertAttribute('#alarm-dialog [data-md-timepicker-dial]', 'data-md-cycle', '24')
|
||||
->assertScript("getComputedStyle(document.querySelector('#alarm-dialog [data-md-timepicker-period]')).display === 'none'")
|
||||
->assertScript("{$dial}.querySelector('[data-md-timepicker-label=\"hour24\"][data-md-value=\"0\"]').textContent.trim() === '00'")
|
||||
->assertScript($radius('0').' === 101')
|
||||
->assertScript($radius('11').' === 101')
|
||||
->assertScript($radius('12').' === 69')
|
||||
->assertScript($radius('13').' === 69')
|
||||
->assertScript($radius('23').' === 69');
|
||||
|
||||
$page->click('#alarm-dialog [data-timepicker-label="hour24"][data-value="15"]')
|
||||
->assertSeeIn('#alarm-dialog [data-timepicker-box="hour"]', '15')
|
||||
->assertAttribute('#alarm-dialog [data-timepicker-dial]', 'data-view', 'minute')
|
||||
->click('#alarm-dialog [data-timepicker-label="minute"][data-value="0"]')
|
||||
->click('#alarm-dialog [data-timepicker-confirm]')
|
||||
$page->click('#alarm-dialog [data-md-timepicker-label="hour24"][data-md-value="15"]')
|
||||
->assertSeeIn('#alarm-dialog [data-md-timepicker-box="hour"]', '15')
|
||||
->assertAttribute('#alarm-dialog [data-md-timepicker-dial]', 'data-md-view', 'minute')
|
||||
->click('#alarm-dialog [data-md-timepicker-label="minute"][data-md-value="0"]')
|
||||
->click('#alarm-dialog [data-md-timepicker-confirm]')
|
||||
->assertSeeIn('#alarm-value', '15:00')
|
||||
->assertValue('#alarm', '15:00');
|
||||
|
||||
// The outer ring is the morning.
|
||||
$page->click('#alarm')
|
||||
->click('#alarm-dialog [data-timepicker-label="hour24"][data-value="3"]')
|
||||
->assertSeeIn('#alarm-dialog [data-timepicker-box="hour"]', '03')
|
||||
->click('#alarm-dialog [data-timepicker-label="minute"][data-value="0"]')
|
||||
->click('#alarm-dialog [data-timepicker-confirm]')
|
||||
->click('#alarm-dialog [data-md-timepicker-label="hour24"][data-md-value="3"]')
|
||||
->assertSeeIn('#alarm-dialog [data-md-timepicker-box="hour"]', '03')
|
||||
->click('#alarm-dialog [data-md-timepicker-label="minute"][data-md-value="0"]')
|
||||
->click('#alarm-dialog [data-md-timepicker-confirm]')
|
||||
->assertSeeIn('#alarm-value', '03:00');
|
||||
});
|
||||
|
||||
it('follows a drag round the dial and settles on the nearest hour', function () {
|
||||
$dial = inPicker('meeting', '[data-timepicker-dial]');
|
||||
$dial = inPicker('meeting', '[data-md-timepicker-dial]');
|
||||
|
||||
$page = timeProbe()->click('#meeting');
|
||||
|
||||
// Pointer events built in the page's own realm, from twelve o'clock round to just past four.
|
||||
$send = fn (string $type, int $degrees): string => <<<JS
|
||||
window.eval(`(() => {
|
||||
const dial = document.querySelector('#meeting-dialog [data-timepicker-dial]');
|
||||
const dial = document.querySelector('#meeting-dialog [data-md-timepicker-dial]');
|
||||
const box = dial.getBoundingClientRect();
|
||||
const radians = {$degrees} * Math.PI / 180;
|
||||
|
||||
@@ -201,14 +201,14 @@ it('follows a drag round the dial and settles on the nearest hour', function ()
|
||||
$page->script($send('pointerdown', 0).';'.$send('pointermove', 20).';'.$send('pointermove', 60).';'.$send('pointermove', 125));
|
||||
|
||||
// While dragging, the handle stays under the pointer rather than on a number.
|
||||
$page->assertScript("{$dial}.hasAttribute('data-dragging') && parseFloat(getComputedStyle({$dial}).getPropertyValue('--timepicker-angle')) % 360 === 125")
|
||||
->assertSeeIn('#meeting-dialog [data-timepicker-box="hour"]', '04');
|
||||
$page->assertScript("{$dial}.hasAttribute('data-md-dragging') && parseFloat(getComputedStyle({$dial}).getPropertyValue('--timepicker-angle')) % 360 === 125")
|
||||
->assertSeeIn('#meeting-dialog [data-md-timepicker-box="hour"]', '04');
|
||||
|
||||
$page->script($send('pointerup', 125));
|
||||
|
||||
$page->assertScript("! {$dial}.hasAttribute('data-dragging')")
|
||||
->assertAttribute('#meeting-dialog [data-timepicker-dial]', 'data-view', 'minute')
|
||||
->assertSeeIn('#meeting-dialog [data-timepicker-box="hour"]', '04');
|
||||
$page->assertScript("! {$dial}.hasAttribute('data-md-dragging')")
|
||||
->assertAttribute('#meeting-dialog [data-md-timepicker-dial]', 'data-md-view', 'minute')
|
||||
->assertSeeIn('#meeting-dialog [data-md-timepicker-box="hour"]', '04');
|
||||
});
|
||||
|
||||
it('changes the focused hour and minute with the arrow keys and confirms with Enter', function () {
|
||||
@@ -217,23 +217,23 @@ it('changes the focused hour and minute with the arrow keys and confirms with En
|
||||
$page->script("document.querySelector('#meeting').focus()");
|
||||
|
||||
$page->keys('#meeting', 'Enter')
|
||||
->assertScript('document.activeElement === '.inPicker('meeting', '[data-timepicker-dial]'))
|
||||
->assertScript('document.activeElement === '.inPicker('meeting', '[data-md-timepicker-dial]'))
|
||||
->keys(':focus', 'ArrowUp')
|
||||
->assertAttribute('#meeting-dialog [data-timepicker-dial]', 'aria-valuenow', '10')
|
||||
->assertSeeIn('#meeting-dialog [data-timepicker-box="hour"]', '10')
|
||||
->assertAttribute('#meeting-dialog [data-md-timepicker-dial]', 'aria-valuenow', '10')
|
||||
->assertSeeIn('#meeting-dialog [data-md-timepicker-box="hour"]', '10')
|
||||
// The keyboard never moves on to the minutes by itself.
|
||||
->assertAttribute('#meeting-dialog [data-timepicker-dial]', 'data-view', 'hour');
|
||||
->assertAttribute('#meeting-dialog [data-md-timepicker-dial]', 'data-md-view', 'hour');
|
||||
|
||||
$page->script(inPicker('meeting', '[data-timepicker-box="minute"]').'.focus()');
|
||||
$page->script(inPicker('meeting', '[data-md-timepicker-box="minute"]').'.focus()');
|
||||
|
||||
$page->keys(':focus', 'Enter')
|
||||
->assertAttribute('#meeting-dialog [data-timepicker-dial]', 'data-view', 'minute');
|
||||
->assertAttribute('#meeting-dialog [data-md-timepicker-dial]', 'data-md-view', 'minute');
|
||||
|
||||
$page->script(inPicker('meeting', '[data-timepicker-dial]').'.focus()');
|
||||
$page->script(inPicker('meeting', '[data-md-timepicker-dial]').'.focus()');
|
||||
|
||||
$page->keys(':focus', ['ArrowDown', 'ArrowLeft'])
|
||||
->assertAttribute('#meeting-dialog [data-timepicker-dial]', 'aria-valuenow', '28')
|
||||
->assertAttribute('#meeting-dialog [data-timepicker-dial]', 'aria-valuetext', '28 minutes')
|
||||
->assertAttribute('#meeting-dialog [data-md-timepicker-dial]', 'aria-valuenow', '28')
|
||||
->assertAttribute('#meeting-dialog [data-md-timepicker-dial]', 'aria-valuetext', '28 minutes')
|
||||
->keys(':focus', 'Enter')
|
||||
->assertScript("! document.querySelector('#meeting-dialog').open")
|
||||
->assertSeeIn('#meeting-value', '10:28');
|
||||
@@ -242,7 +242,7 @@ it('changes the focused hour and minute with the arrow keys and confirms with En
|
||||
it('takes a typed time in the input variant and says what is wrong with it', function () {
|
||||
$page = timeProbe()
|
||||
->click('#meeting')
|
||||
->click('#meeting-dialog [data-timepicker-mode="input"]')
|
||||
->click('#meeting-dialog [data-md-timepicker-mode="input"]')
|
||||
->assertSeeIn('#meeting-title', 'Enter time')
|
||||
->assertScript("document.activeElement.id === 'meeting-hour'")
|
||||
->assertValue('#meeting-hour', '09')
|
||||
@@ -252,7 +252,7 @@ it('takes a typed time in the input variant and says what is wrong with it', fun
|
||||
->assertAttribute('#meeting-hour', 'aria-invalid', 'true')
|
||||
// Word joiners keep the range on one line in the narrow column.
|
||||
->assertScript(supportText('meeting-hour')." === 'Hour must be 1–12'")
|
||||
->click('#meeting-dialog [data-timepicker-confirm]')
|
||||
->click('#meeting-dialog [data-md-timepicker-confirm]')
|
||||
->assertScript("document.querySelector('#meeting-dialog').open")
|
||||
->assertSeeIn('#meeting-value', '09:30');
|
||||
|
||||
@@ -273,37 +273,37 @@ it('takes a typed time in the input variant and says what is wrong with it', fun
|
||||
});
|
||||
|
||||
it('keeps to the step and the limits', function () {
|
||||
$dial = inPicker('slot', '[data-timepicker-dial]');
|
||||
$dial = inPicker('slot', '[data-md-timepicker-dial]');
|
||||
|
||||
$page = timeProbe()
|
||||
->click('#slot')
|
||||
->assertScript("{$dial}.querySelector('[data-timepicker-label=\"hour24\"][data-value=\"8\"]').hasAttribute('data-disabled')")
|
||||
->assertScript("! {$dial}.querySelector('[data-timepicker-label=\"hour24\"][data-value=\"9\"]').hasAttribute('data-disabled')")
|
||||
->assertScript("{$dial}.querySelector('[data-timepicker-label=\"hour24\"][data-value=\"18\"]').hasAttribute('data-disabled')")
|
||||
->assertScript("{$dial}.querySelector('[data-md-timepicker-label=\"hour24\"][data-md-value=\"8\"]').hasAttribute('data-md-disabled')")
|
||||
->assertScript("! {$dial}.querySelector('[data-md-timepicker-label=\"hour24\"][data-md-value=\"9\"]').hasAttribute('data-md-disabled')")
|
||||
->assertScript("{$dial}.querySelector('[data-md-timepicker-label=\"hour24\"][data-md-value=\"18\"]').hasAttribute('data-md-disabled')")
|
||||
// An hour outside the limits is not taken.
|
||||
->click('#slot-dialog [data-timepicker-label="hour24"][data-value="20"]')
|
||||
->assertSeeIn('#slot-dialog [data-timepicker-box="hour"]', '10')
|
||||
->click('#slot-dialog [data-timepicker-label="hour24"][data-value="16"]')
|
||||
->assertAttribute('#slot-dialog [data-timepicker-dial]', 'data-view', 'minute')
|
||||
->assertScript("{$dial}.querySelector('[data-timepicker-label=\"minute\"][data-value=\"20\"]').hasAttribute('data-disabled')")
|
||||
->click('#slot-dialog [data-md-timepicker-label="hour24"][data-md-value="20"]')
|
||||
->assertSeeIn('#slot-dialog [data-md-timepicker-box="hour"]', '10')
|
||||
->click('#slot-dialog [data-md-timepicker-label="hour24"][data-md-value="16"]')
|
||||
->assertAttribute('#slot-dialog [data-md-timepicker-dial]', 'data-md-view', 'minute')
|
||||
->assertScript("{$dial}.querySelector('[data-md-timepicker-label=\"minute\"][data-md-value=\"20\"]').hasAttribute('data-md-disabled')")
|
||||
// A press between the steps lands on the nearest one.
|
||||
->click('#slot-dialog [data-timepicker-label="minute"][data-value="20"]')
|
||||
->assertSeeIn('#slot-dialog [data-timepicker-box="minute"]', '15');
|
||||
->click('#slot-dialog [data-md-timepicker-label="minute"][data-md-value="20"]')
|
||||
->assertSeeIn('#slot-dialog [data-md-timepicker-box="minute"]', '15');
|
||||
|
||||
$page->script("{$dial}.focus()");
|
||||
|
||||
$page->keys(':focus', 'ArrowUp')
|
||||
->assertAttribute('#slot-dialog [data-timepicker-dial]', 'aria-valuenow', '30')
|
||||
->click('#slot-dialog [data-timepicker-mode="input"]')
|
||||
->assertAttribute('#slot-dialog [data-md-timepicker-dial]', 'aria-valuenow', '30')
|
||||
->click('#slot-dialog [data-md-timepicker-mode="input"]')
|
||||
->type('#slot-hour', '18')
|
||||
->assertSeeIn('#slot-dialog [data-timepicker-range-error]', 'Choose a time from 09:00 to 17:00')
|
||||
->assertSeeIn('#slot-dialog [data-md-timepicker-range-error]', 'Choose a time from 09:00 to 17:00')
|
||||
->type('#slot-hour', '16')
|
||||
->type('#slot-minute', '20')
|
||||
->assertSeeIn('#slot-minute-support', 'Minute must be a multiple of 15')
|
||||
->click('#slot-dialog [data-timepicker-confirm]')
|
||||
->click('#slot-dialog [data-md-timepicker-confirm]')
|
||||
->assertScript("document.activeElement.id === 'slot-minute'")
|
||||
->type('#slot-minute', '45')
|
||||
->click('#slot-dialog [data-timepicker-confirm]')
|
||||
->click('#slot-dialog [data-md-timepicker-confirm]')
|
||||
->assertSeeIn('#slot-value', '16:45');
|
||||
});
|
||||
|
||||
@@ -324,16 +324,71 @@ it('gives focus back to the field on Escape', function () {
|
||||
it('stays open with its draft through a Livewire render', function () {
|
||||
$page = timeProbe()
|
||||
->click('#meeting')
|
||||
->click('#meeting-dialog [data-timepicker-label="hour12"][data-value="5"]')
|
||||
->assertAttribute('#meeting-dialog [data-timepicker-dial]', 'data-view', 'minute');
|
||||
->click('#meeting-dialog [data-md-timepicker-label="hour12"][data-md-value="5"]')
|
||||
->assertAttribute('#meeting-dialog [data-md-timepicker-dial]', 'data-md-view', 'minute');
|
||||
|
||||
$page->script('window.eval("Livewire.first().touch()")');
|
||||
|
||||
$page->assertSeeIn('#renders', '1')
|
||||
->assertScript("document.querySelector('#meeting-dialog').open")
|
||||
->assertSeeIn('#meeting-dialog [data-timepicker-box="hour"]', '05')
|
||||
->assertAttribute('#meeting-dialog [data-timepicker-dial]', 'data-view', 'minute')
|
||||
->click('#meeting-dialog [data-timepicker-label="minute"][data-value="10"]')
|
||||
->click('#meeting-dialog [data-timepicker-confirm]')
|
||||
->assertSeeIn('#meeting-dialog [data-md-timepicker-box="hour"]', '05')
|
||||
->assertAttribute('#meeting-dialog [data-md-timepicker-dial]', 'data-md-view', 'minute')
|
||||
->click('#meeting-dialog [data-md-timepicker-label="minute"][data-md-value="10"]')
|
||||
->click('#meeting-dialog [data-md-timepicker-confirm]')
|
||||
->assertSeeIn('#meeting-value', '05:10');
|
||||
});
|
||||
|
||||
it('moves the period selector between AM and PM with arrow keys, as a radio group', function () {
|
||||
$am = '#meeting-dialog [data-md-timepicker-display] [data-md-timepicker-period-option="am"]';
|
||||
$pm = '#meeting-dialog [data-md-timepicker-display] [data-md-timepicker-period-option="pm"]';
|
||||
|
||||
$page = timeProbe()
|
||||
->click('#meeting')
|
||||
->assertAttribute($am, 'role', 'radio')
|
||||
->assertAttribute($am, 'aria-checked', 'true')
|
||||
->assertAttribute($pm, 'aria-checked', 'false');
|
||||
|
||||
$page->script("document.querySelector('{$am}').focus()");
|
||||
|
||||
$page->keys(':focus', 'ArrowRight')
|
||||
->assertAttribute($pm, 'aria-checked', 'true')
|
||||
->assertAttribute($am, 'aria-checked', 'false')
|
||||
->assertScript("document.activeElement.dataset.mdTimepickerPeriodOption === 'pm'")
|
||||
// M3's radio-in-a-list: an arrow key moves to the other option and selects it, so PM
|
||||
// reaches the dial straight away — the hour turns 9 into 21 without a confirm.
|
||||
->assertSeeIn('#meeting-dialog [data-md-timepicker-box="hour"]', '09');
|
||||
|
||||
$page->keys(':focus', 'ArrowLeft')
|
||||
->assertAttribute($am, 'aria-checked', 'true')
|
||||
->assertAttribute($pm, 'aria-checked', 'false')
|
||||
->assertScript("document.activeElement.dataset.mdTimepickerPeriodOption === 'am'");
|
||||
});
|
||||
|
||||
it('lies the dial on its side in a short landscape window', function () {
|
||||
$page = timeProbe()
|
||||
->resize(700, 400)
|
||||
->click('#meeting')
|
||||
->assertScript("document.querySelector('#meeting-dialog').open");
|
||||
|
||||
// Side by side rather than stacked: the display and the dial share a top edge, the dial to
|
||||
// the display's end, and the picker's own layout (flex column) gives way to the grid areas.
|
||||
$page->assertScript(<<<'JS'
|
||||
(() => {
|
||||
const display = document.querySelector('#meeting-dialog [data-md-timepicker-display]').getBoundingClientRect();
|
||||
const dial = document.querySelector('#meeting-dialog [data-md-timepicker-dial]').getBoundingClientRect();
|
||||
|
||||
return Math.abs(display.top - dial.top) < 4 && dial.left >= display.right;
|
||||
})()
|
||||
JS)
|
||||
->assertScript("getComputedStyle(document.querySelector('#meeting-dialog [data-md-timepicker-picker]')).display === 'contents'");
|
||||
|
||||
$page->resize(390, 800)
|
||||
->assertScript(<<<'JS'
|
||||
(() => {
|
||||
const display = document.querySelector('#meeting-dialog [data-md-timepicker-display]').getBoundingClientRect();
|
||||
const dial = document.querySelector('#meeting-dialog [data-md-timepicker-dial]').getBoundingClientRect();
|
||||
|
||||
return dial.top >= display.bottom;
|
||||
})()
|
||||
JS);
|
||||
});
|
||||
|
||||
@@ -34,6 +34,7 @@ dataset('input components', [
|
||||
'table',
|
||||
'sort-header',
|
||||
'datepicker',
|
||||
'timepicker',
|
||||
]);
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,13 +28,13 @@ it('draws a read-only field that opens the picker in a labelled dialog', functio
|
||||
->toContain('aria-describedby="starts-support"')
|
||||
->toMatch('/<p id="starts-support" data-md-field-support\s*>In your time zone<\/p>/')
|
||||
->toContain('x-on:keydown.enter.prevent="show()"')
|
||||
->toContain('data-timepicker-open')
|
||||
->toContain('data-md-timepicker-open')
|
||||
->toContain('aria-label="Choose time"')
|
||||
->toContain('<dialog')
|
||||
->toContain('id="starts-dialog"')
|
||||
->toContain('wire:ignore')
|
||||
->toContain('aria-labelledby="starts-title"')
|
||||
->toContain('<h2 id="starts-title" data-timepicker-title')
|
||||
->toContain('<h2 id="starts-title" data-md-timepicker-title')
|
||||
->toContain('x-modelable="value"')
|
||||
->toContain("materialTimepicker( '14:30' ,")
|
||||
->not->toContain('aria-invalid="true"')
|
||||
@@ -47,18 +47,18 @@ it('draws the dial as a slider, with twelve numbers per ring and M3\'s 24-hour i
|
||||
expect($html)
|
||||
->toContain('role="slider"')
|
||||
->toContain('x-bind:aria-valuetext="valueText"')
|
||||
->and(substr_count($html, 'data-timepicker-label="hour12"'))->toBe(12)
|
||||
->and(substr_count($html, 'data-timepicker-label="hour24"'))->toBe(24)
|
||||
->and(substr_count($html, 'data-timepicker-label="minute"'))->toBe(12)
|
||||
->and(substr_count($html, 'data-md-timepicker-label="hour12"'))->toBe(12)
|
||||
->and(substr_count($html, 'data-md-timepicker-label="hour24"'))->toBe(24)
|
||||
->and(substr_count($html, 'data-md-timepicker-label="minute"'))->toBe(12)
|
||||
->and($html)
|
||||
->toMatch('/data-timepicker-label="hour24" data-value="0"\s+style="--x: 0\.0000; --y: -1\.0000"\s*>00</')
|
||||
->toMatch('/data-timepicker-label="hour24" data-value="12"\s+data-inner\s+style="--x: 0\.0000; --y: -1\.0000"\s*>12</')
|
||||
->toMatch('/data-timepicker-label="hour24" data-value="15"\s+data-inner\s+style="--x: 1\.0000; --y: -0\.0000"\s*>15</')
|
||||
->toMatch('/data-timepicker-label="minute" data-value="0"\s+style="[^"]*"\s*>00</')
|
||||
->toMatch('/data-timepicker-label="hour12" data-value="12"\s+style="--x: 0\.0000; --y: -1\.0000"\s*>12</')
|
||||
->toContain('data-timepicker-handle')
|
||||
->toContain('data-timepicker-ink')
|
||||
->not->toContain('x-bind:data-disabled');
|
||||
->toMatch('/data-md-timepicker-label="hour24" data-md-value="0"\s+style="--x: 0\.0000; --y: -1\.0000"\s*>00</')
|
||||
->toMatch('/data-md-timepicker-label="hour24" data-md-value="12"\s+data-md-inner\s+style="--x: 0\.0000; --y: -1\.0000"\s*>12</')
|
||||
->toMatch('/data-md-timepicker-label="hour24" data-md-value="15"\s+data-md-inner\s+style="--x: 1\.0000; --y: -0\.0000"\s*>15</')
|
||||
->toMatch('/data-md-timepicker-label="minute" data-md-value="0"\s+style="[^"]*"\s*>00</')
|
||||
->toMatch('/data-md-timepicker-label="hour12" data-md-value="12"\s+style="--x: 0\.0000; --y: -1\.0000"\s*>12</')
|
||||
->toContain('data-md-timepicker-handle')
|
||||
->toContain('data-md-timepicker-ink')
|
||||
->not->toContain('x-bind:data-md-disabled');
|
||||
});
|
||||
|
||||
it('offers the input variant, the period selector and the actions', function () {
|
||||
@@ -70,19 +70,19 @@ it('offers the input variant, the period selector and the actions', function ()
|
||||
->toContain('inputmode="numeric"')
|
||||
->toContain('aria-describedby="pickup-hour-support"')
|
||||
->toContain('aria-describedby="pickup-minute-support"')
|
||||
->toContain('data-timepicker-period-option="am"')
|
||||
->toContain('data-timepicker-period-option="pm"')
|
||||
->toContain('data-md-timepicker-period-option="am"')
|
||||
->toContain('data-md-timepicker-period-option="pm"')
|
||||
->toContain('aria-label="Select AM or PM"')
|
||||
// M3's labelling table: AM and PM are radios in a list, not toggle buttons.
|
||||
->toContain('role="radiogroup"')
|
||||
->toContain('role="radio"')
|
||||
->toContain('x-on:keydown.arrow-right.prevent="movePeriod($event)"')
|
||||
// The 24-hour selector widens into the room the period selector leaves.
|
||||
->toContain('data-timepicker-display x-bind:data-cycle="is24 ? \'24\' : \'12\'"')
|
||||
->toContain('data-md-timepicker-display x-bind:data-md-cycle="is24 ? \'24\' : \'12\'"')
|
||||
->toContain('aria-label="Switch to text input mode"')
|
||||
->toContain('aria-label="Switch to clock mode"')
|
||||
->toContain('data-timepicker-cancel')
|
||||
->toContain('data-timepicker-confirm')
|
||||
->toContain('data-md-timepicker-cancel')
|
||||
->toContain('data-md-timepicker-confirm')
|
||||
->toContain('>Cancel</span>')
|
||||
->toContain('>OK</span>');
|
||||
});
|
||||
@@ -104,8 +104,8 @@ it('marks what lies outside the limits only when there are limits', function ()
|
||||
$html = (string) $this->blade('<x-timepicker label="Slot" step="15" />');
|
||||
|
||||
expect($html)
|
||||
->toContain('x-bind:data-disabled="hourAllowed(3 + (isPm ? 12 : 0)) ? null : \'\'"')
|
||||
->toContain('x-bind:data-disabled="minuteAllowed(45) ? null : \'\'"');
|
||||
->toContain('x-bind:data-md-disabled="hourAllowed(3 + (isPm ? 12 : 0)) ? null : \'\'"')
|
||||
->toContain('x-bind:data-md-disabled="minuteAllowed(45) ? null : \'\'"');
|
||||
});
|
||||
|
||||
it('writes the first frame as the locale writes the time', function () {
|
||||
@@ -167,11 +167,11 @@ it('puts the field props on the field, its attributes on the input, and posts a
|
||||
->toMatch('/^<div\s+class="w-60"/')
|
||||
->toContain('data-md-variant="filled"')
|
||||
->toContain('data-md-size="sm"')
|
||||
->toContain('data-timepicker-field')
|
||||
->toContain('data-md-timepicker-field')
|
||||
->toContain('required')
|
||||
->toContain('placeholder="hh:mm"')
|
||||
->toContain('<input type="hidden" name="alarm" value="06:30" x-bind:value="value ?? \'\'" />')
|
||||
->toContain('data-md-field-clear')
|
||||
->toMatch('/<button[^>]*data-timepicker-open[^>]*disabled/s')
|
||||
->toMatch('/<button[^>]*data-md-timepicker-open[^>]*disabled/s')
|
||||
->and(substr_count($html, 'class="field w-60"'))->toBe(0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user