Skip to content

Commit

Permalink
Merge pull request #73 from aversini/feat(TextInput)-adding-support-f…
Browse files Browse the repository at this point in the history
…or-wrapper-and-input-classes

feat(TextInput): adding support for wrapper and input classes
  • Loading branch information
aversini authored Nov 23, 2023
2 parents 93c577a + 968f312 commit ad4226f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/documentation/src/stories/TextInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ const meta: Meta<typeof TextInput> = {
borderKind: "dark",
errorKind: "light",
error: false,
inputClassName: "",
className: "",
},
argTypes: {
className: {
control: "text",
},
inputClassName: {
control: "text",
},
labelId: {
control: "text",
},
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-components/src/components/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const TextInput = ({
error = false,
raw = false,
className,
inputClassName,
focusKind = "light",
borderKind = "dark",
errorKind = "light",
Expand All @@ -28,6 +29,7 @@ export const TextInput = ({
const liveErrorMessage = `${name} error, ${helperText}`;
const textInputClassName = getTextInputClasses({
className,
inputClassName,
error,
raw,
focusKind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export type TextInputProps = {
errorKind?: "dark" | "light";
raw?: boolean;
noBorder?: boolean;
inputClassName?: string;
} & React.InputHTMLAttributes<HTMLInputElement>;
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,34 @@ describe("TextInput modifiers", () => {
const input = await screen.findByTestId("txtnpt-1");
expect(input.className).toBe("");
});

it("should render a text input with a wrapper class", async () => {
render(
<TextInput
label="toto"
name="toto"
className="toto"
data-testid="txtnpt-1"
/>,
);
const input = await screen.findByTestId("txtnpt-1");
expect(input.className).not.toContain("toto");
expect(input.parentElement?.className).toContain("toto");
});

it("should render a text input with an input class", async () => {
render(
<TextInput
label="toto"
name="toto"
inputClassName="toto"
data-testid="txtnpt-1"
/>,
);
const input = await screen.findByTestId("txtnpt-1");
expect(input.className).toContain("toto");
expect(input.parentElement?.className).not.toContain("toto");
});
});

describe("TextInput methods", () => {
Expand Down
10 changes: 7 additions & 3 deletions packages/ui-components/src/components/TextInput/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {

type getTextInputClassesProps = {
className?: string;
inputClassName?: string;
raw: boolean;
focusKind: string;
borderKind: string;
Expand Down Expand Up @@ -104,6 +105,7 @@ const getTextInputHelperTextClasses = ({

export const getTextInputClasses = ({
className,
inputClassName,
raw,
focusKind,
borderKind,
Expand All @@ -112,13 +114,15 @@ export const getTextInputClasses = ({
noBorder,
error,
}: getTextInputClassesProps) => {
const wrapper = raw ? undefined : `${TEXT_INPUT_WRAPPER_CLASSNAME} w-full`;
const wrapper = raw
? className
: `${TEXT_INPUT_WRAPPER_CLASSNAME} w-full ${className}`;

const input = raw
? className
? inputClassName
: clsx(
TEXT_INPUT_CLASSNAME,
className,
inputClassName,
getTextInputBaseClasses(),
getTextInputSizesClasses(),
getTextInputColorClasses(),
Expand Down

0 comments on commit ad4226f

Please sign in to comment.