Skip to content

fix(grid): structural styles, scrolling and filter row in a shadow root - #18097

Open
rkaraivanov wants to merge 2 commits into
masterfrom
rkaraivanov/fix-grid-shadow-root
Open

rkaraivanov wants to merge 2 commits into
masterfrom
rkaraivanov/fix-grid-shadow-root

Conversation

@rkaraivanov

Copy link
Copy Markdown
Member

Closes #17859, closes #17860

Description

  • IgxStylesRegistrar.register() takes an optional host. The sheet is still adopted by the document. When host.getRootNode() is a ShadowRoot that does not have the sheet yet, the same sheet is adopted by that shadow root too.
  • IgxGridBaseDirective registers its structural sheet in ngOnInit with its element, instead of in the constructor without one. retain() stays in the constructor.
  • IgxForOfDirective.onScroll / onHScroll and IgxGridForOfDirective.onScroll read the scroll position from their scroll element instead of event.target.
  • IgxGridFilteringRowComponent reads its input element instead of event.target when the debounced input is handled.

Motivation / Context

#18088 tracks a grids release that works in a shadow root and uses igniteui-i18n-core 2. App Builder exports Web Components views as Lit components with an open shadow root, and they stay on grids 6.1. This pull request fixes the two causes:

Notes for review:

  • The registration moves to ngOnInit because a grid inside @if or @for is not attached in its constructor. With the host passed in the constructor, the shadow root does not get the sheet (checked with the spec below).
  • The sheet stays on the document too: the row-drag ghost is appended to document.body.
  • The pivot row-dimension for-ofs get the scroll event of the body, but they share the grid's scroll master (IgxForOfScrollSyncService), so their scroll element is the event's target.
  • An application that puts a grid in a shadow root must still add the theme to it, as the docs show for Web Components. The theme carries the core() styles, such as the virtual scrollbar.

Not fixed here: when any root component in a shadow root is destroyed, Angular removes the <style> elements of all components from that root. In Elements this happens when one igc-* element, such as an igc-column, is removed. It is tracked in a separate issue.

Type of Change (check all that apply):

  • Bug fix
  • Tests
  • Changelog

Component(s) / Area(s) Affected:

Grid, Tree Grid, Hierarchical Grid, Pivot Grid, igxFor, IgxStylesRegistrar, Elements

How Has This Been Tested?

  • Unit tests

New specs. Each one fails without the fix:

Spec Without the fix With the fix
IgxStylesRegistrar › register › with a host (7 specs) does not compile (no host) pass
grid › should apply the structural styles to a grid in the shadow root of a component no grid sheet in shadowRoot.adoptedStyleSheets pass, igx-grid-cell is display: flex
Elements › in a shadow root › should adopt the structural styles of the grid into the shadow root no grid sheet in the shadow root pass
grid › in a shadow root › should scroll to the last position of a throttled scroll startIndex 10, TypeError: Cannot read properties of null (reading 'scrollTop') startIndex 50
filtering row › in a shadow root › should filter by the value typed in the filter row 200 rows, TypeError ... (reading 'value') 1 row

The grid specs use a new IgxGridInShadowRootComponent in grid-samples.spec.ts. It renders the grid inside @if in a ShadowDom component and copies the styles of the page into its shadow root.

The two existing "scroll throttle trailing edge" specs sent { target: { scrollTop } } objects through scrollNotify. They now set scrollTop on the scroll element through a stub, which keeps them free of native scroll events.

  • npm run test:lib: 7675 of 7676 pass. The one failure, a tooltip integration spec, passes when its file runs alone (66 of 66).
  • npm run test:elements: 99 of 99.
  • npm run lint:lib: 0 errors.

Test Configuration:

  • Angular version: 22.3.0
  • Browser(s): Chromium 156 (Vitest browser mode)
  • OS: Linux (WSL2)

Checklist:

  • All relevant labels have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes API docs for newly added methods/properties (api docs guidelines)
  • This PR includes CHANGELOG.MD updates for newly added functionality

rkaraivanov and others added 2 commits December 4, 2026 13:17
The grid's structural stylesheet was adopted by the document only, so a
grid in a shadow root (a custom element or a ShadowDom component) had no
layout. IgxStylesRegistrar.register() takes an optional host and also
adopts the sheet into the host's shadow root. The grid registers in
ngOnInit, once its element is attached, also inside @if or @for.

Closes #17859
Part of #18088

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The vertical scroll handler runs after a throttle and the filter row
input handler after a debounce. In a shadow root the browser clears the
event target when the dispatch ends, so reading event.target threw and
the rows did not follow the scrollbar or the filter was not applied.
The for-of directives read the scroll element and the filter row reads
its input element instead.

Closes #17860
Part of #18088

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The example calls inject() inside ngOnInit, outside Angular’s injection context, causing NG0203 when copied into a component.

1 open issue
What changed in this PR

Fixes grid layout, scrolling, and filtering inside shadow roots for Angular components and Angular Elements, addressing #17859 and #17860.

Changes:

  • Adopts structural styles into the grid’s shadow root while retaining document styles.
  • Reads scroll and filter values from elements rather than deferred event targets.
  • Adds regression tests and changelog entries.
File Description
projects/​igniteui-angular/​test-utils/​grid-samples.spec.ts Adds a shared shadow-root grid fixture.
projects/​igniteui-angular/​grids/​grid/​src/​grid.component.spec.ts Tests shadow-root styling and throttled scrolling.
projects/​igniteui-angular/​grids/​grid/​src/​grid-filtering-row.spec.ts Tests filtering inside a shadow root.
projects/​igniteui-angular/​grids/​grid/​src/​grid-base.directive.ts Registers styles during initialization with the grid host.
projects/​igniteui-angular/​grids/​core/​src/​filtering/​base/​grid-filtering-row.component.ts Reads the filter input directly.
projects/​igniteui-angular/​directives/​src/​directives/​for-of/​for_of.directive.ts Reads positions from scroll elements.
projects/​igniteui-angular/​core/​src/​services/​styles/​styles-registrar.service.ts Adds host-aware shadow-root stylesheet adoption.
projects/​igniteui-angular/​core/​src/​services/​styles/​styles-registrar.service.spec.ts Tests host-aware stylesheet registration.
projects/​igniteui-angular-elements/​src/​app/​custom-strategy.spec.ts Tests structural styles for Elements in shadow roots.
CHANGELOG.md Documents fixes and the optional registrar host parameter.

Review effort: Balanced

Comment on lines +60 to +62
* public ngOnInit(): void {
* inject(IgxStylesRegistrar).register(STYLES_ID, MY_COMPONENT_CSS, this.elementRef.nativeElement);
* }

This branch has not been deployed

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

Projects

None yet

2 participants