diff --git a/.eslintrc.js b/.eslintrc.js index 4b62cc7af..0833fbcbd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,6 +9,5 @@ module.exports = { 'react/sort-comp': 0, 'jsx-a11y/interactive-supports-focus': 0, 'jsx-a11y/no-autofocus': 0, - 'import/no-extraneous-dependencies': ['error', { devDependencies: true }], }, }; diff --git a/.gitignore b/.gitignore index 6e8f606b5..9b0000159 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ Thumbs.db node_modules .cache dist +debug.tsx assets/**/*.css build lib diff --git a/src/generate.tsx b/src/generate.tsx index da61a0a38..ac429adfa 100644 --- a/src/generate.tsx +++ b/src/generate.tsx @@ -773,11 +773,15 @@ export default function generateSelector< setInnerSearchValue(''); }; - // Close dropdown when disabled change + // Close dropdown & remove focus state when disabled change useEffect(() => { - if (innerOpen && !!disabled) { + if (innerOpen && disabled) { setInnerOpen(false); } + + if (disabled) { + setMockFocused(false); + } }, [disabled]); // Close will clean up single mode search text diff --git a/tests/focus.test.tsx b/tests/focus.test.tsx new file mode 100644 index 000000000..6aae2b528 --- /dev/null +++ b/tests/focus.test.tsx @@ -0,0 +1,33 @@ +import { mount } from 'enzyme'; +import React from 'react'; +import { act } from 'react-dom/test-utils'; +import Select from '../src'; + +describe('Select.Focus', () => { + it('disabled should reset focused', () => { + jest.clearAllTimers(); + jest.useFakeTimers(); + + jest.clearAllTimers(); + + const wrapper = mount(