Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rule): template-click-events-have-key-events - support pseudo events #893

Merged
merged 1 commit into from Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/templateClickEventsHaveKeyEventsRule.ts
Expand Up @@ -56,8 +56,9 @@ class TemplateVisitorCtrl extends BasicTemplateAstVisitor {
if (isInteractiveElement(el)) {
return;
}

const hasKeyEvent = el.outputs.some(output => output.name === 'keyup' || output.name === 'keydown' || output.name === 'keypress');
const hasKeyEvent = el.outputs.some(
output => output.name.startsWith('keyup') || output.name.startsWith('keydown') || output.name.startsWith('keypress')
);

if (hasKeyEvent) {
return;
Expand Down
12 changes: 12 additions & 0 deletions test/templateClickEventsHaveKeyEventsRule.spec.ts
Expand Up @@ -158,6 +158,18 @@ describe(ruleName, () => {
assertSuccess(ruleName, source);
});

it('should work when click events are associated with key pseudo events', () => {
const source = `
@Component({
template: \`
<div (click)="onClick()" (keyup.enter)="onKeyup()"></div>
\`
})
class Bar {}
`;
assertSuccess(ruleName, source);
});

it('should work when click events are passed to custom element', () => {
const source = `
@Component({
Expand Down