This commit is contained in:
Francisco Hodge 2020-12-21 19:24:56 -05:00
parent 9be8a095e0
commit 1166a2824f
3 changed files with 7 additions and 2 deletions

View File

@ -312,6 +312,11 @@ declare module 'simple-keyboard' {
* Clears keyboard listeners and DOM elements. * Clears keyboard listeners and DOM elements.
*/ */
destroy(): void; destroy(): void;
/**
* Iterate on each button (ForEach)
*/
recurseButtons(fn: any): void;
} }
export default Keyboard; export default Keyboard;

View File

@ -880,7 +880,7 @@ class SimpleKeyboard {
* Execute an operation on each button * Execute an operation on each button
*/ */
recurseButtons(fn) { recurseButtons(fn) {
if (!fn) return false; if (!fn) return;
Object.keys(this.buttonElements).forEach(buttonName => Object.keys(this.buttonElements).forEach(buttonName =>
this.buttonElements[buttonName].forEach(fn) this.buttonElements[buttonName].forEach(fn)

View File

@ -1376,7 +1376,7 @@ it('Keyboard buttonAttribute will warn about invalid entries', () => {
it('Keyboard recurseButtons will not work without a valid param', () => { it('Keyboard recurseButtons will not work without a valid param', () => {
setDOM(); setDOM();
const keyboard = new Keyboard(); const keyboard = new Keyboard();
expect(keyboard.recurseButtons()).toBe(false); expect(keyboard.recurseButtons()).toBeFalsy();
}); });
it('Keyboard will not work with a DOM element param without class', () => { it('Keyboard will not work with a DOM element param without class', () => {