Skip to content

feat(css,Dialog,Grid Cell,Page)!: Add inline size containment context to 3 components and as CSS utility#2562

Open
RubenSibon wants to merge 15 commits intodevelopfrom
feat/DES-1806-inline-size-containment-context-utility
Open

feat(css,Dialog,Grid Cell,Page)!: Add inline size containment context to 3 components and as CSS utility#2562
RubenSibon wants to merge 15 commits intodevelopfrom
feat/DES-1806-inline-size-containment-context-utility

Conversation

@RubenSibon
Copy link
Copy Markdown
Contributor

Add inline-size containment context to Page, Grid Cell, and Dialog

What

  • Add an ams-inline-size-context CSS utility class that turns any element into a container query context for its inline size.
  • Page, Grid Cell, and Dialog now intrinsically provide this context. Each has a component-specific container name (e.g. ams-page-containment-context) alongside the shared ams-inline-size-context name, so descendants can query either one.
  • Grid Cell's container name changes from ams-grid-cell to ams-grid-cell-containment-context ams-inline-size-context.

Why

Components need to adapt their layout to the available inline size of their container rather than the viewport. A shared container name across Page, Grid Cell, and Dialog allows a single @container rule to work regardless of which ancestor provides the context.

How

  • New ams-inline-size-context utility class with its own design tokens for container-name and container-type.
  • Added container-name and container-type tokens and CSS properties to Page and Dialog.
  • Updated Grid Cell's existing container-name token to include the shared name.
  • Added Storybook story and docs for the utility; updated docs for Page, Grid, and Dialog.

Checklist

  • Add or update unit tests (not relevant)
  • Add or update documentation
  • Add or update stories
  • Add or update exports in index.* files
  • Comment /chromatic test and verify visual regression tests pass
  • Start the PR title with a Conventional Commit prefix, as explained here.

Additional notes

  • Breaking change: Grid Cell's container-name token value changed from ams-grid-cell to ams-grid-cell-containment-context ams-inline-size-context. Any @container ams-grid-cell (…) rules must be updated. No usages were found in this repo.

@RubenSibon RubenSibon self-assigned this Apr 17, 2026
Copilot AI review requested due to automatic review settings April 17, 2026 09:05
@RubenSibon RubenSibon requested a review from a team as a code owner April 17, 2026 09:05
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 17, 2026

Coverage Report for React components

Status Category Percentage Covered / Total
🟢 Lines 98.62% 715 / 725
🟢 Statements 97.64% 745 / 763
🟠 Functions 93.36% 183 / 196
🟢 Branches 97.92% 518 / 529
File CoverageNo changed files found.
Generated in workflow #35 for commit 3f69923 by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 17, 2026

Size Change: +109 B (+0.18%)

Total Size: 59.1 kB

📦 View Changed
Filename Size Change
packages-proprietary/tokens/dist/index.css 8.89 kB +54 B (+0.61%)
packages/css/dist/index.css 14.1 kB +55 B (+0.39%)
ℹ️ View Unchanged
Filename Size
packages-proprietary/tokens/dist/compact.css 574 B
packages/react/dist/index.esm.js 35.1 kB
packages/react/dist/index.js 464 B

compressed-size-action

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a shared CSS container-query context for inline size, enabling components to respond to the available width of their nearest container (Page/Grid Cell/Dialog) instead of the viewport.

Changes:

  • Added an ams-inline-size-context CSS utility (SCSS + tokens) and Storybook story/docs for it.
  • Updated Page and Dialog to intrinsically establish an inline-size container query context via new design tokens and CSS properties.
  • Updated Grid Cell’s container name token to include both a component-specific name and the shared ams-inline-size-context name.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
