Skip to content

Commit

Permalink
fix descriptionText bug
Browse files Browse the repository at this point in the history
  • Loading branch information
isastettler committed Oct 10, 2023
1 parent 11aafed commit 87cc43d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/components/NewsletterSignup/NewsletterSignup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ Resources:
- [DS Button Accessibility](../?path=/docs/components-form-elements-button--docs#accessibility)
- [DS TextInput Accessibility](../?path=/docs/components-form-elements-textinput--docs#accessibility)

## JSX Elements passed to descriptionText Prop

Alternatively to a `descriptionText` of type `string`, a HTML Element or React component can be passed. When passing a JSX Element, the consuming app is responsible
to assure its accessibility.

<Canvas of={NewsletterSignupStories.DescriptionUsingJSXElements} />

## Form Submission Data

Submitted form data can be retrieved when the `NewsletterSignup` component is
Expand Down
19 changes: 19 additions & 0 deletions src/components/NewsletterSignup/NewsletterSignup.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ export const WithControls: Story = {
render: (args) => <NewsletterSignup {...args} />,
};

export const DescriptionUsingJSXElements: Story = {
render: () => (
<NewsletterSignup
id="jsx-description-text"
view="form"
onChange={() => {}}
onSubmit={() => {}}
descriptionText={
<div>
If the description text needs to have <i>special</i> styling or needs
to have a <a href="https://corgiorgy.com/">nested link</a>
</div>
}
confirmationHeading="Thank you for signing up!"
confirmationText="You can update your email subscription preferences at any time using the links at the bottom of the email."
/>
),
};

export const ComponentStates: Story = {
render: () => (
<VStack align="stretch" spacing="l">
Expand Down
9 changes: 8 additions & 1 deletion src/components/NewsletterSignup/NewsletterSignup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ export const NewsletterSignup = chakra(
>
<VStack id="pitch">
{title && <Heading level="h3" text={title} />}
<Text>{descriptionText}</Text>
{descriptionText ? (
typeof descriptionText === "string" ? (
<Text>{descriptionText}</Text>
) : (
descriptionText
)
) : null}

<Link href={privacyPolicyLink} type="external" id="privacy">
Privacy Policy
</Link>
Expand Down

0 comments on commit 87cc43d

Please sign in to comment.