diff --git a/components/input/Password.tsx b/components/input/Password.tsx index 636fb19838..a1c4d8bb5f 100644 --- a/components/input/Password.tsx +++ b/components/input/Password.tsx @@ -56,6 +56,11 @@ export default class Password extends React.Component { + // Prevent caret position change + // https://github.com/ant-design/ant-design/issues/23524 + e.preventDefault(); + }, }; return React.createElement(icon as React.ComponentType, iconProps); }; diff --git a/components/input/__tests__/Password.test.js b/components/input/__tests__/Password.test.js index dcca4ea473..5bdd5547b0 100644 --- a/components/input/__tests__/Password.test.js +++ b/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(); });