From 3b7ad9d9105be33d506cb0ae1efe891ec6d3458c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 10 May 2019 23:35:44 +0200 Subject: [PATCH] Do not treat buttons as focusable inputs --- src/isFocusableInput.js | 2 +- src/isFocusableInput.test.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/isFocusableInput.js b/src/isFocusableInput.js index 72c2b2c..5bc3a73 100644 --- a/src/isFocusableInput.js +++ b/src/isFocusableInput.js @@ -3,6 +3,6 @@ * Predicate to identify inputs that can have focus() called on them */ const isFocusableInput = (wtf: any) => - !!(wtf && typeof wtf.focus === 'function') + !!(wtf && typeof wtf.focus === 'function' && wtf.tagName !== 'BUTTON') export default isFocusableInput diff --git a/src/isFocusableInput.test.js b/src/isFocusableInput.test.js index 9e9276b..213cea9 100644 --- a/src/isFocusableInput.test.js +++ b/src/isFocusableInput.test.js @@ -14,4 +14,8 @@ describe('isFocusableInput', () => { it('should return true for an object with a focus method', () => { expect(isFocusableInput({ focus: () => {} })).toBe(true) }) + + it('should return false for a button', () => { + expect(isFocusableInput(document.createElement('button'))).toBe(false) + }) })