cssangularangular-ngselect

ng-select multiple - Change height


This is related to the question at ng-select - Change height . I want to do the exact same but with a ng-select that enables multiple items to be selected.

Here is my code of the ng-select:

<label class="col-sm-4 text-sm-right col-form-label">Payout Format</label>
                <div class="col-sm-8">
                    <ng-select
                        [items]="payoutFormats"
                        [multiple]="true"
                        [closeOnSelect]="true"
                        [searchable]="true"
                        bindValue="payoutBatchFormatID"
                        bindLabel="name"
                        placeholder="All"
                        [(ngModel)]="filter.payoutFormats"
                        name="payoutFormats">
                    </ng-select>
                </div>

In my component I have added the following styles:

@Component({
    templateUrl: './test.component.html',
    styles: [`
        .ng-select{
            font-size:0.85em;
        }

        .ng-select .ng-select-container {
            min-height: 3px;
        }

        .ng-select.ng-select-multiple .ng-select-container {
            height: 3px;
        }
  `],
})

I was able to get this working with a non multiple select box by using

.ng-select.ng-select-single .ng-select-container {
  height: 20px;
}

But changing it from .ng-select.ng-select-single to .ng-select.ng-select-multiple when multiple is enabled has no effect on the height.

Here is how my select looks like after the CSS:

enter image description here

I need it to be smaller.

UPDATE

In dev tools I can change min-height in .ng-select .ng-select-container as follows:

enter image description here

And my select box appears smaller:

enter image description here

However adding the same style to my component styling does not pick this up:

@Component({
    templateUrl: './list-exceptions-handling-payments.component.html',
    styles: [`
        .ng-select{
            font-size:0.85em;
        }

        .ng-select .ng-select-container{
            min-height: 3px;
        }


        .ng-select.ng-select-multiple .ng-select-container {
            height: 3px;
        }

  `],
})

Solution

  • You have overriden .ng-select-container and .ng-select-multiple which is correct but you hadn't overriden it's children elements.

    Multiple select checkboxes have additional elements compared to select element (deselect button, view selected choices, etc)

    These are in

    <div class="ng-value-container">
        <div class="ng-value>
        ....
    

    enter image description here

    ng-value divs contain mendoza and franklin elements:

    enter image description here

    You need to adjust the height/line-height/margin/padding defined in these children elements.

    EDIT:

    You need to make your child elements smaller also before the parent element will decrease in size. E.g. in GIF:

    enter image description here