Skip to content

fix: float the standalone component dropdown so it overlays content#506

Merged
almothafar merged 1 commit into
ng2-ui:masterfrom
almothafar:fix/component-dropdown-overlay
Jun 7, 2026
Merged

fix: float the standalone component dropdown so it overlays content#506
almothafar merged 1 commit into
ng2-ui:masterfrom
almothafar:fix/component-dropdown-overlay

Conversation

@almothafar

Copy link
Copy Markdown
Collaborator

Problem

When <ngui-auto-complete> is used as a standalone component and its dropdown opens downward (the default), the list <ul> is rendered in normal document flow. So it takes up layout space — expanding its host, growing the surrounding card, and scrolling the page — instead of floating over the content below.

Only the upward .dropup variant was floated (position: absolute; bottom: 100%); the down case had no positioning. That asymmetry is the bug.

Fix

In auto-complete.component.scss, float the list by default, mirroring .dropup:

.ngui-auto-complete > ul {
  position: absolute;
  top: 100%;
  inset-inline-start: 0;
  z-index: var(--ngui-ac-z-index, 10);
  /**/
}
.ngui-auto-complete > ul.dropup { top: auto; bottom: 100%; }

The directive renders this same component inside a CDK overlay, which already floats the list and must measure its height to flip/reposition on overflow. So a single scoped rule keeps the list in normal flow only there, leaving the directive/overlay behavior byte-for-byte unchanged:

.cdk-overlay-pane .ngui-auto-complete > ul { position: static; }

(The component uses ViewEncapsulation.None, so these are plain global rules — no :host, and no directive change needed.)

A new --ngui-ac-z-index CSS variable (default 10) lets consumers adjust the float layer if it collides with other stacked UI.

Validation

  • npm run build-lib:prod
  • npm run build-docs
  • npx ng test auto-complete16/16 ✅ (incl. the directive overlay open/hide test)
  • npm run format:check
  • Verified visually in the demo: the three Component-tab examples now overlay instead of pushing; the Directive-tab examples (normal, open-direction "up", and near-viewport-bottom flip) are unchanged.

🤖 Generated with Claude Code

The standalone `<ngui-auto-complete>` dropdown opening downward (the default)
was rendered in normal document flow, so it expanded its host element and
pushed sibling content down / scrolled the page. Only the upward `.dropup`
variant was floated.

Float the list by default (`position: absolute; top: 100%; inset-inline-start: 0;
z-index: var(--ngui-ac-z-index, 10)`), mirroring `.dropup`, so it overlays the
content below it. The directive renders this component inside a CDK overlay
(which floats and measures the list itself), so a scoped rule keeps the list in
normal flow there — `.cdk-overlay-pane .ngui-auto-complete > ul { position: static }`
— leaving the directive/overlay behavior unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@almothafar almothafar merged commit 7c89b17 into ng2-ui:master Jun 7, 2026
2 checks passed
almothafar added a commit that referenced this pull request Jun 7, 2026
Added in the dropdown-overlay fix (#506) but missing from the README theming table. Documents the default (10) and that it applies to the standalone component's floating list (the directive's overlay uses its z-index input).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@almothafar almothafar deleted the fix/component-dropdown-overlay branch June 7, 2026 21:18
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.

1 participant