@@ -295,11 +295,13 @@ export const A11yContextProvider: FC<PropsWithChildren> = (props) => {
295295 setStatus ( getInitialStatus ( manual ) ) ;
296296 } , [ getInitialStatus , manual ] ) ;
297297
298+ const isInitial = status === 'initial' ;
299+
298300 useEffect ( ( ) => {
299301 emit ( REMOVE_HIGHLIGHT , `${ ADDON_ID } /selected` ) ;
300302 emit ( REMOVE_HIGHLIGHT , `${ ADDON_ID } /others` ) ;
301303
302- if ( ! highlighted ) {
304+ if ( ! highlighted || isInitial ) {
303305 return ;
304306 }
305307
@@ -312,84 +314,88 @@ export const A11yContextProvider: FC<PropsWithChildren> = (props) => {
312314 const target = result ?. nodes [ Number ( number ) - 1 ] ?. target ;
313315 return target ? [ String ( target ) ] : [ ] ;
314316 } ) ;
315- emit ( HIGHLIGHT , {
316- id : `${ ADDON_ID } /selected` ,
317- priority : 1 ,
318- selectors : selected ,
319- styles : {
320- outline : `1px solid color-mix(in srgb, ${ colorsByType [ tab ] } , transparent 30%)` ,
321- backgroundColor : 'transparent' ,
322- } ,
323- hoverStyles : {
324- outlineWidth : '2px' ,
325- } ,
326- focusStyles : {
327- backgroundColor : 'transparent' ,
328- } ,
329- menu : results ?. [ tab as RuleType ] . map < HighlightMenuItem [ ] > ( ( result ) => {
330- const selectors = result . nodes
331- . flatMap ( ( n ) => n . target )
332- . map ( String )
333- . filter ( ( e ) => selected . includes ( e ) ) ;
334- return [
335- {
336- id : `${ tab } .${ result . id } :info` ,
337- title : getTitleForAxeResult ( result ) ,
338- description : getFriendlySummaryForAxeResult ( result ) ,
339- selectors,
340- } ,
341- {
342- id : `${ tab } .${ result . id } ` ,
343- iconLeft : 'info' ,
344- iconRight : 'shareAlt' ,
345- title : 'Learn how to resolve this violation' ,
346- clickEvent : EVENTS . SELECT ,
347- selectors,
348- } ,
349- ] ;
350- } ) ,
351- } ) ;
317+ if ( selected . length ) {
318+ emit ( HIGHLIGHT , {
319+ id : `${ ADDON_ID } /selected` ,
320+ priority : 1 ,
321+ selectors : selected ,
322+ styles : {
323+ outline : `1px solid color-mix(in srgb, ${ colorsByType [ tab ] } , transparent 30%)` ,
324+ backgroundColor : 'transparent' ,
325+ } ,
326+ hoverStyles : {
327+ outlineWidth : '2px' ,
328+ } ,
329+ focusStyles : {
330+ backgroundColor : 'transparent' ,
331+ } ,
332+ menu : results ?. [ tab as RuleType ] . map < HighlightMenuItem [ ] > ( ( result ) => {
333+ const selectors = result . nodes
334+ . flatMap ( ( n ) => n . target )
335+ . map ( String )
336+ . filter ( ( e ) => selected . includes ( e ) ) ;
337+ return [
338+ {
339+ id : `${ tab } .${ result . id } :info` ,
340+ title : getTitleForAxeResult ( result ) ,
341+ description : getFriendlySummaryForAxeResult ( result ) ,
342+ selectors,
343+ } ,
344+ {
345+ id : `${ tab } .${ result . id } ` ,
346+ iconLeft : 'info' ,
347+ iconRight : 'shareAlt' ,
348+ title : 'Learn how to resolve this violation' ,
349+ clickEvent : EVENTS . SELECT ,
350+ selectors,
351+ } ,
352+ ] ;
353+ } ) ,
354+ } ) ;
355+ }
352356
353357 const others = results ?. [ tab as RuleType ]
354358 . flatMap ( ( r ) => r . nodes . flatMap ( ( n ) => n . target ) . map ( String ) )
355359 . filter ( ( e ) => ! [ ...unhighlightedSelectors , ...selected ] . includes ( e ) ) ;
356- emit ( HIGHLIGHT , {
357- id : `${ ADDON_ID } /others` ,
358- selectors : others ,
359- styles : {
360- outline : `1px solid color-mix(in srgb, ${ colorsByType [ tab ] } , transparent 30%)` ,
361- backgroundColor : `color-mix(in srgb, ${ colorsByType [ tab ] } , transparent 60%)` ,
362- } ,
363- hoverStyles : {
364- outlineWidth : '2px' ,
365- } ,
366- focusStyles : {
367- backgroundColor : 'transparent' ,
368- } ,
369- menu : results ?. [ tab as RuleType ] . map < HighlightMenuItem [ ] > ( ( result ) => {
370- const selectors = result . nodes
371- . flatMap ( ( n ) => n . target )
372- . map ( String )
373- . filter ( ( e ) => ! selected . includes ( e ) ) ;
374- return [
375- {
376- id : `${ tab } .${ result . id } :info` ,
377- title : getTitleForAxeResult ( result ) ,
378- description : getFriendlySummaryForAxeResult ( result ) ,
379- selectors,
380- } ,
381- {
382- id : `${ tab } .${ result . id } ` ,
383- iconLeft : 'info' ,
384- iconRight : 'shareAlt' ,
385- title : 'Learn how to resolve this violation' ,
386- clickEvent : EVENTS . SELECT ,
387- selectors,
388- } ,
389- ] ;
390- } ) ,
391- } ) ;
392- } , [ emit , highlighted , results , tab , selectedItems ] ) ;
360+ if ( others ?. length ) {
361+ emit ( HIGHLIGHT , {
362+ id : `${ ADDON_ID } /others` ,
363+ selectors : others ,
364+ styles : {
365+ outline : `1px solid color-mix(in srgb, ${ colorsByType [ tab ] } , transparent 30%)` ,
366+ backgroundColor : `color-mix(in srgb, ${ colorsByType [ tab ] } , transparent 60%)` ,
367+ } ,
368+ hoverStyles : {
369+ outlineWidth : '2px' ,
370+ } ,
371+ focusStyles : {
372+ backgroundColor : 'transparent' ,
373+ } ,
374+ menu : results ?. [ tab as RuleType ] . map < HighlightMenuItem [ ] > ( ( result ) => {
375+ const selectors = result . nodes
376+ . flatMap ( ( n ) => n . target )
377+ . map ( String )
378+ . filter ( ( e ) => ! selected . includes ( e ) ) ;
379+ return [
380+ {
381+ id : `${ tab } .${ result . id } :info` ,
382+ title : getTitleForAxeResult ( result ) ,
383+ description : getFriendlySummaryForAxeResult ( result ) ,
384+ selectors,
385+ } ,
386+ {
387+ id : `${ tab } .${ result . id } ` ,
388+ iconLeft : 'info' ,
389+ iconRight : 'shareAlt' ,
390+ title : 'Learn how to resolve this violation' ,
391+ clickEvent : EVENTS . SELECT ,
392+ selectors,
393+ } ,
394+ ] ;
395+ } ) ,
396+ } ) ;
397+ }
398+ } , [ isInitial , emit , highlighted , results , tab , selectedItems ] ) ;
393399
394400 const discrepancy : TestDiscrepancy = useMemo ( ( ) => {
395401 if ( ! currentStoryA11yStatusValue ) {
0 commit comments