Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

audit(Blockquote): drop the contentinfo landmark, guard the cite slot, wrap long words (#5144)

Cindy Zhang3281a2410193
diff --git a/.changeset/blockquote-attribution-landmark.md b/.changeset/blockquote-attribution-landmark.md
new file mode 100644
index 0000000000..84202b4159
--- /dev/null
+++ b/.changeset/blockquote-attribution-landmark.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Blockquote: the `cite` attribution renders as a bare `<cite>` instead of being wrapped in a `<footer>`, which was becoming a `contentinfo` document landmark. Also guards the slot with `isRenderable`, so `cite={condition && author}` no longer emits an empty `<cite>`, and wraps long unbroken words instead of overflowing.
+
+@cixzhang
diff --git a/apps/storybook/stories/Blockquote.stories.tsx b/apps/storybook/stories/Blockquote.stories.tsx
index 511ede3fbe..6509a5cc49 100644
--- a/apps/storybook/stories/Blockquote.stories.tsx
+++ b/apps/storybook/stories/Blockquote.stories.tsx
@@ -1,11 +1,27 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.
import type {Meta, StoryObj} from '@storybook/react';
+import * as stylex from '@stylexjs/stylex';
import {Blockquote} from '@astryxdesign/core/Blockquote';
import {Card} from '@astryxdesign/core/Card';
import {Section} from '@astryxdesign/core/Section';
import {VStack} from '@astryxdesign/core/Layout';
import {Text} from '@astryxdesign/core/Text';
+import {
+ spacingVars,
+ typeScaleVars,
+} from '@astryxdesign/core/theme/tokens.stylex';
+
+const styles = stylex.create({
+ pullQuote: {
+ fontSize: typeScaleVars['--text-large-size'],
+ lineHeight: typeScaleVars['--text-large-leading'],
+ marginBlock: spacingVars['--spacing-4'],
+ },
+ narrow: {
+ maxWidth: '280px',
+ },
+});
const meta: Meta<typeof Blockquote> = {
title: 'Core/Blockquote',
@@ -105,3 +121,55 @@ export const MultipleParagraphs: Story = {
</Section>
),
};
+
+export const PullQuoteWithXstyle: Story = {
+ render: () => (
+ <Section variant="muted">
+ <Card>
+ <VStack gap={3}>
+ <Text type="body">
+ xstyle carries layout and type overrides onto the blockquote itself,
+ with no wrapper element.
+ </Text>
+ <Blockquote cite="Alan Kay" xstyle={styles.pullQuote}>
+ The best way to predict the future is to invent it.
+ </Blockquote>
+ </VStack>
+ </Card>
+ </Section>
+ ),
+};
+
+export const LongContent: Story = {
+ render: () => (
+ <Section variant="muted">
+ <Card>
+ <VStack gap={3}>
+ <Blockquote cite="A source with a notably long attribution line that has to wrap">
+ A long quotation that runs past a single line, so the rule on the
+ inline-start edge and the wrapped text stay aligned all the way
+ down. Long attributions wrap the same way underneath.
+ </Blockquote>
+ <Blockquote>
+ An unbroken token such as
+ https://www.example.com/research/2026/design-systems/the-very-long-report-slug/appendix
+ wraps instead of overflowing.
+ </Blockquote>
+ </VStack>
+ </Card>
+ </Section>
+ ),
+};
+
+export const NarrowContainer: Story = {
+ render: () => (
+ <Section variant="muted">
+ <Card xstyle={styles.narrow}>
+ <Blockquote cite="Steve Jobs">
+ Design is not just what it looks like and feels like. Design is how it
+ works.
+ </Blockquote>
+ </Card>
+ </Section>
+ ),
+};
diff --git a/packages/core/src/Blockquote/Blockquote.doc.mjs b/packages/core/src/Blockquote/Blockquote.doc.mjs
index a9cec4ebdd..10aefafe0b 100644
--- a/packages/core/src/Blockquote/Blockquote.doc.mjs
+++ b/packages/core/src/Blockquote/Blockquote.doc.mjs
@@ -19,7 +19,7 @@ export const docs = {
{
name: 'cite',
type: 'ReactNode',
- description: 'Optional attribution for the quote. Rendered in a <footer> with <cite>.',
+ description: 'Optional attribution for the quote. Rendered in a <cite> element after the quoted content.',
},
{
name: 'xstyle',
@@ -28,17 +28,31 @@ export const docs = {
'StyleX styles for layout customization (margins, positioning, sizing). Must be a stylex.create() value, not an inline style object like style={{}}.',
},
],
+ playground: {
+ defaults: {
+ children:
+ 'Design is not just what it looks like and feels like. Design is how it works.',
+ cite: 'Steve Jobs',
+ },
+ },
theming: {
targets: [
{className: 'astryx-blockquote', visualProps: []},
],
},
usage: {
- description: 'A styled quotation block with an accent-colored left border and secondary text color. Use to highlight quoted content, testimonials, or excerpts.',
+ description: 'A quotation block with a rule on its inline-start edge and secondary text color. Use to highlight quoted content, testimonials, or excerpts. The rule and padding are logical, so they move to the right edge in right-to-left locales.',
+ anatomy: [
+ {name: 'Rule', required: true, description: 'The border on the inline-start edge, drawn with --color-border-emphasized.'},
+ {name: 'Quotation', required: true, description: 'The quoted content, passed as children. Renders inside the <blockquote> element.'},
+ {name: 'Attribution', required: false, description: 'The source, passed as cite. Renders as a <cite> element below the quotation.'},
+ ],
bestPractices: [
{ guidance: true, description: 'Use for quoted text, testimonials, or highlighted excerpts from external sources.' },
{ guidance: true, description: 'Provide a cite prop when the source of the quote is known.' },
+ { guidance: true, description: 'Pass the source through cite rather than typing it into children, so it renders as a semantic <cite> element that assistive technology can distinguish from the quotation.' },
{ guidance: false, description: 'Use for callout boxes or informational notes; use Banner for those.' },
+ { guidance: false, description: 'Wrap the attribution in your own <footer>. A <footer> inside a <blockquote> becomes a contentinfo document landmark, and a page with several quotes then reports several page footers.' },
],
},
};
@@ -57,7 +71,7 @@ export const docsZh = {
{
name: 'cite',
type: 'ReactNode',
- description: '引用的可选出处。在 <footer> 中以 <cite> 渲染。',
+ description: '引用的可选出处。在引用内容之后以 <cite> 元素渲染。',
},
{
name: 'xstyle',
@@ -72,29 +86,38 @@ export const docsZh = {
],
},
usage: {
- description: '带有强调色左边框和次要文本颜色的引用块。用于突出显示引用内容、推荐语或摘录。',
+ description: '带有行首边框和次要文本颜色的引用块。用于突出显示引用内容、推荐语或摘录。边框和内边距使用逻辑属性,因此在从右到左的语言环境中会移到右侧。',
+ anatomy: [
+ {name: '边框', required: true, description: '行首边缘的边框,使用 --color-border-emphasized 绘制。'},
+ {name: '引用内容', required: true, description: '通过 children 传入的引用内容,渲染在 <blockquote> 元素内。'},
+ {name: '出处', required: false, description: '通过 cite 传入的来源,在引用内容下方以 <cite> 元素渲染。'},
+ ],
bestPractices: [
{ guidance: true, description: '用于引用文本、推荐语或来自外部来源的高亮摘录。' },
{ guidance: true, description: '当引用来源已知时,提供 cite 属性。' },
+ { guidance: true, description: '通过 cite 传入来源,而不是写在 children 里,这样它会渲染为语义化的 <cite> 元素,辅助技术可以将其与引用内容区分开。' },
{ guidance: false, description: '用于提示框或信息说明,应使用 Banner。' },
+ { guidance: false, description: '自行用 <footer> 包裹出处。<blockquote> 内的 <footer> 会成为 contentinfo 文档地标,页面上有多个引用时就会报告多个页脚。' },
],
},
};
/** @type {import('@astryxdesign/cli/authoring').ComponentTranslationDoc} */
export const docsDense = {
- description: 'styled quotation block w/ accent left border, secondary text, optional citation',
+ description: 'quotation block w/ inline-start rule, secondary text, optional citation',
usage: {
- description: 'A styled quotation block with an accent-colored left border and secondary text color. Use to highlight quoted content, testimonials, or excerpts.',
+ description: 'A quotation block with a rule on its inline-start edge and secondary text color. Use to highlight quoted content, testimonials, or excerpts.',
bestPractices: [
{ guidance: true, description: 'Use for quoted text, testimonials, or highlighted excerpts.' },
{ guidance: true, description: 'Provide cite when source is known.' },
+ { guidance: true, description: 'Pass the source via cite, not inside children.' },
{ guidance: false, description: 'Use for callouts/notes; use Banner instead.' },
+ { guidance: false, description: 'Wrap the attribution in <footer>; it becomes a contentinfo landmark.' },
],
},
propDescriptions: {
children: 'blockquote content',
- cite: 'optional attribution rendered in <footer><cite>',
+ cite: 'optional attribution rendered as <cite> after the quote',
xstyle: 'StyleX styles for layout; must be stylex.create() value',
},
};
diff --git a/packages/core/src/Blockquote/Blockquote.test.tsx b/packages/core/src/Blockquote/Blockquote.test.tsx
index 2c3d51d858..751ab38bdc 100644
--- a/packages/core/src/Blockquote/Blockquote.test.tsx
+++ b/packages/core/src/Blockquote/Blockquote.test.tsx
@@ -11,6 +11,7 @@
import {describe, it, expect, vi} from 'vitest';
import {render, screen} from '@testing-library/react';
+import {renderToString} from 'react-dom/server';
import {Blockquote} from './Blockquote';
describe('Blockquote', () => {
@@ -31,7 +32,6 @@ describe('Blockquote', () => {
it('renders without cite by default', () => {
render(<Blockquote data-testid="bq">Quote</Blockquote>);
const element = screen.getByTestId('bq');
- expect(element.querySelector('footer')).toBeNull();
expect(element.querySelector('cite')).toBeNull();
});
@@ -42,13 +42,34 @@ describe('Blockquote', () => {
</Blockquote>,
);
const element = screen.getByTestId('bq');
- const footer = element.querySelector('footer');
- expect(footer).toBeInTheDocument();
const cite = element.querySelector('cite');
expect(cite).toBeInTheDocument();
expect(cite).toHaveTextContent('Steve Jobs');
});
+ it('never wraps the attribution in a landmark element', () => {
+ render(
+ <Blockquote cite="Steve Jobs" data-testid="bq">
+ Quote
+ </Blockquote>,
+ );
+ const element = screen.getByTestId('bq');
+ expect(element.querySelector('footer')).toBeNull();
+ expect(screen.queryByRole('contentinfo')).toBeNull();
+ });
+
+ it.each([
+ ['false', false],
+ ['an empty string', ''],
+ ])('renders no cite element when cite is %s', (_label, cite) => {
+ render(
+ <Blockquote cite={cite} data-testid="bq">
+ Quote
+ </Blockquote>,
+ );
+ expect(screen.getByTestId('bq').querySelector('cite')).toBeNull();
+ });
+
it('renders cite as ReactNode', () => {
render(
<Blockquote
@@ -87,4 +108,14 @@ describe('Blockquote', () => {
);
expect(screen.getByTestId('child-p')).toBeInTheDocument();
});
+
+ it('renders on the server', () => {
+ const html = renderToString(
+ <Blockquote cite="Steve Jobs">Design is how it works.</Blockquote>,
+ );
+ expect(html).toContain('<blockquote');
+ expect(html).toContain('astryx-blockquote');
+ expect(html).toContain('<cite');
+ expect(html).toContain('Steve Jobs');
+ });
});
diff --git a/packages/core/src/Blockquote/Blockquote.tsx b/packages/core/src/Blockquote/Blockquote.tsx
index f32e628142..80c9858421 100644
--- a/packages/core/src/Blockquote/Blockquote.tsx
+++ b/packages/core/src/Blockquote/Blockquote.tsx
@@ -17,7 +17,7 @@ import type {ReactNode} from 'react';
import type {BaseProps} from '../BaseProps';
import * as stylex from '@stylexjs/stylex';
import {colorVars, spacingVars, typeScaleVars} from '../theme/tokens.stylex';
-import {mergeProps} from '../utils';
+import {isRenderable, mergeProps} from '../utils';
import {themeProps} from '../utils/themeProps';
export interface BlockquoteProps extends BaseProps<HTMLQuoteElement> {
@@ -26,7 +26,8 @@ export interface BlockquoteProps extends BaseProps<HTMLQuoteElement> {
/** Content of the blockquote */
children: ReactNode;
/**
- * Optional attribution for the quote. Rendered in a <footer> with <cite>.
+ * Optional attribution for the quote. Rendered in a `<cite>` element after
+ * the quoted content.
*/
cite?: ReactNode;
}
@@ -38,6 +39,7 @@ const styles = stylex.create({
borderInlineStartColor: colorVars['--color-border-emphasized'],
paddingInlineStart: spacingVars['--spacing-4'],
color: colorVars['--color-text-secondary'],
+ overflowWrap: 'break-word',
marginInlineStart: 0,
marginInlineEnd: 0,
marginBlockStart: 0,
@@ -55,8 +57,8 @@ const styles = stylex.create({
/**
* Blockquote component for displaying quoted content.
*
- * Renders a semantic `<blockquote>` with an accent-colored left border
- * and secondary text color, matching the Astryx visual language.
+ * Renders a semantic `<blockquote>` with an inline-start rule and secondary
+ * text color, matching the Astryx visual language.
*
* @example
* ```
@@ -83,11 +85,11 @@ export function Blockquote({
)}
{...props}>
{children}
- {cite != null && (
- <footer>
- <cite {...stylex.props(styles.cite)}>{cite}</cite>
- </footer>
- )}
+ {/*
+ A bare <cite>, never wrapped in <footer>: <blockquote> is a sectioning
+ root, so a <footer> inside it maps to a contentinfo document landmark.
+ */}
+ {isRenderable(cite) && <cite {...stylex.props(styles.cite)}>{cite}</cite>}
</blockquote>
);
}