0

html

<div (click)=addBtn($event)>Button</div>

.ts

addBtn(e:Event){
e.stopPropagation()
}

Its working fine but my code is getting failed while testing for eslint showing , " click must be accompanied by either keyup, keydown or keypress event for accessibility @angular-eslint/template/click-events-have-key-events. "

naman
  • 51
  • 4
  • Does this answer your question? [Calling a typescript method from your html button onclick event](https://stackoverflow.com/questions/45544752/calling-a-typescript-method-from-your-html-button-onclick-event) – pilchard Jul 04 '23 at 07:58
  • nope, its not working with this way too – naman Jul 04 '23 at 08:09
  • What is your question? do you want to change this `(click)` event? can you elaborate more.. – CodeThing Jul 04 '23 at 08:15
  • Also you have typo there. It's `stopPropagation` not `stopPropagtion ` – CodeThing Jul 04 '23 at 08:17
  • I just missed it here , while posting the query – naman Jul 04 '23 at 08:35
  • eslint error makes sense since your element is not ADA compliant, anyways you can either disable the error with a comment or better you can convert the div into a button https://stackoverflow.com/a/59407526/9016028 – Anand Bhushan Jul 04 '23 at 08:51
  • try maybe adding keyup method, which will along with click method serve to call addBtn.. see (for inspiration): https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/click-events-have-key-events.md – traynor Jul 04 '23 at 09:07

0 Answers0