Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions packages/core/src/components/field-wrapper/helper-text-util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,31 @@ import {

export function hasAnyText({
invalidText,
isInvalid,
warningText,
isWarning,
infoText,
isInfo,
validText,
isValid,
helperText,
}: {
invalidText?: string;
isInvalid?: boolean;
warningText?: string;
isWarning?: boolean;
infoText?: string;
isInfo?: boolean;
validText?: string;
isValid?: boolean;
helperText?: string;
}) {
return [invalidText, warningText, infoText, validText, helperText].some(
(text) => text?.trim()
return (
(isInvalid && invalidText?.trim()) ||
(isWarning && warningText?.trim()) ||
(isInfo && infoText?.trim()) ||
(isValid && validText?.trim()) ||
helperText?.trim()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,66 @@ regressionTest(
await expect(helperTextElement).toHaveCount(1);
}
);

regressionTest(
'should not show empty tooltip if invalidText is present but isInvalid is false and no helperText',
async ({ mount, page }) => {
await mount(
`
<ix-field-wrapper
invalid-text="This invalid message should be ignored"
show-text-as-tooltip
>
<div style="position: relative; width: 100%; height: 2rem; background: red;">Content</div>
</ix-field-wrapper>
`
);

const fieldWrapperElement = page.locator('ix-field-wrapper');
await expect(fieldWrapperElement).toHaveClass(/hydrated/);

const bottomTextElement = fieldWrapperElement
.locator('.field-bottom')
.locator('ix-typography.bottom-text');
await expect(bottomTextElement).toHaveCount(0);

await page.mouse.move(10, 10);
await page.waitForTimeout(500);

const tooltip = fieldWrapperElement.locator('ix-tooltip');
await expect(tooltip).toHaveCount(0);
await expect(tooltip).not.toBeVisible();
}
);
regressionTest(
'should not show tooltip if invalidText is an empty string even when isInvalid is true',
async ({ mount, page }) => {
await mount(
`
<ix-field-wrapper
<ix-field-wrapper
invalid-text=""
is-invalid
show-text-as-tooltip
>
<div style="position: relative; width: 100%; height: 2rem; background: red;">Content</div>
</ix-field-wrapper>
`
);
const fieldWrapperElement = page.locator('ix-field-wrapper');
await expect(fieldWrapperElement).toHaveClass(/hydrated/);

const bottomTextElement = fieldWrapperElement
.locator('.field-bottom')
.locator('ix-typography.bottom-text');
await expect(bottomTextElement).toHaveCount(0);

await page.mouse.move(10, 10);
await page.waitForTimeout(500);

const tooltip = fieldWrapperElement.locator('ix-tooltip');

await expect(tooltip).toHaveCount(0);
await expect(tooltip).not.toBeVisible();
}
);