Browse Source

fix: preserve caret position🐛 (#23633)

* 🐛 fix: preserve caret position

*  update test case for preserving caret position

* Update Password.tsx

* Update Password.test.js

* Update Password.test.js

Co-authored-by: 偏右 <afc163@gmail.com>
pull/23673/head
Yu Mao 5 years ago
committed by GitHub
parent
commit
e199a7a301
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      components/input/Password.tsx
  2. 7
      components/input/__tests__/Password.test.js

5
components/input/Password.tsx

@ -56,6 +56,11 @@ export default class Password extends React.Component<PasswordProps, PasswordSta
// https://github.com/ant-design/ant-design/issues/15173
e.preventDefault();
},
onMouseUp: (e: MouseEvent) => {
// Prevent caret position change
// https://github.com/ant-design/ant-design/issues/23524
e.preventDefault();
},
};
return React.createElement(icon as React.ComponentType, iconProps);
};

7
components/input/__tests__/Password.test.js

@ -60,10 +60,16 @@ describe('Input.Password', () => {
.at(0)
.getDOMNode(),
);
document.activeElement.setSelectionRange(2, 2);
expect(document.activeElement.selectionStart).toBe(2);
wrapper
.find('.ant-input-password-icon')
.at(0)
.simulate('mousedown');
wrapper
.find('.ant-input-password-icon')
.at(0)
.simulate('mouseup');
wrapper
.find('.ant-input-password-icon')
.at(0)
@ -74,6 +80,7 @@ describe('Input.Password', () => {
.at(0)
.getDOMNode(),
);
expect(document.activeElement.selectionStart).toBe(2);
wrapper.unmount();
});

Loading…
Cancel
Save