Skip to content

Commit

Permalink
fix([DST-501]): Don't render helptext if there is no error and descri…
Browse files Browse the repository at this point in the history
…ption. (#4033)

* fix([DST-501]): Don't render helptext if there is no error and description.

* Create sixty-bears-double.md
  • Loading branch information
sebald authored Jul 23, 2024
1 parent 0bf0940 commit 449de9b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-bears-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marigold/components": patch
---

fix([DST-501]): Don't render helptext if there is no error and description.
24 changes: 10 additions & 14 deletions packages/components/src/HelpText/HelpText.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
import { useContext } from 'react';
import type { PropsWithChildren, ReactNode } from 'react';
import type { ReactNode } from 'react';
import type { ValidationResult } from 'react-aria-components';
import { FieldError, FieldErrorContext, Text } from 'react-aria-components';

import { cn, useClassNames } from '@marigold/system';

// Description
// ---------------
const Description = ({ children }: PropsWithChildren) => {
const ctx = useContext(FieldErrorContext);

if (ctx && ctx.isInvalid) {
return null;
}

return <Text slot="description">{children}</Text>;
};

// Icon
// ---------------
const Icon = ({ className }: { className?: string }) => (
Expand Down Expand Up @@ -59,6 +47,12 @@ export const HelpText = ({
variant,
size,
});
const ctx = useContext(FieldErrorContext);

// Prevent rendering anything if no error/description should be shown.
if (!description && ctx && !ctx.isInvalid) {
return null;
}

return (
<div className={cn(classNames.container)}>
Expand Down Expand Up @@ -91,7 +85,9 @@ export const HelpText = ({
);
}}
</FieldError>
<Description>{description}</Description>
{ctx && ctx.isInvalid ? null : (
<Text slot="description">{description}</Text>
)}
</div>
);
};

0 comments on commit 449de9b

Please sign in to comment.