Skip to content

Commit e570a85

Browse files
committed
fix(core): a mouse release lands on the hover the control still has
Under spec:AST-094 FR43 the press controller paints a mouse's or a pen's press too, and its colour arms yielded to the press image over the whole release. Under a hovering pointer that hid the hover the control still has: the fade ran toward nothing, dipping toward the resting colour, and the hover snapped back when the attribute went. Now only the press yields over the release: a hovering pointer's hover paints again beneath the fading image (the colour, image and neutral overlay variants, the button press layer, and the card, selectable-card and thumbnail overlay layers, whose hover fades back in on their fast transition). A finger has no hover, so its release still fades to nothing; the pressed-only variant (a text link, a disclosure row) paints no hover and is unchanged. Real Chromium, median brightness 15 ms apart after a hovered release (hover 242, rest 255): list row 236 249 255 244 -> 228 234 241 242; TopNav item 236 247 254 255 -> 230 234 241 242; ClickableCard 236 247 254 249 -> 230 236 242. Button 222 232 239 -> 211 221 227 (hover 228). Under Reduce Motion a link and a disclosure row show no tint. Builds on the yield rule of the press-paint work by vjeux.
1 parent 61cc2f5 commit e570a85

8 files changed

Lines changed: 90 additions & 25 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] A mouse or pen release on a hovered control lands on its hover tint: the hover paints again beneath the fading press, so buttons, list rows, navigation items and cards no longer dip toward their resting colour or flash bare as the press ends.
6+
7+
@cixzhang

