@@ -28,10 +28,12 @@ import {
2828 pressConsts ,
2929} from './interactionOverlay.stylex' ;
3030import {
31+ PRESS_GROUP_ITEM_ATTRIBUTE ,
3132 PRESSABLE_ATTRIBUTE ,
3233 PRESSED_ATTRIBUTE ,
3334 installPressFeedback ,
3435 paintPress ,
36+ pressGroupItemProps ,
3537} from './pressFeedback' ;
3638import {
3739 PRESS_FADE_MS ,
@@ -281,6 +283,66 @@ describe('the press reaches the surface the finger landed on', () => {
281283 } ) ;
282284} ) ;
283285
286+ describe ( 'an action group whose own tracker paints its actions' , ( ) => {
287+ // family:action-groups: the group's tracker follows a held pointer across
288+ // its actions and paints them; the controller must not write the press
289+ // attribute there too.
290+ function group ( ) : { actions : HTMLElement [ ] ; field : HTMLElement } {
291+ const root = document . createElement ( 'div' ) ;
292+ const actions = [ pressable ( 'button' ) , pressable ( 'button' ) ] ;
293+ for ( const action of actions ) {
294+ for ( const [ name , value ] of Object . entries ( pressGroupItemProps ) ) {
295+ action . setAttribute ( name , value ) ;
296+ }
297+ root . appendChild ( action ) ;
298+ }
299+ // A member the tracker skips (a menu trigger) carries no marker.
300+ const field = pressable ( 'button' ) ;
301+ root . appendChild ( field ) ;
302+ document . body . appendChild ( root ) ;
303+ return { actions, field} ;
304+ }
305+
306+ it ( 'paints nothing on an action its group tracks' , ( ) => {
307+ const { actions} = group ( ) ;
308+ expect ( actions [ 0 ] . hasAttribute ( PRESS_GROUP_ITEM_ATTRIBUTE ) ) . toBe ( true ) ;
309+ press ( actions [ 0 ] , 'pointerdown' , 10 , 10 ) ;
310+ vi . advanceTimersByTime ( PRESS_ONSET_MS ) ;
311+ press ( actions [ 0 ] , 'pointerup' , 10 , 10 ) ;
312+ vi . advanceTimersByTime ( PRESS_FLASH_MS ) ;
313+ expect ( actions [ 0 ] . hasAttribute ( PRESSED_ATTRIBUTE ) ) . toBe ( false ) ;
314+ } ) ;
315+
316+ it ( 'leaves the paint the group writes on it alone' , ( ) => {
317+ const { actions} = group ( ) ;
318+ actions [ 1 ] . setAttribute ( PRESSED_ATTRIBUTE , 'on' ) ;
319+ press ( actions [ 1 ] , 'pointerdown' , 10 , 10 ) ;
320+ vi . advanceTimersByTime ( PRESS_ONSET_MS ) ;
321+ press ( actions [ 1 ] , 'pointercancel' , 10 , 10 ) ;
322+ expect ( actions [ 1 ] . getAttribute ( PRESSED_ATTRIBUTE ) ) . toBe ( 'on' ) ;
323+ } ) ;
324+
325+ it ( 'still paints a member the group does not track' , ( ) => {
326+ const { field} = group ( ) ;
327+ press ( field , 'pointerdown' , 10 , 10 ) ;
328+ vi . advanceTimersByTime ( PRESS_ONSET_MS ) ;
329+ expect ( field . getAttribute ( PRESSED_ATTRIBUTE ) ) . toBe ( 'on' ) ;
330+ } ) ;
331+
332+ it ( 'still records the touch, so a scroll it drives brakes the next one' , ( ) => {
333+ const { actions} = group ( ) ;
334+ scroller . appendChild ( actions [ 0 ] . parentElement as HTMLElement ) ;
335+ press ( actions [ 0 ] , 'pointerdown' , 10 , 10 ) ;
336+ // The browser takes the touch to scroll: the cancel records nothing, so
337+ // the touch-down alone must have recorded the finger.
338+ press ( actions [ 0 ] , 'pointercancel' , 10 , 10 ) ;
339+ scroller . dispatchEvent ( new Event ( 'scroll' ) ) ;
340+ press ( rows [ 1 ] , 'pointerdown' , 10 , 100 ) ;
341+ vi . advanceTimersByTime ( PRESS_ONSET_MS * 2 ) ;
342+ expect ( pressedRow ( ) ) . toBe ( - 1 ) ;
343+ } ) ;
344+ } ) ;
345+
284346describe ( 'a scroll takes it away and nothing brings it back' , ( ) => {
285347 it ( 'clears on a scroll from the ancestor scroller' , ( ) => {
286348 press ( rows [ 1 ] , 'pointerdown' , 10 , 10 ) ;
@@ -869,6 +931,32 @@ describe('a phone or tablet paints a mouse or Space press itself', () => {
869931 expect ( rows [ 1 ] . hasAttribute ( PRESSED_ATTRIBUTE ) ) . toBe ( false ) ;
870932 } ) ;
871933
934+ function groupAction ( row : HTMLElement ) : HTMLButtonElement {
935+ const action = focusedButton ( row ) ;
936+ for ( const [ name , value ] of Object . entries ( pressGroupItemProps ) ) {
937+ action . setAttribute ( name , value ) ;
938+ }
939+ return action ;
940+ }
941+
942+ it ( "leaves a mouse press on an action its group tracks to the group's tracker (family:action-groups)" , ( ) => {
943+ const action = groupAction ( rows [ 1 ] ) ;
944+ press ( action , 'pointerdown' , 10 , 100 , 'mouse' ) ;
945+ expect ( action . hasAttribute ( PRESSED_ATTRIBUTE ) ) . toBe ( false ) ;
946+ // The tracker's own paint is left alone through the release.
947+ action . setAttribute ( PRESSED_ATTRIBUTE , 'on' ) ;
948+ press ( action , 'pointerup' , 10 , 100 , 'mouse' ) ;
949+ expect ( action . getAttribute ( PRESSED_ATTRIBUTE ) ) . toBe ( 'on' ) ;
950+ } ) ;
951+
952+ it ( 'still paints a Space press on a focused action its group tracks: the group tracks pointers only' , ( ) => {
953+ const action = groupAction ( rows [ 1 ] ) ;
954+ key ( action , 'keydown' ) ;
955+ expect ( action . getAttribute ( PRESSED_ATTRIBUTE ) ) . toBe ( 'on' ) ;
956+ key ( action , 'keyup' ) ;
957+ expect ( action . getAttribute ( PRESSED_ATTRIBUTE ) ) . toBe ( 'fading' ) ;
958+ } ) ;
959+
872960 it ( 'keeps the paint while the mouse is dragged off the surface, as `:active` does' , ( ) => {
873961 press ( rows [ 1 ] , 'pointerdown' , 10 , 100 , 'mouse' ) ;
874962 press ( document . body , 'pointermove' , 400 , 900 , 'mouse' ) ;
0 commit comments