Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/ui/src/lib/components/select/select-popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class ScSelectPopup {

protected readonly class = computed(() =>
cn(
'bg-popover text-popover-foreground ring-foreground/10 relative z-50 mt-1 flex w-full max-h-44 min-w-36 flex-col rounded-lg p-1 shadow-md ring-1',
'bg-popover text-popover-foreground ring-foreground/10 relative z-50 flex w-full max-h-44 min-w-36 flex-col rounded-lg p-1 shadow-md ring-1',
this.combobox.expanded()
? 'opacity-100 visible transition-[max-height,opacity,visibility] duration-150 ease-out'
: 'max-h-0 opacity-0 invisible transition-[max-height,opacity,visibility] duration-150 ease-in [transition-delay:0s,0s,150ms]',
Expand Down
33 changes: 27 additions & 6 deletions libs/ui/src/lib/components/select/select.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Combobox, ComboboxPopupContainer } from '@angular/aria/combobox';
import { OverlayModule } from '@angular/cdk/overlay';
import { ConnectedPosition, OverlayModule } from '@angular/cdk/overlay';
import { NgTemplateOutlet } from '@angular/common';
import {
ChangeDetectionStrategy,
Expand All @@ -19,6 +19,25 @@ import { ScSelectList } from './select-list';
import { ScSelectPortal } from './select-portal';
import { ScSelectTrigger } from './select-trigger';

const positions: ConnectedPosition[] = [
// Below, aligned to start (preferred)
{
originX: 'start',
originY: 'bottom',
overlayX: 'start',
overlayY: 'top',
offsetY: 4,
},
// Above, aligned to start (fallback when not enough space below)
{
originX: 'start',
originY: 'top',
overlayX: 'start',
overlayY: 'bottom',
offsetY: -4,
},
];

@Component({
selector: 'div[scSelect]',
exportAs: 'scSelect',
Expand All @@ -34,12 +53,10 @@ import { ScSelectTrigger } from './select-trigger';
@if (origin(); as origin) {
<ng-template
cdkConnectedOverlay
[cdkConnectedOverlay]="{
origin,
usePopover: 'inline',
matchWidth: true,
}"
[cdkConnectedOverlayOrigin]="origin"
[cdkConnectedOverlayOpen]="true"
[cdkConnectedOverlayPositions]="positions"
[cdkConnectedOverlayMinWidth]="triggerWidth()"
>
<ng-container [ngTemplateOutlet]="selectPortal().templateRef" />
</ng-template>
Expand All @@ -65,12 +82,16 @@ export class ScSelect implements FormValueControl<string> {
protected readonly selectPortal = contentChild.required(ScSelectPortal);

readonly origin = computed(() => this.trigger()?.elementRef);
readonly triggerWidth = computed(
() => this.trigger()?.elementRef.nativeElement.offsetWidth ?? 0,
);
readonly values = computed(() => this.content()?.values() ?? []);
readonly displayValue = computed(() => this.value() || this.placeholder());
protected readonly class = computed(() =>
cn('relative min-w-36 w-fit', this.classInput()),
);

protected readonly positions = positions;
protected readonly combobox = inject(Combobox);

constructor() {
Expand Down