Skip to content

Commit

Permalink
fix: patch label of textfield when it's not a string (#2851)
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY authored Sep 27, 2023
1 parent be2c2f3 commit 1b0f290
Showing 1 changed file with 10 additions and 8 deletions.
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
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

1 comment on commit 1b0f290

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Packaging for test is done in 6329749384

Please sign in to comment.