Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Tooltip status override #4367

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/slow-bags-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@salt-ds/core": patch
---

Fixed Tooltip to prioritize it's `status` prop over the status inherited from a parent FormField.
joshwooding marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 24 additions & 0 deletions packages/core/src/__tests__/__e2e__/tooltip/Tooltip.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,28 @@ describe("GIVEN a Tooltip", () => {
cy.findByTestId(FLOATING_TEST_ID).should("exist");
});
});

describe("WHEN used in a FormField", () => {
it("AND status is undefined, THEN should inherit status", () => {
cy.mount(
<FormField validationStatus="error">
<Tooltip open content="tooltip">
<InfoIcon />
</Tooltip>
</FormField>,
);
cy.findByRole("tooltip").should("have.class", "saltTooltip-error");
});

it("AND status is defined, THEN should not inherit status", () => {
cy.mount(
<FormField validationStatus="error">
<Tooltip open content="tooltip" status="info">
<InfoIcon />
</Tooltip>
</FormField>,
);
cy.findByRole("tooltip").should("have.class", "saltTooltip-info");
});
});
});
5 changes: 3 additions & 2 deletions packages/core/src/tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(

const disabled = disabledProp || formFieldDisabled;
const status =
formFieldValidationStatus !== undefined &&
statusProp ??
(formFieldValidationStatus !== undefined &&
VALIDATION_NAMED_STATUS.includes(formFieldValidationStatus)
? formFieldValidationStatus
: statusProp;
: undefined);
const { Component: FloatingComponent } = useFloatingComponent();

const hookProps: UseTooltipProps = {
Expand Down
Loading