storybook/src/utils/InlineSizeContext/InlineSizeContext.tsx Adds a mock wrapper component for Storybook examples.
storybook/src/utils/InlineSizeContext/InlineSizeContext.stories.tsx Story demonstrating the inline-size containment context utility.
storybook/src/utils/InlineSizeContext/InlineSizeContext.docs.mdx Storybook docs page rendering the CSS README for the utility.
storybook/src/components/Page/Page.docs.mdx Repositions the “Home Page” reference into the examples section.
packages/css/src/components/page/page.scss Makes .ams-page a container query context via tokenized container-name/type.
packages/css/src/components/page/README.md Documents Page as an inline-size container query context and adds guidelines.
packages/css/src/components/inline-size-context/inline-size-context.scss Adds .ams-inline-size-context utility class styles.
packages/css/src/components/inline-size-context/README.md Documents the new inline-size context utility and how to use/override it.
packages/css/src/components/index.scss Includes the new inline-size-context SCSS entrypoint.
packages/css/src/components/grid/README.md Updates Grid docs to describe Grid Cell as the container query context.
packages/css/src/components/dialog/dialog.scss Makes .ams-dialog a container query context via tokenized container-name/type.
packages/css/src/components/dialog/README.md Documents Dialog as providing a container query context.
packages-proprietary/tokens/src/components/ams/page.tokens.json Adds Page container-name/type tokens including shared + component-specific names.
packages-proprietary/tokens/src/components/ams/inline-size-context.tokens.json Adds tokens for the utility’s default container name/type.
packages-proprietary/tokens/src/components/ams/grid.tokens.json Updates Grid Cell container-name token to include shared + component-specific names.
packages-proprietary/tokens/src/components/ams/dialog.tokens.json Adds Dialog container-name/type tokens including shared + component-specific names.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +26 to +27
This Paragraph sits inside an Inline Size Context, which establishes a containment context of type
`inline-size`. Descendants can query its inline size:
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

The backticks around inline code in the Paragraph text (e.g. inline-size) will render as literal backtick characters because Paragraph doesn’t parse Markdown. Use a element (or remove the backticks) for inline code styling.

Suggested change
This Paragraph sits inside an Inline Size Context, which establishes a containment context of type
`inline-size`. Descendants can query its inline size:
This Paragraph sits inside an Inline Size Context, which establishes a containment context of type{' '}
<code>inline-size</code>. Descendants can query its inline size:

Copilot uses AI. Check for mistakes.
@RubenSibon RubenSibon changed the title feat(css,Page,Grid Cell,Dialog)!: Add inline size containment context as utility and to some containers feat(css,Dialog,Grid Cell,Page)!: Add inline size containment context to 3 components and as CSS utility Apr 17, 2026
@RubenSibon
Copy link
Copy Markdown
Contributor Author

RubenSibon commented Apr 17, 2026

@alimpens, this PR adds the container-* properties to a new CSS utility and to 3 container components that affect the page's layout.

Currently, not a single child component uses container queries so no side-effecting is taking place.

PR #2539 will add container queries, but I’m working on a system so that media queries do still work by default. Only when the container queries find a containment context up the tree will the media queries be overridden. Watch for those changes when they come.

With these two pieces of information I believe your concerns about isolated CSS and side effects are properly addressed/mitigated?

@alimpens
Copy link
Copy Markdown
Contributor

@alimpens, this PR adds the container-* properties to a new CSS utility and to 3 container components that are affect the page's layout.

Currently, not a single child component uses container queries so no side-effecting is taking place.

PR #2539 will add container queries, but I’m working on a system so that media queries do still work by default. Only when the container queries find a containment context up the tree will the media queries be overridden. Watch for those changes when they come.

With these two pieces of information I believe your concerns about isolated CSS and side effects are properly addressed/mitigated?

Well, sort of. It seems container queries cannot really be used scoped to a component, dependencies on other components are (almost?) always necessary. This undermines the component isolation we currently do have, and makes the system less robust.

It's nice that we'll fall back on media queries when container queries do not work, but that's still patching an issue we're creating by using container queries in the first place. Imo, if a problem is solvable without using container queries, that should always have preference.

@RubenSibon
Copy link
Copy Markdown
Contributor Author

Imo, if a problem is solvable without using container queries, that should always have preference.

I agree, for DL we could look at a way so that it collapses (wraps) from a default horizontal orientation to a vertical orientation when it gets too little inline size. That solution would avoid both media and container queries altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants