Skip to content

Commit

Permalink
fix(select): prevent empty select height collapsing (#1643)
Browse files Browse the repository at this point in the history
  • Loading branch information
yggg committed Jun 28, 2019
1 parent 1658ccf commit 43655c7
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 2 deletions.
26 changes: 26 additions & 0 deletions e2e/select.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { browser, by, element, ElementArrayFinder } from 'protractor';

describe('nb-select', () => {

beforeEach((done) => {
browser.get('#/select/select-test.component').then(done);
});

it('should not shrink when has no placeholder and text', (done) => {
const checks: Promise<void>[] = [];
const selectHeights = [ 24, 32, 40, 48, 56 ];
const selectElements: ElementArrayFinder = element.all(by.tagName('nb-select'));

for (let i = 0; i < selectElements.length; i++) {
const check = Promise.all([selectElements[i].getText(), selectElements[i].getSize()])
.then(([text, { height }]) => {
expect(text).toEqual('');
expect(height).toEqual(selectHeights[i]);
});

checks.push(check);
}

Promise.all(checks).then(done);
});
});
6 changes: 6 additions & 0 deletions src/app/playground-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,12 @@ export const PLAYGROUND_COMPONENTS: ComponentLink[] = [
component: 'SelectInteractiveComponent',
name: 'Select Interactive',
},
{
path: 'select-test.component',
link: '/select/select-test.component',
component: 'SelectTestComponent',
name: 'Select Test',
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
line-height: nb-theme(select-#{$size}-text-line-height);
}

nb-select.size-#{$size} .select-button.empty::before {
content: ' ';
display: block;
height: nb-theme(select-#{$size}-text-line-height);
}

nb-select.size-#{$size}:not(.full-width),
.options-list:not(.full-width) {
max-width: nb-theme(select-#{$size}-max-width);
Expand Down
5 changes: 4 additions & 1 deletion src/framework/theme/components/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,10 @@ export class NbSelectComponent<T> implements AfterViewInit, AfterContentInit, On
const classes = [];

if (!this.selectionModel.length) {
classes.push('placeholder')
classes.push('placeholder');
}
if (!this.selectionModel.length && !this.placeholder) {
classes.push('empty');
}
if (this.isOpen) {
classes.push(this.overlayPosition);
Expand Down
19 changes: 18 additions & 1 deletion src/framework/theme/components/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import { Component, ElementRef, EventEmitter, Input, Output, QueryList, ViewChild, ViewChildren } from '@angular/core';
import {
Component,
ElementRef,
EventEmitter,
Input,
Output,
QueryList,
ViewChild,
ViewChildren,
} from '@angular/core';
import { ComponentFixture, fakeAsync, flush, TestBed } from '@angular/core/testing';
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';
Expand Down Expand Up @@ -576,6 +585,14 @@ describe('Component: NbSelectComponent', () => {
expect(() => selectFixture.ngOnDestroy()).not.toThrow();
});

it(`should has 'empty' class when has no placeholder and text`, () => {
const selectFixture = TestBed.createComponent(NbSelectComponent);
selectFixture.detectChanges();
const button = selectFixture.debugElement.query(By.css('button'));

expect(button.classes['empty']).toEqual(true);
});

it(`should set overlay width same as button inside select`, () => {
const selectFixture = TestBed.createComponent(NbSelectComponent);
const selectComponent = selectFixture.componentInstance;
Expand Down
5 changes: 5 additions & 0 deletions src/playground/with-layout/select/select-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { SelectShowcaseComponent } from './select-showcase.component';
import { SelectSizesComponent } from './select-sizes.component';
import { SelectStatusComponent } from './select-status.component';
import { SelectInteractiveComponent } from './select-interactive.component';
import { SelectTestComponent } from './select-test.component';

const routes: Route[] = [
{
Expand Down Expand Up @@ -78,6 +79,10 @@ const routes: Route[] = [
path: 'select-interactive.component',
component: SelectInteractiveComponent,
},
{
path: 'select-test.component',
component: SelectTestComponent,
},
];

@NgModule({
Expand Down
17 changes: 17 additions & 0 deletions src/playground/with-layout/select/select-test.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component } from '@angular/core';
import { NbComponentSize } from '@nebular/theme';

@Component({
template: `
<h1>Empty select height test</h1>
<nb-select *ngFor="let size of sizes" [size]="size"></nb-select>
`,
styles: [`
nb-select {
display: block;
}
`],
})
export class SelectTestComponent {
sizes: NbComponentSize[] = [ 'tiny', 'small', 'medium', 'large', 'giant' ];
}
2 changes: 2 additions & 0 deletions src/playground/with-layout/select/select.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { SelectShowcaseComponent } from './select-showcase.component';
import { SelectSizesComponent } from './select-sizes.component';
import { SelectStatusComponent } from './select-status.component';
import { SelectInteractiveComponent } from './select-interactive.component';
import { SelectTestComponent } from './select-test.component';

@NgModule({
declarations: [
Expand All @@ -40,6 +41,7 @@ import { SelectInteractiveComponent } from './select-interactive.component';
SelectSizesComponent,
SelectStatusComponent,
SelectInteractiveComponent,
SelectTestComponent,
],
imports: [
FormsModule,
Expand Down

0 comments on commit 43655c7

Please sign in to comment.