88 */
99
1010import type { A11yIssue , CustomRulesConfig } from '../types/types'
11+ import type { SeverityThreshold } from '../types/types'
12+ import { meetsThreshold } from './ally-audit.utils'
1113
1214/**
1315 * Interactive HTML elements that can receive focus and have implicit roles
@@ -332,6 +334,7 @@ function getSelector(element: Element): string {
332334 */
333335function checkClickHandlerOnNonInteractive (
334336 context : Document | Element = document ,
337+ threshold : SeverityThreshold = 'serious' ,
335338) : Array < A11yIssue > {
336339 const issues : Array < A11yIssue > = [ ]
337340 const timestamp = Date . now ( )
@@ -385,7 +388,7 @@ function checkClickHandlerOnNonInteractive(
385388 html : element . outerHTML . slice ( 0 , 200 ) ,
386389 } ,
387390 ] ,
388- meetsThreshold : true ,
391+ meetsThreshold : meetsThreshold ( 'serious' , threshold ) ,
389392 timestamp,
390393 } )
391394 } else if ( hasFocus && ! hasKeyboard ) {
@@ -407,7 +410,7 @@ function checkClickHandlerOnNonInteractive(
407410 html : element . outerHTML . slice ( 0 , 200 ) ,
408411 } ,
409412 ] ,
410- meetsThreshold : true ,
413+ meetsThreshold : meetsThreshold ( 'moderate' , threshold ) ,
411414 timestamp,
412415 } )
413416 }
@@ -424,9 +427,12 @@ function checkClickHandlerOnNonInteractive(
424427 */
425428function checkMouseOnlyEvents (
426429 context : Document | Element = document ,
430+ threshold : SeverityThreshold = 'serious' ,
427431) : Array < A11yIssue > {
428432 const issues : Array < A11yIssue > = [ ]
429433 const timestamp = Date . now ( )
434+ // default threshold will be provided by runCustomRules
435+ // We'll accept threshold by adding a parameter in the function signature
430436
431437 // Build selector for elements with mouse events
432438 const mouseEventSelectors = MOUSE_ONLY_EVENTS . map (
@@ -473,7 +479,7 @@ function checkMouseOnlyEvents(
473479 html : element . outerHTML . slice ( 0 , 200 ) ,
474480 } ,
475481 ] ,
476- meetsThreshold : true ,
482+ meetsThreshold : meetsThreshold ( 'serious' , threshold ) ,
477483 timestamp,
478484 } )
479485 }
@@ -489,6 +495,7 @@ function checkMouseOnlyEvents(
489495 */
490496function checkStaticElementInteraction (
491497 context : Document | Element = document ,
498+ threshold : SeverityThreshold = 'serious' ,
492499) : Array < A11yIssue > {
493500 const issues : Array < A11yIssue > = [ ]
494501 const timestamp = Date . now ( )
@@ -533,7 +540,7 @@ function checkStaticElementInteraction(
533540 html : element . outerHTML . slice ( 0 , 200 ) ,
534541 } ,
535542 ] ,
536- meetsThreshold : true ,
543+ meetsThreshold : meetsThreshold ( 'serious' , threshold ) ,
537544 timestamp,
538545 } )
539546 }
@@ -562,7 +569,7 @@ function checkStaticElementInteraction(
562569 html : element . outerHTML . slice ( 0 , 200 ) ,
563570 } ,
564571 ] ,
565- meetsThreshold : true ,
572+ meetsThreshold : meetsThreshold ( 'moderate' , threshold ) ,
566573 timestamp,
567574 } )
568575 }
@@ -577,6 +584,7 @@ function checkStaticElementInteraction(
577584export function runCustomRules (
578585 context : Document | Element = document ,
579586 config : CustomRulesConfig = { } ,
587+ threshold : SeverityThreshold = 'serious' ,
580588) : Array < A11yIssue > {
581589 const {
582590 clickHandlerOnNonInteractive = true ,
@@ -587,15 +595,15 @@ export function runCustomRules(
587595 const issues : Array < A11yIssue > = [ ]
588596
589597 if ( clickHandlerOnNonInteractive ) {
590- issues . push ( ...checkClickHandlerOnNonInteractive ( context ) )
598+ issues . push ( ...checkClickHandlerOnNonInteractive ( context , threshold ) )
591599 }
592600
593601 if ( mouseOnlyEventHandlers ) {
594- issues . push ( ...checkMouseOnlyEvents ( context ) )
602+ issues . push ( ...checkMouseOnlyEvents ( context , threshold ) )
595603 }
596604
597605 if ( staticElementInteraction ) {
598- issues . push ( ...checkStaticElementInteraction ( context ) )
606+ issues . push ( ...checkStaticElementInteraction ( context , threshold ) )
599607 }
600608
601609 return issues
0 commit comments