diff --git a/src/input/Input.tsx b/src/input/Input.tsx index 6697ec89e..284c23090 100644 --- a/src/input/Input.tsx +++ b/src/input/Input.tsx @@ -279,6 +279,7 @@ const Input = forwardRefWithStatics( ); function togglePasswordVisible() { + if (disabled) return; const toggleType = renderType === 'password' ? 'text' : 'password'; setRenderType(toggleType); } diff --git a/src/input/__tests__/input.test.tsx b/src/input/__tests__/input.test.tsx index e7153f998..070915c6e 100644 --- a/src/input/__tests__/input.test.tsx +++ b/src/input/__tests__/input.test.tsx @@ -90,8 +90,19 @@ describe('Input 组件测试', () => { expect(queryByPlaceholderText(InputPlaceholder).disabled).toBeTruthy(); }); test('password', async () => { - const { queryByPlaceholderText } = render(); + const { queryByPlaceholderText, container } = render(); expect(queryByPlaceholderText(InputPlaceholder).type).toEqual('password'); + + expect(container.querySelector('.t-icon-browse-off')).toBeTruthy(); + fireEvent.click(container.querySelector('.t-input__suffix-clear')); + expect(container.querySelector('.t-icon-browse')).toBeTruthy(); + }); + test('password can be toggle when disabled', async () => { + const { container } = render(); + + expect(container.querySelector('.t-icon-browse-off')).toBeTruthy(); + fireEvent.click(container.querySelector('.t-input__suffix-clear')); + expect(container.querySelector('.t-icon-browse-off')).toBeTruthy(); }); test('status', async () => { const { container } = render();