From 26bf7472c01472d9f924284d7b81b6e2ec05e06f Mon Sep 17 00:00:00 2001 From: Liam Smith Date: Fri, 1 Nov 2024 14:37:41 +0000 Subject: [PATCH] Fix Tooltip status override (#4367) Co-authored-by: Josh Wooding <12938082+joshwooding@users.noreply.github.com> --- .changeset/slow-bags-give.md | 5 ++++ .../__tests__/__e2e__/tooltip/Tooltip.cy.tsx | 24 +++++++++++++++++++ packages/core/src/tooltip/Tooltip.tsx | 5 ++-- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 .changeset/slow-bags-give.md diff --git a/.changeset/slow-bags-give.md b/.changeset/slow-bags-give.md new file mode 100644 index 00000000000..6bedbdadf18 --- /dev/null +++ b/.changeset/slow-bags-give.md @@ -0,0 +1,5 @@ +--- +"@salt-ds/core": patch +--- + +Fixed Tooltip to prioritize its `status` prop over the status inherited from a parent FormField. diff --git a/packages/core/src/__tests__/__e2e__/tooltip/Tooltip.cy.tsx b/packages/core/src/__tests__/__e2e__/tooltip/Tooltip.cy.tsx index 572ecff4b2c..034093e11b5 100644 --- a/packages/core/src/__tests__/__e2e__/tooltip/Tooltip.cy.tsx +++ b/packages/core/src/__tests__/__e2e__/tooltip/Tooltip.cy.tsx @@ -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( + + + + + , + ); + cy.findByRole("tooltip").should("have.class", "saltTooltip-error"); + }); + + it("AND status is defined, THEN should not inherit status", () => { + cy.mount( + + + + + , + ); + cy.findByRole("tooltip").should("have.class", "saltTooltip-info"); + }); + }); }); diff --git a/packages/core/src/tooltip/Tooltip.tsx b/packages/core/src/tooltip/Tooltip.tsx index 654c9844304..2efae0bfc44 100644 --- a/packages/core/src/tooltip/Tooltip.tsx +++ b/packages/core/src/tooltip/Tooltip.tsx @@ -96,10 +96,11 @@ export const Tooltip = forwardRef( 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 = {