An open source design system that's fully customizable and agent ready
TypeScript
fix(markdown): forward the rest of BaseProps on Markdown and List (#5288)
Alexander Blom43a0839af0c1
diff --git a/.changeset/markdown-list-forward-base-props.md b/.changeset/markdown-list-forward-base-props.mdnew file mode 100644index 0000000000..da13969719--- /dev/null+++ b/.changeset/markdown-list-forward-base-props.md@@ -0,0 +1,20 @@+---+'@astryxdesign/core': patch+---++[fix] Markdown and List forward the rest of `BaseProps`++Both declare `BaseProps`, and `BaseProps` documents that `data-*`, `aria-*` and+`role` reach the element — but each destructured a fixed set of props and+forwarded only `data-testid`, so an `aria-label` a consumer passed silently+disappeared. `<Markdown aria-label="Release notes">` named nothing, and a list+could not be labelled by a heading it did not render itself.++Consumer props spread first, so what a component sets for itself still wins:+the block root stays `role="document"`, the list keeps the explicit `role="list"`+that restores Safari/VoiceOver announcements, and a list rendering its own+header keeps that association rather than one pointed elsewhere. The+`aria-labelledby` for that header is only written when the header exists —+writing `undefined` unconditionally would erase a consumer's own label.++@lexsdiff --git a/packages/core/src/List/List.test.tsx b/packages/core/src/List/List.test.tsxindex c159ae7242..a1a124aa7d 100644--- a/packages/core/src/List/List.test.tsx+++ b/packages/core/src/List/List.test.tsx@@ -681,6 +681,44 @@ describe('List', () => {expect(screen.getByText('Simple text')).toBeInTheDocument();});+ it('forwards data and aria attributes onto the list element', () => {+ // BaseProps keeps data-*/aria-*; the list element dropped them.+ const {container} = render(+ <List listStyle="decimal" data-delimiter=")" aria-label="Steps">+ <ListItem label="First" />+ </List>,+ );+ const list = container.querySelector('ol')!;+ expect(list.getAttribute('data-delimiter')).toBe(')');+ expect(list.getAttribute('aria-label')).toBe('Steps');+ });++ it('keeps an aria-labelledby pointing outside the component', () => {+ // With no header of its own there is nothing to associate, so the+ // consumer's label must survive.+ const {container} = render(+ <List aria-labelledby="external-heading">+ <ListItem label="First" />+ </List>,+ );+ expect(container.querySelector('ul')!.getAttribute('aria-labelledby')).toBe(+ 'external-heading',+ );+ });++ it('keeps its own list role and header association', () => {+ // The rest spread comes first so a consumer prop cannot drop the+ // Safari/VoiceOver role workaround or the generated header association.+ const {container} = render(+ <List header="Steps" role="presentation" aria-labelledby="elsewhere">+ <ListItem label="First" />+ </List>,+ );+ const list = container.querySelector('ul')!;+ expect(list.getAttribute('role')).toBe('list');+ expect(list.getAttribute('aria-labelledby')).not.toBe('elsewhere');+ });+it('accepts number as description (ReactNode)', () => {render(<List>diff --git a/packages/core/src/List/List.tsx b/packages/core/src/List/List.tsxindex 0fe516ab6c..5b63cd6b67 100644--- a/packages/core/src/List/List.tsx+++ b/packages/core/src/List/List.tsx@@ -152,6 +152,7 @@ export function List({style,'data-testid': testId,ref,+ ...props}: ListProps) {const headerId = useId();const isOrdered = listStyle === 'decimal';@@ -165,8 +166,14 @@ export function List({const listElement = (<Tagref={ref as React.Ref<HTMLUListElement & HTMLOListElement>}+ // Consumer props first: everything the component sets for itself below+ // is part of its contract and wins on conflict.+ {...props}data-testid={testId}- aria-labelledby={header != null ? headerId : undefined}+ // Only when this component renders the header — writing `undefined`+ // unconditionally would erase a label a consumer pointed at their own+ // heading.+ {...(header != null ? {'aria-labelledby': headerId} : null)}{...(isOrdered && start != null && start !== 1 ? {start} : {})}// The base list style always sets list-style-type: none (markers are// custom-rendered by ListItem), and Safari/VoiceOver drops implicitdiff --git a/packages/core/src/Markdown/Markdown.test.tsx b/packages/core/src/Markdown/Markdown.test.tsxindex 54974fb9ec..193bad8d70 100644--- a/packages/core/src/Markdown/Markdown.test.tsx+++ b/packages/core/src/Markdown/Markdown.test.tsx@@ -124,6 +124,43 @@ describe('Markdown', () => {expect(second.className).toContain('astryx-markdown-paragraph');});+ describe('base props', () => {+ // BaseProps documents that data-*, aria-* and role are kept; the root+ // dropped everything but data-testid.+ it('forwards data and aria attributes to the block root', () => {+ const {container} = render(+ <Markdown data-source="turn-7" aria-label="Answer">+ Hello+ </Markdown>,+ );+ const root = container.firstElementChild!;+ expect(root.getAttribute('data-source')).toBe('turn-7');+ expect(root.getAttribute('aria-label')).toBe('Answer');+ });++ it('keeps its own role when a consumer passes one', () => {+ // The rest spread comes first precisely so the component's own+ // semantics survive a consumer prop.+ const {container} = render(+ <Markdown role="presentation">Hello</Markdown>,+ );+ expect(container.firstElementChild!.getAttribute('role')).toBe(+ 'document',+ );+ });++ it('forwards them on the inline root too', () => {+ const {container} = render(+ <Markdown display="inline" data-source="turn-7">+ Hello+ </Markdown>,+ );+ expect(container.firstElementChild!.getAttribute('data-source')).toBe(+ 'turn-7',+ );+ });+ });+describe('block spacing theme targets', () => {// Every block type renders a stable astryx-markdown-<block> class so a// theme can tune the gap around it (marginBlockStart/marginBlockEnd) viadiff --git a/packages/core/src/Markdown/Markdown.tsx b/packages/core/src/Markdown/Markdown.tsxindex 813e44eb1a..0ba2449fa8 100644--- a/packages/core/src/Markdown/Markdown.tsx+++ b/packages/core/src/Markdown/Markdown.tsx@@ -1627,6 +1627,7 @@ export function Markdown({className,style,'data-testid': testId,+ ...props}: MarkdownProps): React.ReactElement {const t = useTranslator();const LinkComponent = useLinkComponent();@@ -1749,6 +1750,8 @@ export function Markdown({const renderedInline = (<spanref={ref}+ // Consumer props first: what the component sets for itself wins.+ {...props}data-testid={testId}{...mergeProps(themeProps('markdown', {density}),@@ -1780,8 +1783,11 @@ export function Markdown({const rendered = (<div- role="document"ref={ref as React.Ref<HTMLDivElement>}+ // Consumer props first: what the component sets for itself — the+ // document role included — wins.+ {...props}+ role="document"data-testid={testId}{...mergeProps(themeProps('markdown', {density}),