Skip to content

Commit

Permalink
fix: Password value still exists after blur it
Browse files Browse the repository at this point in the history
close #24526
  • Loading branch information
afc163 committed May 28, 2020
1 parent 6773020 commit 190912e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions components/input/Input.tsx
Expand Up @@ -190,15 +190,15 @@ class Input extends React.Component<InputProps, InputState> {

onFocus: React.FocusEventHandler<HTMLInputElement> = e => {
const { onFocus } = this.props;
this.setState({ focused: true });
this.setState({ focused: true }, this.clearPasswordValueAttribute);
if (onFocus) {
onFocus(e);
}
};

onBlur: React.FocusEventHandler<HTMLInputElement> = e => {
const { onBlur } = this.props;
this.setState({ focused: false });
this.setState({ focused: false }, this.clearPasswordValueAttribute);
if (onBlur) {
onBlur(e);
}
Expand Down
17 changes: 17 additions & 0 deletions components/input/__tests__/Password.test.js
Expand Up @@ -70,6 +70,23 @@ describe('Input.Password', () => {
expect(wrapper.find('input').at('0').getDOMNode().getAttribute('value')).toBeFalsy();
});

// https://github.com/ant-design/ant-design/issues/24526
it('should not show value attribute in input element after blur it', async () => {
const wrapper = mount(<Input.Password />);
wrapper
.find('input')
.at('0')
.simulate('change', { target: { value: 'value' } });
await sleep();
expect(wrapper.find('input').at('0').getDOMNode().getAttribute('value')).toBeFalsy();
wrapper.find('input').at('0').simulate('blur');
await sleep();
expect(wrapper.find('input').at('0').getDOMNode().getAttribute('value')).toBeFalsy();
wrapper.find('input').at('0').simulate('focus');
await sleep();
expect(wrapper.find('input').at('0').getDOMNode().getAttribute('value')).toBeFalsy();
});

// https://github.com/ant-design/ant-design/issues/20541
it('could be unmount without errors', () => {
expect(() => {
Expand Down

0 comments on commit 190912e

Please sign in to comment.