Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }],
},
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Thumbs.db
node_modules
.cache
dist
debug.tsx
assets/**/*.css
build
lib
Expand Down
8 changes: 6 additions & 2 deletions src/generate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions tests/focus.test.tsx
Original file line number Diff line number Diff line change
@@ -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(<Select />);

// Focus
wrapper.find('input').simulate('focus');
act(() => {
jest.runAllTimers();
wrapper.update();
});
expect(wrapper.exists('.rc-select-focused')).toBeTruthy();

// Disabled
wrapper.setProps({ disabled: true });
act(() => {
jest.runAllTimers();
wrapper.update();
});
expect(wrapper.exists('.rc-select-focused')).toBeFalsy();

jest.useRealTimers();
});
});