Skip to content

chore(framework): apply css variables on custom element#12928

Merged
nnaydenow merged 13 commits intomainfrom
css-vars-host
Jan 27, 2026
Merged

chore(framework): apply css variables on custom element#12928
nnaydenow merged 13 commits intomainfrom
css-vars-host

Conversation

@nnaydenow
Copy link
Contributor

@nnaydenow nnaydenow commented Jan 19, 2026

Enable customization of --sap* theming CSS variables at the component level (part one: style preparation and loading mechanism).

Example:

<ui5-button style="--sapButton_Background: red">

To support all use cases, internal --ui5* CSS variables must be defined on the custom element using the :host selector, not on the document using the :root selector.

For the same reason, all content density–related variables and direction-related variables must also be defined on :host.

Direction-related variables are now set using the :dir() selector.

For content density–related variables, there was no fully working solution before. CSS container style queries are not fully supported, and the classes and attributes used by application developers are applied outside the shadow root. This PR adds a mechanism to handle this. CSS container style queries are now used and, at build time, they are transpiled into a working solution.

To define variables, use the following syntax:

@container style(--ui5_content_density: compact) {
	:host {
		...
	}
}

All of this behavior is controlled by the cssVariablesTarget flag (accepted values: "host" and "root"). The flag is configured at the package level via package-script.js.
When this flag is enabled, all *-parameters.css files must be migrated to define variables on :host instead of :root.

For direction-related CSS variables, the :dir() selector is used. For content density–related variables, the new container style query syntax is used.

Since CSS variables are now defined at the component level, CSS variable scoping is no longer needed. As a result, the getScopedVarName function is no longer required.

Fixes: #12791

@ui5-webcomponents-bot
Copy link
Collaborator

ui5-webcomponents-bot commented Jan 19, 2026

🧹 Preview deployment cleaned up: https://pr-12928--ui5-webcomponents.netlify.app

@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview January 19, 2026 14:12 Inactive
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview January 21, 2026 20:55 Inactive
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview January 22, 2026 12:28 Inactive
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview January 22, 2026 14:24 Inactive
@nnaydenow nnaydenow changed the title wip(framework): apply css variables on custom element chore(framework): apply css variables on custom element Jan 23, 2026
@nnaydenow nnaydenow requested a review from pskelin January 23, 2026 08:55
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview January 23, 2026 14:54 Inactive
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview January 26, 2026 12:15 Inactive
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview January 26, 2026 12:35 Inactive
@nnaydenow nnaydenow merged commit 09471a1 into main Jan 27, 2026
14 checks passed
@nnaydenow nnaydenow deleted the css-vars-host branch January 27, 2026 08:02
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview January 27, 2026 08:02 Inactive
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.

[Feature Request]: Move CSS Variables from :root to components shadow DOM

3 participants