Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(TextField): add support for inputProps.className #399

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ export default meta;

export const Example = {};

export const Large = {
args: {
inputProps: {
className: 'text-2xl',
},
},
};

export const HtmlValidation = (args: any) => (
<form
onSubmit={(event) => {
Expand Down
9 changes: 8 additions & 1 deletion packages/utah-design-system/src/components/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type InputProps,
type ValidationResult,
} from 'react-aria-components';
import { twJoin } from 'tailwind-merge';
import { tv } from 'tailwind-variants';
import {
Description,
Expand Down Expand Up @@ -35,6 +36,12 @@ export const TextField = forwardRef(function TextField(
{ label, description, errorMessage, inputProps, ...props }: TextFieldProps,
ref: ForwardedRef<HTMLInputElement>,
) {
// mix in input classes if necessary
let inputClasses = inputStyles();
if (inputProps?.className) {
inputClasses = twJoin(inputStyles(), inputProps.className as string);
}

return (
<AriaTextField
{...props}
Expand All @@ -44,7 +51,7 @@ export const TextField = forwardRef(function TextField(
)}
>
{label && <Label>{label}</Label>}
<Input ref={ref} {...inputProps} className={inputStyles} />
<Input ref={ref} {...inputProps} className={inputClasses} />
{description && <Description>{description}</Description>}
<FieldError>{errorMessage}</FieldError>
</AriaTextField>
Expand Down
Loading