Skip to content
Merged
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
18 changes: 10 additions & 8 deletions packages/neuron-ui/src/widgets/TextField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const TextField = React.forwardRef(
...rest
}: {
field: string
label?: string
label?: string | React.ReactNode

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it could be implemented as label?: string | { node: ReactNode; text: string }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it could be implemented as label?: string | { node: ReactNode; text: string }

I think label should be strictly limited to string, so the definition will be recovered to string, and if a pre-component is necessary, an independent field as prefix/suffix/preTab/postTab can be added

value?: string
hint?: string
error?: string
Expand Down Expand Up @@ -58,6 +58,8 @@ const TextField = React.forwardRef(
const changePasswordHide = useCallback(() => {
setIsPasswordHidden(v => !v)
}, [setIsPasswordHidden])
// FIXME: label should be limited to a string because it has its own semantic meaning
const labelStr = typeof label === 'string' ? label : field
return (
<div
className={`${styles.textField} ${stack ? styles.stack : ''} ${className}`}
Expand All @@ -66,7 +68,7 @@ const TextField = React.forwardRef(
ref={ref}
>
{label ? (
<label htmlFor={field} aria-label={label} title={label}>
<label htmlFor={field} aria-label={labelStr} title={labelStr}>
{label}
</label>
) : null}
Expand All @@ -85,9 +87,9 @@ const TextField = React.forwardRef(
rows={rows}
value={value}
placeholder={placeholder}
title={label}
name={label}
aria-label={label}
title={labelStr}
name={labelStr}
aria-label={labelStr}
onChange={onChange}
onClick={onClick}
readOnly={readOnly}
Expand All @@ -101,9 +103,9 @@ const TextField = React.forwardRef(
type={!isPasswordHidden && type === 'password' ? 'text' : type}
value={value}
placeholder={placeholder}
title={label}
name={label}
aria-label={label}
title={labelStr}
name={labelStr}
aria-label={labelStr}
onChange={onChange}
onClick={onClick}
readOnly={readOnly}
Expand Down