;
-const iconCss = css`
- display: inline-block;
- padding-inline-end: var(--space-0_5);
-`;
-
export const HelperText = memo(function HelperTex({
color,
- id,
errorIconAccessibilityLabel,
errorIconTestID,
- children,
- dangerouslySetColor,
- textAlign = 'start',
- style,
styles,
- className,
classNames,
...props
}: HelperTextProps) {
- const rootStyle = { ...style, ...styles?.root };
+ const rootStyle = { ...props.style, ...styles?.root };
// TODO: when we actually remove dangerouslySetColor:
// when migrating from dangerouslySetColor to style.color,
// root style/className color will not automatically style the error icon like dangerouslySetColor.
// Consumers must set both styles.root and styles.icon (or classNames equivalents).
// We need to have a migrator handle this or document in future migration guide.
- const iconStyle = styles?.icon;
+ const iconStyle = useMemo(
+ () => ({
+ // Sit on the first line of label2, matching nested-text alignment.
+ marginTop: 'calc((var(--lineHeight-label2) - var(--iconSize-xs)) / 2)',
+ ...styles?.icon,
+ }),
+ [styles?.icon],
+ );
+ const justifyContent =
+ props.textAlign === 'end' ? 'flex-end' : props.textAlign === 'center' ? 'center' : 'flex-start';
+
+ if (color === 'fgNegative') {
+ return (
+
+
+
+
+ );
+ }
return (
- {color === 'fgNegative' && (
-
-
-
- )}
- {children}
-
+ className={cx(props.className, classNames?.root)}
+ style={rootStyle}
+ />
);
});
diff --git a/packages/web/src/controls/__stories__/HelperText.stories.tsx b/packages/web/src/controls/__stories__/HelperText.stories.tsx
index a2102f86bb..2c9fbf6217 100644
--- a/packages/web/src/controls/__stories__/HelperText.stories.tsx
+++ b/packages/web/src/controls/__stories__/HelperText.stories.tsx
@@ -37,7 +37,14 @@ export const TextAlign = () => {
return (
{alignments.map((alignment) => (
- {`${alignment} message`}
+
+ {`${alignment} message`}
+
+ ))}
+ {alignments.map((alignment) => (
+
+ {`${alignment} error message that can wrap onto multiple lines to check icon alignment`}
+
))}
);
diff --git a/packages/web/src/controls/__tests__/HelperText.test.tsx b/packages/web/src/controls/__tests__/HelperText.test.tsx
index 0ca277a0cf..08fa9a670c 100644
--- a/packages/web/src/controls/__tests__/HelperText.test.tsx
+++ b/packages/web/src/controls/__tests__/HelperText.test.tsx
@@ -81,4 +81,16 @@ describe('HelperText.test', () => {
expect(screen.getByTestId('helper-text-test').className).toContain('4');
});
+
+ it('keeps the error icon and message together when textAlign is end', () => {
+ render(
+
+
+ Test text
+
+ ,
+ );
+
+ expect(screen.getByTestId('error-icon').parentElement?.className).toContain('flex-end');
+ });
});