✨(react) add textItems to Field
This allow to add bullet points lists below inputs, the best example is when we want to list multiple errors from form validation. Fixes #147
This commit is contained in:
@@ -119,6 +119,26 @@ describe("<Input/>", () => {
|
||||
);
|
||||
screen.getByText("Some text");
|
||||
});
|
||||
it("renders with text items", async () => {
|
||||
render(
|
||||
<Input
|
||||
label="First name"
|
||||
rightIcon={<span className="material-icons">apartment</span>}
|
||||
textItems={[
|
||||
"Text too long",
|
||||
"Wrong choice",
|
||||
"Must contain at least 9 characters, uppercase and digits",
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
expect(
|
||||
screen.getAllByRole("listitem").map((item) => item.textContent),
|
||||
).toEqual([
|
||||
"Text too long",
|
||||
"Wrong choice",
|
||||
"Must contain at least 9 characters, uppercase and digits",
|
||||
]);
|
||||
});
|
||||
it("renders with text and text right", async () => {
|
||||
render(
|
||||
<Input
|
||||
|
||||
@@ -43,6 +43,21 @@ export const Error = {
|
||||
},
|
||||
};
|
||||
|
||||
export const ErrorItems = {
|
||||
args: {
|
||||
defaultValue: "Hello world",
|
||||
label: "Your name",
|
||||
state: "error",
|
||||
icon: <span className="material-icons">person</span>,
|
||||
text: "This is an optional error message",
|
||||
textItems: [
|
||||
"Text too long",
|
||||
"Wrong choice",
|
||||
"Must contain at least 9 characters, uppercase and digits",
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
export const DisabledEmpty = {
|
||||
args: {
|
||||
label: "Your name",
|
||||
|
||||
@@ -31,6 +31,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||
rightIcon,
|
||||
state = "default",
|
||||
text,
|
||||
textItems,
|
||||
rightText,
|
||||
fullWidth,
|
||||
charCounter,
|
||||
@@ -76,6 +77,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||
<Field
|
||||
state={state}
|
||||
text={text}
|
||||
textItems={textItems}
|
||||
rightText={rightTextToUse}
|
||||
fullWidth={fullWidth}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user