Skip to content

Commit abde23b

Browse files
committed
fix(AlertDialog): a released action fades on the theme's tempo, as other presses do
Under the touch presentation, AlertDialog's action-group tracker took the press off a released action on a fixed 200 ms timer. The stylesheet's release runs 200 ms times the theme's tempo (up to 1.5), and the press controller's own timer follows it, so under a slower tempo the fade snapped off before it ended. The tracker now times its release fades with the press controller's clock (pressFadeMs, exported from pressFeedback.ts), which also keeps the Reduce Motion cap.
1 parent 36cde5e commit abde23b

4 files changed

Lines changed: 64 additions & 6 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] AlertDialog: under the touch presentation, the action a finger or pen lifts on now fades for the theme's full release time, as every other press does, instead of cutting off at 200 ms under a slower motion tempo.
6+
7+
@vjeux

‎packages/core/src/hooks/actionGroupTracker.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,55 @@ describe('createActionGroupTracker', () => {
240240
]);
241241
});
242242

243+
it('times the release fade by the tempo its stylesheet reads, as the press controller does (spec:AST-108 FR4)', () => {
244+
// A rule writes the tempo; browsers inherit it from the theme, jsdom
245+
// only reads it where it is declared.
246+
const style = document.createElement('style');
247+
style.textContent = '[data-action] { --_astryx-motion-tempo: 1.5; }';
248+
document.head.append(style);
249+
try {
250+
const group = tracker();
251+
group.begin(100, 20);
252+
group.end();
253+
vi.advanceTimersByTime(PRESS_FADE_MS);
254+
expect(first.button.getAttribute(PRESSED_ATTRIBUTE)).toBe('fading');
255+
vi.advanceTimersByTime(PRESS_FADE_MS / 2);
256+
expect(first.button.hasAttribute(PRESSED_ATTRIBUTE)).toBe(false);
257+
} finally {
258+
style.remove();
259+
}
260+
});
261+
262+
it('under Reduce Motion a tempo may shorten the release fade but never lengthens it past 200 ms (spec:AST-108 FR4)', () => {
263+
vi.stubGlobal(
264+
'matchMedia',
265+
(query: string): MediaQueryList =>
266+
({
267+
matches: /prefers-reduced-motion:\s*reduce/.test(query),
268+
media: query,
269+
onchange: null,
270+
addListener: () => undefined,
271+
removeListener: () => undefined,
272+
addEventListener: () => undefined,
273+
removeEventListener: () => undefined,
274+
dispatchEvent: () => false,
275+
}) as MediaQueryList,
276+
);
277+
const style = document.createElement('style');
278+
style.textContent = '[data-action] { --_astryx-motion-tempo: 1.5; }';
279+
document.head.append(style);
280+
try {
281+
const group = tracker();
282+
group.begin(100, 20);
283+
group.end();
284+
vi.advanceTimersByTime(PRESS_FADE_MS);
285+
expect(first.button.hasAttribute(PRESSED_ATTRIBUTE)).toBe(false);
286+
} finally {
287+
style.remove();
288+
vi.unstubAllGlobals();
289+
}
290+
});
291+
243292
it('dispose finishes a pending release fade', () => {
244293
const group = tracker();
245294
group.begin(100, 20);

‎packages/core/src/hooks/actionGroupTracker.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @file actionGroupTracker.ts
55
* @input The tracked elements, the action selector and hit expansion, and the
6-
* press paint and fade clocks
6+
* press paint and the press controller's fade clock
77
* @output createActionGroupTracker, ActionGroupTracker,
88
* ActionGroupTrackerOptions, ActionGroupTarget
99
* @position Internal core tracker for a held finger that slides across a
@@ -14,8 +14,7 @@
1414

1515
import {clickAndReport, clickForLift} from '../utils/browserClickWait';
1616
import {armClickGuard} from '../utils/clickGuard';
17-
import {PRESSED_ATTRIBUTE} from '../utils/pressFeedback';
18-
import {PRESS_FADE_MS} from '../utils/pressGesture';
17+
import {PRESSED_ATTRIBUTE, pressFadeMs} from '../utils/pressFeedback';
1918

2019
/** An action that is not enabled takes no highlight and does not run. */
2120
const DISABLED = ':disabled, [aria-disabled="true"]';
@@ -193,14 +192,16 @@ export function createActionGroupTracker(
193192
}
194193
clearFade(element);
195194
element.setAttribute(PRESSED_ATTRIBUTE, 'fading');
195+
// The stylesheet's release follows the theme's tempo, so the fade ends on
196+
// the press controller's clock.
196197
fades.set(
197198
element,
198199
setTimeout(() => {
199200
fades.delete(element);
200201
if (element.getAttribute(PRESSED_ATTRIBUTE) === 'fading') {
201202
element.removeAttribute(PRESSED_ATTRIBUTE);
202203
}
203-
}, PRESS_FADE_MS),
204+
}, pressFadeMs(element)),
204205
);
205206
};
206207

‎packages/core/src/utils/pressFeedback.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ const TIMER_MS: Record<NonNullable<PressStep['timer']>, number> = {
152152
* The release fade's clock on `element`, read once, at the release, from the
153153
* property its stylesheet reads: the theme's `--_astryx-motion-tempo`. Under
154154
* Reduce Motion a tempo may shorten the fade, never lengthen it past 200 ms.
155+
* A group's tracker times its own release fades with it too.
155156
*/
156-
function fadeMs(element: Element): number {
157+
export function pressFadeMs(element: Element): number {
157158
const style = getComputedStyle(element);
158159
const value = style.getPropertyValue('--_astryx-motion-tempo').trim();
159160
const read = value === '' ? Number.NaN : Number(value);
@@ -234,7 +235,7 @@ function apply(slot: Slot, step: PressStep): void {
234235
},
235236
// The release fade follows the theme's tempo (AST-108). The onset delay
236237
// and the tap flash do not.
237-
kind === 'fade' ? fadeMs(live.element) : TIMER_MS[kind],
238+
kind === 'fade' ? pressFadeMs(live.element) : TIMER_MS[kind],
238239
);
239240
}
240241
}

0 commit comments

Comments
 (0)