Skip to content

Commit

Permalink
Ensure input component can be assigned type
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundito committed Apr 27, 2022
1 parent fe51cb3 commit 2c47718
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion airbyte-webapp/src/components/base/Input/Input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@ import { Input } from "./Input";
describe("<Input />", () => {
test("renders text input", () => {
const value = "[email protected]";
const { getByTestId, queryByTestId } = render(<Input defaultValue={value} />);
const { getByTestId, queryByTestId } = render(<Input type="text" defaultValue={value} />);

expect(getByTestId("input")).toHaveAttribute("type", "text");
expect(getByTestId("input")).toHaveValue(value);
expect(queryByTestId("toggle-password-visibility-button")).toBeFalsy();
});

test("renders other type of input", () => {
const type = "number";
const value = 888;
const { getByTestId, queryByTestId } = render(<Input type={type} defaultValue={value} />);

expect(getByTestId("input")).toHaveAttribute("type", type);
expect(getByTestId("input")).toHaveValue(value);
expect(queryByTestId("toggle-password-visibility-button")).toBeFalsy();
});

test("renders password input with visibilty button", () => {
const value = "eight888";
const { getByTestId, getByRole } = render(<Input type="password" defaultValue={value} />);
Expand Down
3 changes: 2 additions & 1 deletion airbyte-webapp/src/components/base/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ const Input: React.FC<InputProps> = (props) => {

const isPassword = props.type === "password";
const isVisibilityButtonVisible = isPassword && !props.disabled;
const type = isPassword ? (isContentVisible ? "text" : "password") : props.type;
const onInputFocusChange = () => toggleFocused();

return (
<InputContainer {...props} className={focused ? "input-container--focused" : undefined}>
<InputComponent
{...props}
type={!isPassword || isContentVisible ? "text" : "password"}
type={type}
isPassword={isPassword}
onFocus={onInputFocusChange}
onBlur={onInputFocusChange}
Expand Down

0 comments on commit 2c47718

Please sign in to comment.