Browse Source

fix: Input disabled should not keep focus style (#32739)

pull/32746/head
二货机器人 3 years ago
committed by GitHub
parent
commit
9fa79dc09d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      components/input/Input.tsx
  2. 9
      components/input/__tests__/focus.test.tsx

3
components/input/Input.tsx

@ -188,6 +188,9 @@ class Input extends React.Component<InputProps, InputState> {
if (nextProps.value !== undefined || prevValue !== nextProps.value) {
newState.value = nextProps.value;
}
if (nextProps.disabled) {
newState.focused = false;
}
return newState;
}

9
components/input/__tests__/focus.test.tsx

@ -55,4 +55,13 @@ describe('Input.Focus', () => {
expect(focus).toHaveBeenCalled();
expect(setSelectionRange).toHaveBeenCalledWith(expect.anything(), 0, 5);
});
it('disabled should reset focus', () => {
const wrapper = mount(<Input allowClear />);
wrapper.find('input').simulate('focus');
expect(wrapper.exists('.ant-input-affix-wrapper-focused')).toBeTruthy();
wrapper.setProps({ disabled: true });
expect(wrapper.exists('.ant-input-affix-wrapper-focused')).toBeFalsy();
});
});

Loading…
Cancel
Save