René's URL Explorer Experiment


Title: [Feature Request] Resolve conflicting classes from a component, its directives, and its template · Issue #71888 · angular/angular · GitHub

Open Graph Title: [Feature Request] Resolve conflicting classes from a component, its directives, and its template · Issue #71888 · angular/angular

X Title: [Feature Request] Resolve conflicting classes from a component, its directives, and its template · Issue #71888 · angular/angular

Description: Which @angular/* package(s) are relevant/related to the feature request? core, compiler, compiler-cli Description Angular applies the union of an element's classes from the component's host, its other directives, and the template. With u...

Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? core, compiler, compiler-cli Description Angular applies the union of an element's classes from the component's host, its ot...

X Description: Which @angular/* package(s) are relevant/related to the feature request? core, compiler, compiler-cli Description Angular applies the union of an element's classes from the component's host...

Opengraph URL: https://github.com/angular/angular/issues/71888

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Feature Request] Resolve conflicting classes from a component, its directives, and its template","articleBody":"### Which @angular/\\* package(s) are relevant/related to the feature request?\n\ncore, compiler, compiler-cli\n\n### Description\n\nAngular applies the union of an element's classes from the component's host, its other directives, and the template. With utility CSS such as Tailwind, conflicting classes both stay, and the stylesheet picks the winner:\n\n```ts\n@Component({\n  selector: 'ui-button',\n  host: {class: 'px-4 py-2'},\n  template: '\u003cng-content />',\n})\nexport class UiButton {}\n```\n\n```html\n\u003cui-button class=\"px-2\">Save\u003c/ui-button>\n\u003c!-- Today: class=\"px-4 py-2 px-2\". px-2 may or may not win. -->\n\u003c!-- Wanted: class=\"py-2 px-2\". -->\n```\n\nLibraries work around it with an input aliased to `class` and a computed host `[class]`, as spartan-ng does. That can't see `[class.x]` bindings or other directives' classes, and each library reimplements it.\n\n### Proposed solution\n\nAn app provides a resolver, and a `(class)` binding resolves an element's classes with it. A prototype is implemented and tested: https://github.com/Flarette/angular/pull/5. Reference: https://github.com/Flarette/angular/blob/feat/class-resolver/docs/class-resolver.md\n\n#### Provide a resolver\n\n```ts\nbootstrapApplication(App, {providers: [provideClassResolver(twMerge)]});\n\n// Angular calls it with one string per source, lowest priority first:\ntwMerge('px-4 py-2' /* component */, '' /* directives */, 'px-2' /* template */); // 'py-2 px-2'\n```\n\nAny `(...classes: string[]) => string` fits. Without a provider, classes merge as they do today. A library can scope its own resolver with `viewProviders`.\n\n#### Resolve a component's host\n\n```ts\n@Component({\n  selector: 'ui-button',\n  host: {class: 'px-4 py-2 bg-primary', '(class)': 'classes'},\n  template: '\u003cng-content />',\n})\nexport class UiButton {\n  readonly disabled = input(false);\n  protected readonly classes: ClassCallback = (twMerge) => twMerge(this.disabled() && 'bg-muted');\n}\n```\n\n```html\n\u003cui-button class=\"px-2\" />\n\u003c!-- class=\"py-2 bg-primary px-2\" -->\n\n\u003cui-button class=\"px-2 bg-danger\" [disabled]=\"true\" />\n\u003c!-- class=\"py-2 px-2 bg-danger\": the template still wins over the component's extra bg-muted -->\n```\n\n#### Resolve in a template\n\n```html\n\u003cui-button class=\"px-2\" (class)=\"(twMerge) => twMerge('shadow-lg', busy() && 'opacity-50')\" />\n```\n\n`(class)=\"F\"` is shorthand for `(attr.class)=\"$event.resolve((F)($event.resolver))\"`. The full form gives a handler the classes of each source:\n\n```ts\n@Component({\n  selector: 'app-toolbar',\n  imports: [UiButton],\n  template: `\u003cui-button class=\"px-2\" (attr.class)=\"resolveButton($event)\" />`,\n})\nexport class Toolbar {\n  readonly busy = signal(false);\n  readonly compact = signal(false);\n\n  protected resolveButton(event: ClassResolveEvent) {\n    // event.sources, after UiButton's own host resolver ran:\n    // [['py-2', 'bg-primary'], [], ['px-2']]\n    if (this.compact()) {\n      event.resolve('px-1 py-1'); // exact classes, no resolver\n    } else if (this.busy()) {\n      event.resolve(event.resolver('opacity-50')); // twMerge with an extra class\n    }\n    // No resolve() call: the element keeps the classes as collected.\n  }\n}\n```\n\nThe shorthand must return what its resolver returns. Both of these are compile errors:\n\n```html\n\u003cdiv (class)=\"(twMerge) => 'px-2'\">\u003c/div>\n\u003cdiv (class)=\"onClick\">\u003c/div>\n```\n\n#### Resolve every element\n\n```ts\nbootstrapApplication(App, {providers: [provideClassResolver(twMerge, withAutoResolution())]});\n\n@Component({\n  // Off for this component's template.\n  viewProviders: [provideClassResolver(twMerge)],\n})\nexport class LegacyWidget {}\n```\n\nEvery element that a component or directive matches resolves without a binding.\n\n#### Several resolvers on one element\n\nPriority: template > directives > component. Every resolver runs, lowest priority first, and each gets the previous result as its sources.\n\n```ts\n@Component({\n  selector: 'ui-button',\n  host: {class: 'px-4 bg-primary', '(class)': 'resolve'},\n  template: '\u003cng-content />',\n})\nexport class UiButton {\n  protected readonly resolve: ClassCallback = (twMerge) => twMerge('rounded');\n}\n\n@Directive({\n  selector: '[tone]',\n  host: {class: 'bg-gray-100', '(class)': 'resolve'},\n})\nexport class Tone {\n  protected readonly resolve: ClassCallback = (twMerge) => twMerge('text-gray-900');\n}\n```\n\n```html\n\u003cui-button tone class=\"px-2 bg-white\" (class)=\"(twMerge) => twMerge('shadow')\" />\n```\n\n```text\nsources        component 'px-4 bg-primary'   directives 'bg-gray-100'    template 'px-2 bg-white'\n1. UiButton    component 'rounded'           directives ''               template 'px-2 bg-white'\n2. Tone        component 'rounded'           directives 'text-gray-900'  template 'px-2 bg-white'\n3. template    class=\"rounded text-gray-900 px-2 bg-white shadow\"\n```\n\nEach resolver's extra classes join its own source, so a component's extras are defaults that directives and the template override.\n\n#### Cost\n\nAbout 2 µs or less per resolved element in dev mode, not counting the resolver. Apps that don't use it don't bundle it.\n\n#### Breaking changes\n\n```ts\n@Directive({selector: '[dir]'})\nexport class Dir {\n  // `\u003cdiv dir (class)=\"...\">` no longer listens to this output. NG8120 warns.\n  readonly class = output\u003cstring>();\n}\n```\n\n```ts\n@HostListener('class') onClass() {} // Now a compile error.\n```\n\nOutputs named `class` are rare. Until #71661, such an output also dropped the element's `[class]` binding, so apps are unlikely to depend on one.\n\n### Alternatives considered\n\nToday's alternative is the userland workaround above. The open design choices, with why the prototype chose what it did:\n\n- **All attributes, not only `class`.** `aria-describedby` and other token lists have the same problem:\n\n  ```ts\n  provideAttributeResolvers({class: twMerge, 'aria-describedby': joinIds});\n  ```\n\n  The prototype resolves only `class`, because each attribute needs its own merge rule. Other `(attr.*)` names stay ordinary event bindings, so the namespace is still free for this.\n\n- **Styles.** A `(style)` counterpart that resolves conflicting style declarations. Not designed yet.\n- **The shorthand's shape.** Today the callback gets only the bound resolver. It could also get the sources:\n\n  ```html\n  \u003c!-- Today -->\n  \u003cdiv (class)=\"(twMerge) => twMerge('px-2')\">\u003c/div>\n  \u003c!-- With the sources as a second argument -->\n  \u003cdiv (class)=\"(twMerge, sources) => twMerge(...sources[0], 'px-2')\">\u003c/div>\n  \u003c!-- The first prototype: the callback got the sources and returned the classes,\n       which a component method merged -->\n  \u003cdiv (class)=\"(sources) => merge(sources, 'px-2')\">\u003c/div>\n  ```\n\n  Why the prototype chose today's shape:\n  - **The callback returns what the resolver returns.** An earlier version used a handler's return value as the classes. No other Angular event does that, the value wasn't type-checked, and a later statement in a handler could replace the classes silently. The result is now an opaque type that only the resolver creates, so the compiler rejects `(twMerge) => 'px-2'`, and a cast fails in dev mode.\n  - **The sources stay in the full form.** A handler that needs them uses `(attr.class)` and `$event.sources`. The shorthand stays one call for the common case.\n  - **Extras join the caller's source.** Appending them after every source let a component's extras beat the consumer's classes.\n  - **The resolver takes and returns strings:** `(...classes: string[]) => string`. A string is what a DOM attribute takes natively, for any attribute, so the same contract can serve a resolver for any attribute. `class` adds one step: Angular first reads extras and `resolve()` values the way a `[class]` binding does, so arrays, Sets, and object maps work, and `false` adds nothing. `twMerge` and a shadcn `cn` fit unchanged. A contract that takes `[class]` values fails `twMerge`'s types, and declaration merging for the extras' type breaks when two libraries augment it differently.\n\n- **Several resolvers.** Every resolver runs, and each gets the previous result back in its sources. Letting one resolver replace the others depended on `imports` order and dropped a library's logic silently. Letting a lower resolver delegate upward let its appended classes beat the consumer's.\n- **Naming.** `(class)` and `(attr.class)` collide with outputs named `class`. A name such as `(class.resolve)` avoids the breaking change, but it loses the short form, and `(class.x)` reads like a modifier, as in `(keydown.enter)`.\n- **Automatic resolution's reach.** It could resolve every element. The prototype chose not to: every element would pay the extra cost, and an element that no component or directive matches has only the template's classes, so it has no conflict to resolve. A template that needs a merge there can import `twMerge` and bind `[class]` to its result. Resolving every element would trade explicitness and performance for consistency and less boilerplate.\n\n\n### RFC\n\nThe class resolution is a special case of the  #67519, Angular has no API for resolving host conflicts and relies on defaults (classes join, Id's override). Other frameworks avoid it by not having the selectors, in angular it is a friction point. The full feature could resolve any attribute, with shorthands such as `(class)` for the common cases or cases with special defaults ex: (class) accepting same types as [class]. Before proceeding with the implementation i want to hear the opinion of the maintainers and users if this API fits the angular vision\n","author":{"url":"https://github.com/Flarette","@type":"Person","name":"Flarette"},"datePublished":"2026-11-08T21:33:58Z","url":"https://github.com/angular/angular/issues/71888"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:2d0eb349-4bed-7354-5471-bc3ec95892b4
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA6A4:23CF06:F3ED90:13A0D5D:6B00FDF9
html-safe-nonce9f711485b91fb9d98ebb26bc69ab7344b8cb08e4ba5ef30d6d7cc035503cecb5
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNkE0OjIzQ0YwNjpGM0VEOTA6MTNBMEQ1RDo2QjAwRkRGOSIsInZpc2l0b3JfaWQiOiI0MzIyMDk0MTk5NTY3NjEzNDMzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmace523d0d43e79a7c10a2be703c04c2a047ae7a508e3240401afbd9ffc6912f9df
hovercard-subject-tagissue:6275877673
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/71888/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c9b38fc50640427c8ec8ca9f96f83c0cb36ec1a4c93e271d5ebc4e675f109133/angular/angular/issues/71888
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c9b38fc50640427c8ec8ca9f96f83c0cb36ec1a4c93e271d5ebc4e675f109133/angular/angular/issues/71888
og:image:altWhich @angular/* package(s) are relevant/related to the feature request? core, compiler, compiler-cli Description Angular applies the union of an element's classes from the component's host, its ot...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameFlarette
hostnamegithub.com
expected-hostnamegithub.com
Nonee208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187
turbo-cache-controlno-preview
go-importgithub.com/angular/angular git https://github.com/angular/angular.git
octolytics-dimension-user_id139426
octolytics-dimension-user_loginangular
octolytics-dimension-repository_id24195339
octolytics-dimension-repository_nwoangular/angular
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id24195339
octolytics-dimension-repository_network_root_nwoangular/angular
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7dafd017fb7809a839c443dba08622af38e63c09
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/angular/angular/issues/71888#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F71888
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F71888
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=angular%2Fangular
Reloadhttps://github.com/angular/angular/issues/71888
Reloadhttps://github.com/angular/angular/issues/71888
Reloadhttps://github.com/angular/angular/issues/71888
angularhttps://github.com/angular
angularhttps://github.com/angular/angular
Codehttps://github.com/angular/angular
Issues835 (835)https://github.com/angular/angular/issues
Pull requests141 (141)https://github.com/angular/angular/pulls
Discussionshttps://github.com/angular/angular/discussions
Actionshttps://github.com/angular/angular/actions
Projectshttps://github.com/angular/angular/projects
Security and quality40 (40)https://github.com/angular/angular/security
Insightshttps://github.com/angular/angular/insights
https://github.com/angular/angular
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/71888
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/71888
[Feature Request] Resolve conflicting classes from a component, its directives, and its templatehttps://github.com/angular/angular/issues/71888#top
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
needsTriagehttps://github.com/angular/angular/milestone/83
https://github.com/Flarette
Flarettehttps://github.com/Flarette
on Nov 8, 2026https://github.com/angular/angular/issues/71888#issue-6275877673
Flarette#5https://github.com/Flarette/angular/pull/5
https://github.com/Flarette/angular/blob/feat/class-resolver/docs/class-resolver.mdhttps://github.com/Flarette/angular/blob/feat/class-resolver/docs/class-resolver.md
#71661https://github.com/angular/angular/pull/71661
#67519https://github.com/angular/angular/issues/67519
angular-robothttps://github.com/apps/angular-robot
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
on Nov 8, 2026https://github.com/angular/angular/issues/71888#event-35514717307
angular-robothttps://github.com/apps/angular-robot
needsTriagehttps://github.com/angular/angular/milestone/83
on Nov 8, 2026https://github.com/angular/angular/issues/71888#event-35514718465
ngbothttps://github.com/apps/ngbot
needsTriagehttps://github.com/angular/angular/milestone/83
on Nov 8, 2026https://github.com/angular/angular/issues/71888#event-35514718550
Flarettehttps://github.com/Flarette
on Nov 8, 2026https://github.com/angular/angular/issues/71888#event-35514822992
JeanMechehttps://github.com/JeanMeche
duplicatehttps://github.com/angular/angular/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Aduplicate
[Feature Request] Provide ability to specify class resolution logic at component's host when supplied by multiple sources. #67519https://github.com/angular/angular/issues/67519
on Nov 8, 2026https://github.com/angular/angular/issues/71888#event-35518334112
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular/issues/71888
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular/issues/71888
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
needsTriageNo due datehttps://github.com/angular/angular/milestone/83
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.