Skip to content

mat-select is scrolling up when selecting - continuation #30931

Closed
@AntonBobylev

Description

@AntonBobylev

The select expects options to be of a certain height and we currently don't support overriding it so you're doing it at your own risk.

Originally posted by @crisbeto in #18154

Look, I have the multiple mat-select, all rows have equal height, but scroll moves itself when select any option.

scroll.webm

template:

<div style="position: relative; width: 100%">
    <div class="loading-spinner-wrapper"
         [style.display]="isLoading() ? 'flex' : 'none'"
    >
        <app-loading-spinner [isLoading]="isLoading()" />
    </div>

    <mat-form-field appearance="outline"
                    [formGroup]="parentFormGroup"
                    [floatLabel]="floatLabel"
    >
        @if (label) {
            <mat-label>{{ label }}</mat-label>
        }
        <mat-select #fieldCtrl
                    [multiple]="isSupercombo"
                    [formControlName]="name"
                    [placeholder]="placeholder"
                    (valueChange)="onValueChanged.emit($event)"
        >
            @if (isSupercombo && valuesSeparator !== ',') {
                <mat-select-trigger>
                    <span>{{ getSelectedItemsDisplayValue() }}</span>
                </mat-select-trigger>
            }

            <!--@if (searchRequired && !EmsowAngular.isEmpty(data)) {
                <mat-option>
                    <ngx-mat-select-search [formControl]="searchCtrl"
                                           [noEntriesFoundLabel]="searchNothingFoundMessage"
                                           [placeholderLabel]="searchTooltip"
                                           [showToggleAllCheckbox]="showToggleAllCheckbox"
                                           (toggleAll)="onToggleAll($event)"
                                           [toggleAllCheckboxTooltipMessage]="toggleAllTooltip"
                    >
                        <mat-icon ngxMatSelectSearchClear
                                  class="material-symbols-outlined"
                        >
                            close
                        </mat-icon>
                    </ngx-mat-select-search>
                </mat-option>
            }-->

            @if (emptyOptionRequired) {
                <mat-option><span class="option">{{ emptyOptionLabel }}</span></mat-option>
            }

            <mat-option *ngFor="let record of filteredRecords()"
                        [value]="record"
            >
                <span class="option">{{ record.displayValue }}</span>
            </mat-option>
        </mat-select>

        @if (isAddNewEntity) {
            <app-icon-button matSuffix
                             icon="add"
                             (onClickEvent)="onAddNewEntity($event)"
            />
        }

        @if (clearBtnRequired && getValue() && !EmsowAngular.isEmpty(getValue())) {
            <app-icon-button matSuffix
                             icon="close"
                             (onClickEvent)="clear($event)"
            />
        }
    </mat-form-field>
</div>

styles:

mat-form-field {
    width: 100%;
}

.option {
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions