Skip to content

Commit

Permalink
fix(input): render placeholder for multiline text inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmo314 committed May 6, 2024
1 parent a348406 commit 534e45e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/TextInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Input from "../Input";
import iconSelection from "src/icons/selection.json";

export const VALID_ICON_NAMES = iconSelection.icons.map(
(icon) => icon.properties.name
(icon) => icon.properties.name,
);

/**
Expand All @@ -30,7 +30,7 @@ const TextInput = React.forwardRef((props, forwardedRef) => {
} = props;

const [inputValue, setInputValue] = useState(
defaultValue ? defaultValue : ""
defaultValue ? defaultValue : "",
);

function _onBlur(e) {
Expand Down Expand Up @@ -86,6 +86,7 @@ const TextInput = React.forwardRef((props, forwardedRef) => {
onChange={_onChange}
onBlur={_onBlur}
required
placeholder={props.label}
aria-label={props.label}
data-testid={testId}
{...nativeElementProps}
Expand Down
7 changes: 6 additions & 1 deletion src/TextInput/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ export const Example = () => {
};

export const MultiLine = () => {
return <TextInput multiline />;
return (
<>
<TextInput multiline />
<TextInput multiline label="Multiline with label" />
</>
);
};

export const WithIcon = Template.bind({});
Expand Down
10 changes: 8 additions & 2 deletions src/TextInput/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import TextInput from "./";
describe("TextInput", () => {
it("Basic Test to verify TextInput behaves as an Html input", () => {
render(
<TextInput data-testid={1} label={"Label"} defaultValue={"Default"} />
<TextInput data-testid={1} label={"Label"} defaultValue={"Default"} />,
);
const basicInput = screen.getByTestId(1);
expect(basicInput.value).toEqual("Default");
Expand All @@ -20,7 +20,7 @@ describe("TextInput", () => {
id="test"
label={"Test Quotes"}
formatter={(text) => text.replace("“", '"').replace("”", '"')}
/>
/>,
);
const smartQuoteInput = screen.getByLabelText("Test Quotes");

Expand All @@ -43,4 +43,10 @@ describe("TextInput", () => {

expect(basicInput.value).toBe("“this is a test”");
});

it("multiline with label sets placeholder attribute", () => {
render(<TextInput label={"Label"} multiline />);
const multilineInput = screen.getByPlaceholderText("Label");
expect(multilineInput).toBeInTheDocument();
});
});

0 comments on commit 534e45e

Please sign in to comment.