-
Notifications
You must be signed in to change notification settings - Fork 0
feat: enhance TextField component with additional className props #118
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,14 +54,17 @@ export const FieldSuffix = ({ | |
| export interface TextInputProps extends Omit<InputProps, 'prefix' | 'suffix'> { | ||
| control?: Control<FieldValues>; | ||
| name: FieldPath<FieldValues>; | ||
| label?: string | React.ReactNode; | ||
| label?: string; | ||
| description?: string; | ||
| components?: Partial<FieldComponents> & { | ||
| Input?: React.ComponentType<InputProps & React.RefAttributes<HTMLInputElement>>; | ||
| }; | ||
| prefix?: React.ReactNode; | ||
| suffix?: React.ReactNode; | ||
| className?: string; | ||
| groupClassName?: string; | ||
| prefixClassName?: string; | ||
| suffixClassName?: string; | ||
| } | ||
|
|
||
| export const TextField = function TextField({ | ||
|
|
@@ -74,6 +77,9 @@ export const TextField = function TextField({ | |
| prefix, | ||
| suffix, | ||
| ref, | ||
| groupClassName, | ||
| prefixClassName, | ||
| suffixClassName, | ||
| ...props | ||
|
Comment on lines
+80
to
83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider forwarding refs properly instead of accepting a ref prop. Function components don’t receive ref via props; won’t populate the ref variable unless you use React.forwardRef. This is orthogonal to this PR but worth addressing. Example refactor (outside this hunk): export const TextField = React.forwardRef<HTMLInputElement, TextInputProps>(function TextField(
{
control,
name,
label,
description,
className,
components,
prefix,
suffix,
groupClassName,
prefixClassName,
suffixClassName,
...props
},
ref
) {
// ... use `ref` here
});Then remove ref from TextInputProps entirely (it will be provided by forwardRef). 🤖 Prompt for AI Agents |
||
| }: TextInputProps & { ref?: React.Ref<HTMLInputElement> }) { | ||
| // Use the custom Input component if provided, otherwise use the default TextInput | ||
|
|
@@ -91,10 +97,10 @@ export const TextField = function TextField({ | |
| className={cn('flex group transition-all duration-200 rounded-md', { | ||
| 'field__input--with-prefix': prefix, | ||
| 'field__input--with-suffix': suffix, | ||
| 'focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 focus-within:ring-offset-background': true, | ||
| })} | ||
| 'focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 focus-within:ring-offset-background': true | ||
| }, groupClassName)} | ||
| > | ||
| {prefix && <FieldPrefix>{prefix}</FieldPrefix>} | ||
| {prefix && <FieldPrefix className={prefixClassName}>{prefix}</FieldPrefix>} | ||
| <FormControl Component={components?.FormControl}> | ||
| <InputComponent | ||
| {...field} | ||
|
|
@@ -106,7 +112,7 @@ export const TextField = function TextField({ | |
| })} | ||
| /> | ||
| </FormControl> | ||
| {suffix && <FieldSuffix>{suffix}</FieldSuffix>} | ||
| {suffix && <FieldSuffix className={suffixClassName}>{suffix}</FieldSuffix>} | ||
| </div> | ||
| {description && <FormDescription Component={components?.FormDescription}>{description}</FormDescription>} | ||
| {fieldState.error && ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Avoid breaking change: keep label as ReactNode-compatible.
Narrowing label to string breaks valid use cases (icons, formatted labels, i18n components). Recommend restoring React.ReactNode.
Apply:
If you intend to keep it string-only, please confirm there are no callsites passing JSX. Use the script in package.json review to verify.
🏁 Script executed:
Length of output: 248
🏁 Script executed:
Length of output: 284
Restore ReactNode for the
labelpropOur search across all
.tsx/.jsxfiles did not find any instances of non-string labels being passed to<TextField>, so reverting this change is non-breaking today and preserves future flexibility (icons, formatted labels, i18n components).• File:
packages/components/src/ui/text-field.tsxline 57• Apply:
🤖 Prompt for AI Agents