Skip to content

Commit 5b57bd6

Browse files
mohammedzamakhanmgechev
authored andcommitted
fix(rule): template-click-events-have-key-events - support pseudo events (#893)
1 parent 5a80e90 commit 5b57bd6

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/templateClickEventsHaveKeyEventsRule.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ class TemplateVisitorCtrl extends BasicTemplateAstVisitor {
5656
if (isInteractiveElement(el)) {
5757
return;
5858
}
59-
60-
const hasKeyEvent = el.outputs.some(output => output.name === 'keyup' || output.name === 'keydown' || output.name === 'keypress');
59+
const hasKeyEvent = el.outputs.some(
60+
output => output.name.startsWith('keyup') || output.name.startsWith('keydown') || output.name.startsWith('keypress')
61+
);
6162

6263
if (hasKeyEvent) {
6364
return;

test/templateClickEventsHaveKeyEventsRule.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ describe(ruleName, () => {
158158
assertSuccess(ruleName, source);
159159
});
160160

161+
it('should work when click events are associated with key pseudo events', () => {
162+
const source = `
163+
@Component({
164+
template: \`
165+
<div (click)="onClick()" (keyup.enter)="onKeyup()"></div>
166+
\`
167+
})
168+
class Bar {}
169+
`;
170+
assertSuccess(ruleName, source);
171+
});
172+
161173
it('should work when click events are passed to custom element', () => {
162174
const source = `
163175
@Component({

0 commit comments

Comments
 (0)