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

add a slot to customize email helper text #179

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
47 changes: 47 additions & 0 deletions cypress/e2e/state-calculator-email.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/// <reference types="cypress" />
/// <reference types="cypress-axe" />

describe('rewiring-america-state-calculator email field', () => {
beforeEach(function () {
cy.visit('http://localhost:1234');
});

it('does not show the email field by default', () => {
cy.get('rewiring-america-state-calculator')
.shadow()
.find('#email')
.should('not.exist');
});

it('shows the email field if requested', () => {
cy.get('rewiring-america-state-calculator').invoke(
'attr',
'show-email',
'true',
);

cy.get('rewiring-america-state-calculator')
.shadow()
.find('#email')
.should('exist');
});

it('allows overriding the email field helper if a slot is provided', () => {
cy.get('rewiring-america-state-calculator').invoke(
'attr',
'show-email',
'true',
);

cy.get('rewiring-america-state-calculator').then($el => {
$el.append(
'<span id="test-email-helper" slot="email-helper">Get updates from Rewiring America and our partners.</span>',
);
});

cy.get('rewiring-america-state-calculator')
.find('#test-email-helper')
.should('contain', 'Get updates from Rewiring America and our partners.')
.should('be.visible');
});
});
26 changes: 14 additions & 12 deletions src/state-calculator-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,20 @@ const renderEmailField = (
required={emailRequired}
/>
<div className="mt-1 mx-3 text-color-text-secondary text-xsm leading-normal">
{msg(
'Get updates on incentives, rebates, and more from Rewiring America.',
)}{' '}
{msg('View our')}{' '}
<a
className="text-color-action-primary font-medium"
href="https://rewiringamerica.org/terms-of-use"
target="_blank"
>
{msg('terms')}
</a>
.
<slot name="email-helper">
{msg(
'Get updates on incentives, rebates, and more from Rewiring America.',
)}{' '}
{msg('View our')}{' '}
<a
className="text-color-action-primary font-medium"
href="https://rewiringamerica.org/terms-of-use"
target="_blank"
>
{msg('terms')}
</a>
.
</slot>
</div>
</div>
);
Expand Down
Loading