This is a method for binding accessible activation events, for elements that should act like buttons. These events will be fired when an element is clicked (or tapped, on touch devices), or when the enter key is pressed down or the spacebar key is released while the element has focus.
This emulates how browsers natively apply click events to <button> elements.
Though activate binds keyboard events, it will not force an element to become keyboard focusable. If you bind an event to an element that is not natively focusable, make sure it has a tabindex="0" attribute so it can receive keyboard focus.
Binds the function fn to a click event to the element or elements passed through in the elements argument. Similarly to addEventListener, activate will not bind multiple instance of the same function to the same element.
In addition to the click event, activate will also bind additional key events based on each element's type.
Most elements will have enter keydown events and spacebar keyup events bound to them.
<a> elements already natively accept enter keydowns as a click event natively. Unlike other elements, holding down enter while focus is on an <a> element will only cause the click event to fire once.
<button> elements don't need any additional events to be bound, as they already accept enter and spacebar key events as clicks natively.
activate will also prevent the default action of spacebar in order to stop the page scrolling, except for some elements that don't treat this as the default action. The elements excluded from this are <button>, <input>, and <textarea>
Because activate creates secondary event listeners that listen for 'keydown' events, and the primary function it binds is bound to the 'click' event, that primary function needs to be able to handle either a KeyboardEvent or a MouseEvent as its first argument.