Skip to content

Commit

Permalink
SONARHTML-145 MouseEventWithoutKeyboardEquivalentCheck should not rai…
Browse files Browse the repository at this point in the history
…se on clickable lightning buttons (#188)
  • Loading branch information
yassin-kammoun-sonarsource authored Nov 19, 2021
1 parent 65cd104 commit 637022c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void startElement(TagNode node) {
}

private static boolean isException(TagNode node) {
return (isInput(node) || isButton(node) || isHyperlink(node)) && hasOnClick(node) && !hasButtonRole(node);
return isClickableLightningButton(node) || ((isInput(node) || isButton(node) || isHyperlink(node)) && hasOnClick(node) && !hasButtonRole(node));
}

private static boolean hasOnClick(TagNode node) {
Expand Down Expand Up @@ -122,6 +122,12 @@ private static boolean isHyperlink(TagNode node) {
return "A".equalsIgnoreCase(node.getNodeName());
}

private static boolean isClickableLightningButton(TagNode node) {
return "LIGHTNING-BUTTON".equalsIgnoreCase(node.getNodeName())
|| "LIGHTNING-BUTTON-ICON".equalsIgnoreCase(node.getNodeName())
|| "LIGHTNING-BUTTON-MENU".equalsIgnoreCase(node.getNodeName());
}

private static boolean hasAngularKeyDownWithKeyName(TagNode node) {
return node.getAttributes().stream().anyMatch(a -> KEY_DOWN_WITH_KEY_NAME.matcher(a.getName()).find());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@
<div (click)="doSomething();" (keydown.shift.control.z)="doSomething();"></div> <!-- Compliant -->
<div (click)="doSomething();" (keydown.undefinedkeyname)="doSomething();"></div> <!-- Non-Compliant - too long key name -->
<div (click)="doSomething();" (keydown.1.2.3.4.5.6)="doSomething();"></div> <!-- Non-Compliant - unrealistic key combination -->

<lightning-button onclick={doSomething}></lightning-button> <!-- Compliant -->
<lightning-button-icon onclick={doSomething}></lightning-button-icon> <!-- Compliant -->
<lightning-button-menu onclick={doSomething}></lightning-button-menu> <!-- Compliant -->

0 comments on commit 637022c

Please sign in to comment.