Skip to content

Commit

Permalink
chore(textarea): refactor Textarea component props and add (#1928)
Browse files Browse the repository at this point in the history
hasHelper prop
  • Loading branch information
jrgarciadev authored Nov 8, 2023
1 parent 2f87b8d commit d2bd008
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-rice-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/input": patch
---

Texarea label validation added to avoid rendering the element when there is no label.
23 changes: 12 additions & 11 deletions packages/components/input/src/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ type OmittedInputProps =
| "isClearButtonFocusVisible"
| "isLabelPlaceholder"
| "isClearable"
| "isTextarea"
| "startContent"
| "endContent";
| "isTextarea";

export type TextareaHeightChangeMeta = {
rowHeight: number;
Expand Down Expand Up @@ -77,6 +75,7 @@ const Textarea = forwardRef<"textarea", TextAreaProps>(
description,
startContent,
endContent,
hasHelper,
shouldLabelBeOutside,
shouldLabelBeInside,
errorMessage,
Expand All @@ -92,7 +91,7 @@ const Textarea = forwardRef<"textarea", TextAreaProps>(

const [hasMultipleRows, setIsHasMultipleRows] = useState(minRows > 1);
const [isLimitReached, setIsLimitReached] = useState(false);
const labelContent = <label {...getLabelProps()}>{label}</label>;
const labelContent = label ? <label {...getLabelProps()}>{label}</label> : null;
const inputProps = getInputProps();

const handleHeightChange = (height: number, meta: TextareaHeightChangeMeta) => {
Expand Down Expand Up @@ -143,13 +142,15 @@ const Textarea = forwardRef<"textarea", TextAreaProps>(
{shouldLabelBeInside ? labelContent : null}
{innerWrapper}
</div>
<div {...getHelperWrapperProps()}>
{errorMessage ? (
<div {...getErrorMessageProps()}>{errorMessage}</div>
) : description ? (
<div {...getDescriptionProps()}>{description}</div>
) : null}
</div>
{hasHelper ? (
<div {...getHelperWrapperProps()}>
{errorMessage ? (
<div {...getErrorMessageProps()}>{errorMessage}</div>
) : description ? (
<div {...getDescriptionProps()}>{description}</div>
) : null}
</div>
) : null}
</Component>
);
},
Expand Down

2 comments on commit d2bd008

@vercel
Copy link

@vercel vercel bot commented on d2bd008 Nov 8, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on d2bd008 Nov 8, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.