Skip to content

Add responsive table component with CSS-only mobile card layout#9222

Merged
pelikhan merged 4 commits intomainfrom
copilot/implement-responsive-table-component
Jan 7, 2026
Merged

Add responsive table component with CSS-only mobile card layout#9222
pelikhan merged 4 commits intomainfrom
copilot/implement-responsive-table-component

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 7, 2026

Implements a responsive table pattern for Astro Starlight docs that transforms standard tables into stacked cards on mobile (≤640px) using CSS only, preserving semantic HTML and screen reader accessibility.

Changes

  • ResponsiveTable.astro component: Reusable table with typed props (columns[], rows[], optional caption). Includes data-label attributes on <td> elements for mobile transformation.

  • Enhanced markdown tables: Updated custom.css with responsive styles. Desktop shows standard table layout; mobile uses display: block reflow with td::before { content: attr(data-label) } for labels. <thead> hidden visually via clip technique while remaining accessible.

  • responsive-tables.ts script: Auto-extracts headers and adds data-label attributes to markdown tables on page load. Integrated via CustomHead.astro.

Usage

Component:

<ResponsiveTable 
  columns={[
    { key: 'command', header: 'Command' },
    { key: 'status', header: 'Status', align: 'center' }
  ]}
  rows={[
    { command: 'gh aw compile', status: '✅ Stable' }
  ]}
/>

Markdown (automatic):

| Feature | Status |
|---------|--------|
| Safe Outputs | Beta |

Technical Notes

  • Transformation is CSS-only at 640px breakpoint; no JS-based conditional rendering
  • Table semantics preserved at all viewports for screen readers
  • Works with both light and dark themes
  • All existing markdown tables in docs now responsive
  • Component available for use in MDX pages when explicit table control is needed
Original prompt

Agent Prompt: Responsive Table → Card Pattern for Astro Starlight

You are an autonomous frontend engineer working in an Astro Starlight documentation site.
Your task is to design and implement a responsive, accessible table component that renders as a standard semantic HTML table on desktop and degrades gracefully into a list/card layout on mobile using CSS only (no JavaScript-based layout switching).


Objective

Create a reusable solution that:

  • Uses a single semantic <table> as the source of truth
  • Preserves accessibility and table semantics for screen readers
  • Visually transforms table rows into stacked “cards” on small screens
  • Is compatible with Astro Starlight and usable in MDX content
  • Avoids duplicated DOM trees or conditional rendering

Core Requirements

1. Component Implementation

Create a reusable component:

Path

src/components/ResponsiveTable.astro

Props

  • columns: Array of column definitions
    {
      key: string;
      header: string;
      align?: 'left' | 'center' | 'right';
    }
    
    	rows: Array of objects keyed by columns[].key
    	Optional:
    	caption
    	class

Rendering Rules
• Render a semantic

with , , and optional
• Standard row and column alignment

Mobile (≤ 640px)
• Visually hide

using an accessibility-safe technique
• Display each as a block-level “card”
• Display each must remain available to screen readers when hidden

• Use must be supported
• Content must remain keyboard navigable
• No information may be lost in the mobile layout

  1. Styling & Integration
    • CSS may be:
    • Scoped to the component, or
    • Global (e.g., in src/styles/global.css) if documented
    • The component must work inside Astro Starlight MDX pages
    • No JavaScript, media-query hooks, or client-side rendering logic

  1. Documentation & Example Usage

Provide:
• Example usage inside an MDX or .astro page
• Sample columns and rows data
• Brief documentation explaining:
• How the responsive transformation works
• When this pattern is appropriate
• Known limitations (e.g., extremely wide cell content)

Constraints
• Do not duplicate markup for mobile vs desktop
• Do not replace table semantics with div-based layouts
• Do not use JavaScript for layout switching
• Prefer clarity, maintainability, and standards compliance

Success Criteria
• Desktop displays a conventional, readable table
• Mobile displays stacked, labeled rows resembling a list
• Screen readers still interpret the structure as a table
• The solution can be copy-pasted into an Astro Starlight project and used immediately

  • integrated seamlessly into the markdown table rendering

Deliver a production-ready implementation that meets all the above requirements.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

for all column headers
• Every
must include a data-label attribute whose value is the corresponding column header
• Do not introduce non-table elements (div, span) to replace table structure

  1. Responsive Behavior (Option 1: CSS-only)

Implement responsive behavior via CSS:

Desktop
• Normal table layout
• Visible

as a row with:
• A label (from data-label)
• A value (cell content)
• Use td::before { content: attr(data-label); } to render labels
• Ensure proper spacing, wrapping, and vertical rhythm

  1. Accessibility Requirements
    • Table semantics must be preserved at all breakpoints

Copilot AI self-assigned this Jan 7, 2026
Copilot AI and others added 2 commits January 7, 2026 13:07
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add responsive table component for Astro Starlight Add responsive table component with CSS-only mobile card layout Jan 7, 2026
Copilot AI requested a review from pelikhan January 7, 2026 13:17
@@ -0,0 +1,189 @@
---
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove page

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the responsive-tables documentation page and sidebar entry in commit b3afe5a.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 7, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • telemetry.astro.build
    • Triggering command: /opt/hostedtoolcache/node/24.12.0/x64/bin/node node /home/REDACTED/.npm/_npx/aa98e6899c6baff3/node_modules/.bin/astro build (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.12.0/x64/bin/node node /home/REDACTED/work/gh-aw/gh-aw/docs/node_modules/.bin/astro build (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from pelikhan January 7, 2026 13:46
@pelikhan pelikhan marked this pull request as ready for review January 7, 2026 13:46
@pelikhan pelikhan merged commit 7bfc58e into main Jan 7, 2026
3 checks passed
@pelikhan pelikhan deleted the copilot/implement-responsive-table-component branch January 7, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants