Shows section headings in letter-spaced capitals
SectionHeading gets the new sectionHeading text style: uppercase, the shared caps letter-spacing, 26px on phones and 30px from md. The text in the DOM does not change, so accessible names stay as they are. The plain sectionTitle style stays for the headings that do not use SectionHeading. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import CallToAction from '@/components/CallToAction/CallToAction';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { cssRulesFor } from '@/test/cssRules';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import SectionHeading from './SectionHeading';
|
||||
|
||||
@@ -50,4 +52,34 @@ describe('SectionHeading', () => {
|
||||
).toHaveAttribute('id', 'about-title');
|
||||
expect(screen.getByText('Over mij')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the title in letter-spaced capitals without changing its text', async () => {
|
||||
const title = 'Lifestyle fotograaf met een passie voor storytelling';
|
||||
await renderWithProviders(<SectionHeading id="t" title={title} />);
|
||||
|
||||
const heading = screen.getByRole('heading', { level: 2 });
|
||||
// The case is CSS only: the text and the accessible name stay as given
|
||||
expect(heading).toHaveTextContent(title);
|
||||
expect(heading).toHaveAccessibleName(title);
|
||||
|
||||
const rules = cssRulesFor(heading).join();
|
||||
expect(rules).toContain('text-transform: uppercase');
|
||||
// The wide spacing is the shared "caps" token (0.22em)
|
||||
expect(rules).toContain(
|
||||
'letter-spacing: var(--slp-letter-spacings-caps)',
|
||||
);
|
||||
});
|
||||
|
||||
it('does not give the plain section titles of other blocks the new style', async () => {
|
||||
await renderWithProviders(
|
||||
<CallToAction title="Benieuwd naar de prijzen?" titleId="cta-title">
|
||||
<span>Actie</span>
|
||||
</CallToAction>,
|
||||
);
|
||||
|
||||
const rules = cssRulesFor(
|
||||
screen.getByRole('heading', { level: 2 }),
|
||||
).join();
|
||||
expect(rules).not.toContain('text-transform: uppercase');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,8 +16,9 @@ type SectionHeadingProps = {
|
||||
focusable?: boolean;
|
||||
};
|
||||
|
||||
// Heading block of a homepage section (design .section__head): optional
|
||||
// small label, the h2 and an optional intro sentence.
|
||||
// Heading block of a section (design .section__head): optional small label,
|
||||
// the h2 in letter-spaced capitals (the case is only CSS, the text stays as
|
||||
// given) and an optional intro sentence.
|
||||
export default function SectionHeading({
|
||||
id,
|
||||
title,
|
||||
@@ -40,7 +41,7 @@ export default function SectionHeading({
|
||||
<Heading
|
||||
as="h2"
|
||||
id={id}
|
||||
textStyle="sectionTitle"
|
||||
textStyle="sectionHeading"
|
||||
tabIndex={focusable ? -1 : undefined}
|
||||
>
|
||||
{title}
|
||||
|
||||
+13
-1
@@ -197,7 +197,19 @@ const config = defineConfig({
|
||||
lineHeight: '1',
|
||||
},
|
||||
},
|
||||
// The h2 of a homepage section (SectionHeading); smaller than the
|
||||
// The h2 of a section block (SectionHeading): letter-spaced
|
||||
// capitals, as on the live site. 26px on phones, 30px from md.
|
||||
sectionHeading: {
|
||||
value: {
|
||||
fontFamily: 'heading',
|
||||
fontSize: { base: '1.625rem', md: '1.875rem' },
|
||||
lineHeight: '1.15',
|
||||
letterSpacing: 'caps',
|
||||
textTransform: 'uppercase',
|
||||
},
|
||||
},
|
||||
// Plain h2 in blocks that do not use SectionHeading (call to
|
||||
// action, packages, shoot and story blocks); smaller than the
|
||||
// design's 2.5rem at the owner's request, 30px at every width
|
||||
sectionTitle: {
|
||||
value: {
|
||||
|
||||
Reference in New Issue
Block a user