Skip to content

Commit

Permalink
fix(input): disable password toggle when input disabled (#2991)
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn authored Jul 12, 2024
1 parent 942264d commit fdad042
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ const Input = forwardRefWithStatics(
);

function togglePasswordVisible() {
if (disabled) return;
const toggleType = renderType === 'password' ? 'text' : 'password';
setRenderType(toggleType);
}
Expand Down
13 changes: 12 additions & 1 deletion src/input/__tests__/input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,19 @@ describe('Input 组件测试', () => {
expect(queryByPlaceholderText(InputPlaceholder).disabled).toBeTruthy();
});
test('password', async () => {
const { queryByPlaceholderText } = render(<Input placeholder={InputPlaceholder} type="password" />);
const { queryByPlaceholderText, container } = render(<Input placeholder={InputPlaceholder} type="password" />);
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(<Input placeholder={InputPlaceholder} type="password" disabled />);

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(<Input placeholder={InputPlaceholder} status="error" />);
Expand Down

0 comments on commit fdad042

Please sign in to comment.