‎packages/core/src/ClickableCard/ClickableCard.tsx‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ const styles = stylex.create({
114114
pointerEvents: 'none',
115115
// A press the controller paints shows on its first frame and fades on
116116
// its strength's own animation, so the colour it replaces drops out at
117-
// once rather than crossfading: no transition while it paints. The
118-
// mouse states keep the fast fade.
117+
// once rather than crossfading: no transition while the press is on.
118+
// The mouse states, and the hover returning beneath a fading press,
119+
// keep the fast fade.
119120
transitionProperty: {
120121
default: 'background-color',
121122
[PRESSED_ON]: 'none',
122-
[PRESSED_FADING]: 'none',
123123
},
124124
transitionDuration: durationVars['--duration-fast'],
125125
transitionTimingFunction: easeVars['--ease-standard'],
@@ -129,7 +129,9 @@ const styles = stylex.create({
129129
backgroundColor: {
130130
default: 'var(--_press-overlay)',
131131
[PRESSED_ON]: 'transparent',
132-
[PRESSED_FADING]: 'transparent',
132+
// Over the release only the press yields: a hovering pointer's hover
133+
// fades back in beneath the fading image, so the release lands on it.
134+
[PRESSED_FADING]: 'var(--_press-overlay)',
133135
},
134136
// The press at its strength, which the card's `pressedAlpha` arms own:
135137
// 1 on the first frame of a believed press, then 1 → 0 over the

‎packages/core/src/SelectableCard/SelectableCard.tsx‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ const styles = stylex.create({
119119
pointerEvents: 'none',
120120
// A press the controller paints shows on its first frame and fades on
121121
// its strength's own animation, so the colour it replaces drops out at
122-
// once rather than crossfading: no transition while it paints. The
123-
// mouse states keep the fast fade.
122+
// once rather than crossfading: no transition while the press is on.
123+
// The mouse states, and the hover returning beneath a fading press,
124+
// keep the fast fade.
124125
transitionProperty: {
125126
default: 'background-color',
126127
[PRESSED_ON]: 'none',
127-
[PRESSED_FADING]: 'none',
128128
},
129129
transitionDuration: durationVars['--duration-fast'],
130130
transitionTimingFunction: easeVars['--ease-standard'],
@@ -134,7 +134,9 @@ const styles = stylex.create({
134134
backgroundColor: {
135135
default: 'var(--_press-overlay)',
136136
[PRESSED_ON]: 'transparent',
137-
[PRESSED_FADING]: 'transparent',
137+
// Over the release only the press yields: a hovering pointer's hover
138+
// fades back in beneath the fading image, so the release lands on it.
139+
[PRESSED_FADING]: 'var(--_press-overlay)',
138140
},
139141
// The press at its strength, which the card's `pressedAlpha` arms own:
140142
// 1 on the first frame of a believed press, then 1 → 0 over the

‎packages/core/src/Thumbnail/Thumbnail.tsx‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,12 @@ const styles = stylex.create({
217217
pointerEvents: 'none',
218218
// A press the controller paints shows on its first frame and fades on
219219
// its strength's own animation, so the colour it replaces drops out at
220-
// once rather than crossfading: no transition while it paints. The
221-
// mouse states keep the fast fade.
220+
// once rather than crossfading: no transition while the press is on.
221+
// The mouse states, and the hover returning beneath a fading press,
222+
// keep the fast fade.
222223
transitionProperty: {
223224
default: 'background-color',
224225
[PRESSED_ON]: 'none',
225-
[PRESSED_FADING]: 'none',
226226
},
227227
transitionDuration: durationVars['--duration-fast'],
228228
transitionTimingFunction: easeVars['--ease-standard'],
@@ -232,7 +232,9 @@ const styles = stylex.create({
232232
backgroundColor: {
233233
default: 'var(--_press-overlay)',
234234
[PRESSED_ON]: 'transparent',
235-
[PRESSED_FADING]: 'transparent',
235+
// Over the release only the press yields: a hovering pointer's hover
236+
// fades back in beneath the fading image, so the release lands on it.
237+
[PRESSED_FADING]: 'var(--_press-overlay)',
236238
},
237239
// The press at its strength, which the container's `pressedAlpha` arms
238240
// own: 1 on the first frame of a believed press, then 1 → 0 over the

‎packages/core/src/__tests__/pressState.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,11 @@ export function readsPressStrength(el: Element, arm = FADING_ARM): boolean {
183183
/**
184184
* Does the element's `::after` paint the press the controller writes as its
185185
* image while `arm` matches (`var(--_press-paint-image)`), with the layer's
186-
* own colour yielding to it (`transparent`) on the same arm? A card's overlay
187-
* layer paints this way; `arm` defaults to the release's.
186+
* own colour yielding to it on the same arm? A card's overlay layer paints
187+
* this way; `arm` defaults to the release's. While the press is on the colour
188+
* is `transparent`; over the release it is the layer's hover-or-nothing
189+
* colour (`var(--_press-overlay)`, `:active` no longer matching), so a
190+
* hovering pointer's hover returns beneath the fading image.
188191
*/
189192
export function afterPaintsPress(el: Element, arm = FADING_ARM): boolean {
190193
const rules = rulesWithSelector(el, arm).filter(rule =>
@@ -195,7 +198,12 @@ export function afterPaintsPress(el: Element, arm = FADING_ARM): boolean {
195198
/background-image:[^;}]*(--_press-paint-image|--color-overlay-pressed)/.test(
196199
rule,
197200
),
198-
) && rules.some(rule => /background-color:\s*transparent/.test(rule))
201+
) &&
202+
rules.some(rule =>
203+
arm === FADING_ARM
204+
? /background-color:\s*var\(--_press-overlay\)/.test(rule)
205+
: /background-color:\s*transparent/.test(rule),
206+
)
199207
);
200208
}
201209

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,16 @@ export const controlPressLayerStyles = stylex.create({
128128
default: null,
129129
...pointerImageArms,
130130
[PRESSED_ON]: {default: pressedOverlayImage, [COARSE]: 'none'},
131-
[PRESSED_FADING]: {default: pressedOverlayImage, [COARSE]: 'none'},
131+
// Over the release a hovering pointer's hover paints beneath the
132+
// fading image, so the release lands on it (interactionOverlay).
133+
[PRESSED_FADING]: {
134+
default: pressedOverlayImage,
135+
[COARSE]: 'none',
136+
[HOVER_HOVER]: {
137+
default: pressedOverlayImage,
138+
':hover': `${pressedOverlayImage}, ${hoverImage}`,
139+
},
140+
},
132141
},
133142
},
134143
...strengthReleaseOutsideCoarse,

‎packages/core/src/utils/interactionOverlay.stylex.ts‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
* deselect crossfade; the controller removes the attribute when the same
5656
* clock runs out, and by then the paint is gone). It fades to nothing, not
5757
* to the hover strength: under a finger there is no hover to land on.
58+
* Under a hovering mouse or pen the hover arm paints again beneath the
59+
* fading image (only the press yields while `fading`), so the release
60+
* lands on the hover the control still has, with no dip toward its rest
61+
* and no bare frame when the attribute goes.
5862
*
5963
* WHY AN ANIMATION AND NOT A TRANSITION. Two reasons, both about composers.
6064
* StyleX is last-wins per property, and composers own their `transition-*`
@@ -325,9 +329,17 @@ export const interactionOverlayStyles = stylex.create({
325329
// While the controller paints, the colour arms yield to the image. A
326330
// device with a touchscreen beside a mouse matches `:active` and the
327331
// emulated `:hover` under a finger too, and the press would otherwise
328-
// paint twice.
332+
// paint twice. Over the release only the press yields: a hovering
333+
// pointer's hover paints beneath the fading image, so the release
334+
// lands on it.
329335
[PRESSED_ON]: 'transparent',
330-
[PRESSED_FADING]: 'transparent',
336+
[PRESSED_FADING]: {
337+
default: 'transparent',
338+
[HOVER_HOVER]: {
339+
default: 'transparent',
340+
':hover': colorVars['--color-overlay-hover'],
341+
},
342+
},
331343
},
332344
},
333345
backgroundImage: {
@@ -349,7 +361,15 @@ export const interactionOverlayStyles = stylex.create({
349361
default: null,
350362
...pointerImageArms,
351363
[PRESSED_ON]: pressedOverlayImage,
352-
[PRESSED_FADING]: pressedOverlayImage,
364+
// Over the release a hovering pointer's hover paints beneath the
365+
// fading image; see the colour variant above.
366+
[PRESSED_FADING]: {
367+
default: pressedOverlayImage,
368+
[HOVER_HOVER]: {
369+
default: pressedOverlayImage,
370+
':hover': `${pressedOverlayImage}, ${hoverImage}`,
371+
},
372+
},
353373
},
354374
},
355375
},
@@ -371,7 +391,13 @@ export const interactionOverlayStyles = stylex.create({
371391
':active': `${pressedImage}, ${neutralImage}`,
372392
},
373393
[PRESSED_ON]: `${pressedOverlayImage}, ${neutralImage}`,
374-
[PRESSED_FADING]: `${pressedOverlayImage}, ${neutralImage}`,
394+
[PRESSED_FADING]: {
395+
default: `${pressedOverlayImage}, ${neutralImage}`,
396+
[HOVER_HOVER]: {
397+
default: `${pressedOverlayImage}, ${neutralImage}`,
398+
':hover': `${pressedOverlayImage}, ${hoverImage}, ${neutralImage}`,
399+
},
400+
},
375401
},
376402
},
377403
},

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,14 +1377,23 @@ describe('the release fades: the arms the controller writes to', () => {
13771377
`${variant} ${arm}`,
13781378
).toBe(true);
13791379
}
1380-
// ...and lands on nothing, not on the hover strength: under a finger
1381-
// there is no hover.
1380+
// ...and the press lands on nothing, not on the hover strength: under
1381+
// a finger there is no hover. Only a hovering pointer's own hover arm
1382+
// paints beneath the fading image, so a mouse release lands on it.
1383+
const fading = rulesWithSelector(element, '[data-astryx-press="fading"]');
13821384
expect(
1383-
rulesWithSelector(element, '[data-astryx-press="fading"]').some(rule =>
1384-
rule.includes('--color-overlay-hover'),
1385+
fading
1386+
.filter(rule => rule.includes('--color-overlay-hover'))
1387+
.every(rule => rule.includes(':hover')),
1388+
variant,
1389+
).toBe(true);
1390+
expect(
1391+
fading.some(
1392+
rule =>
1393+
rule.includes(':hover') && rule.includes('--color-overlay-hover'),
13851394
),
13861395
variant,
1387-
).toBe(false);
1396+
).toBe(variant !== 'pressedBackgroundColor');
13881397
}
13891398
});
13901399

0 commit comments

Comments
 (0)