NYPL / nypl-design-system

React design system putting accessibility first.
https://nypl.github.io/nypl-design-system/reservoir/v3/?path=/docs/welcome--docs
Apache License 2.0
71 stars 6 forks source link

DSD-1585: HelperErrorText styling bug #1659

Closed oliviawongnyc closed 2 months ago

oliviawongnyc commented 2 months ago

Fixes JIRA ticket DSD-1585

This PR does the following:

Basically, the following test failed because the code now sees strings as strings and JSX elements as JSX elements, rather than interpreting HTML strings like "This text is bold". (Marty this is why we were using dangerouslySetInnerHtml, I believe), but I feel like this maybe should be the case anyway. Let me know what you think.

it("renders the text passed as an HTML string", () => { render(); expect(screen.getByText("This text is bold")).toBeInTheDocument(); });

How has this been tested?

Accessibility concerns or updates

Accessibility Checklist

Open Questions

-

Checklist:

Front End Review:

vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nypl-design-system ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 17, 2024 6:10pm
bigfishdesign13 commented 2 months ago

With this update, when the text prop is passed as a string, HTML tags that are included in the string will no longer be rendered. That is definitely a breaking change and it will either need to be reverted or annother solution will need to be implemented to allow the HTML tags to be rendered propperly. Form field helper text is everywhere and we can't take this risk.

I see that we are using dangerouslySetInnerHTML in a number of other components, so I think we can stick with that.

Thoughts?

EdwinGuzman commented 2 months ago

This very closely follows the requirement in the ticket to remove the conditional logic but I still think it's needed. We just recently added this to the Banner component because of the use-case where HTML is stored as a string from either a database, API call, or environment variable.

I think the conditional should still be there so it's backwards compatible, but wrap the text in <Box __css={styles.innerChild}>{text}</Box>. The issue might also come from how the parent Box wrapper is styled.

If the user passes in HTML that has top margin or padding, the text will be off and we cannot help that. So maybe add a warning against doing so or being careful about what gets passed -- the simpler the better.