Skip to content

Commit

Permalink
fix tooltip disabled status evaluator (#2901)
Browse files Browse the repository at this point in the history
Co-authored-by: Zhihao Cui <[email protected]>
  • Loading branch information
Fercas123 and origami-z authored Jan 12, 2024
1 parent dafea8b commit 48f6c20
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-trees-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@salt-ds/core": patch
---

Fixed Tooltip not honoring `disabled` prop when used in Form Field
20 changes: 19 additions & 1 deletion packages/core/src/__tests__/__e2e__/tooltip/Tooltip.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as tooltipStories from "@stories/tooltip/tooltip.stories";
import { composeStories } from "@storybook/react";
import { InfoIcon } from "@salt-ds/icons";
import { checkAccessibility } from "../../../../../../cypress/tests/checkAccessibility";
import { Tooltip } from "@salt-ds/core";
import { Tooltip, FormField } from "@salt-ds/core";

import { CustomFloatingComponentProvider, FLOATING_TEST_ID } from "../common";

Expand Down Expand Up @@ -57,6 +57,24 @@ describe("GIVEN a Tooltip", () => {
});
});

describe("WHEN disabled", () => {
it("should not render when form field context disabled is undefined", () => {
cy.mount(
<FormField>
<Open disabled />
</FormField>
);
cy.findByRole("tooltip").should("not.exist");
});
it("should not render when form field context disabled is disabled", () => {
cy.mount(
<FormField disabled>
<Open />
</FormField>
);
cy.findByRole("tooltip").should("not.exist");
});
});
describe("WHEN tooltip placement is", () => {
it("TOP - tooltip should be positioned above the trigger", () => {
cy.mount(<Open placement="top" />);
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
validationStatus: formFieldValidationStatus,
} = useFormFieldProps();

const disabled = formFieldDisabled ?? disabledProp;
const disabled = disabledProp || formFieldDisabled;

const status =
formFieldValidationStatus !== undefined &&
VALIDATION_NAMED_STATUS.includes(formFieldValidationStatus)
Expand Down

1 comment on commit 48f6c20

@vercel
Copy link

@vercel vercel bot commented on 48f6c20 Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.