Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add igxDropDown maxHeight input #3005

Merged
merged 7 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes for each version of this project will be documented in this file.

## 6.2.1
- `igx-drop-down`:
- Added a new property `maxHeight`, defining the max height of the drop down.

## 6.2.0
- Updated typography following the Material guidelines. Type system is now also optional and can be applied via class to the desired containers. [#2112](https://github.com/IgniteUI/igniteui-angular/pull/2112)
- **Breaking change:** Applications using Ignite UI for Angular now require the `igx-typography` class to be applied on wrapping element, like the body element for instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1584,13 +1584,10 @@ describe('igxCombo', () => {
expect(inputGroupBorder.classList.contains(CSS_CLASS_INPUTGROUP_BORDER)).toBeTruthy();
expect(inputGroupBorder.childElementCount).toEqual(0);

const dropDownWrapper = comboElement.children[1];
expect(dropDownWrapper.classList.contains(CSS_CLASS_COMBO_DROPDOWN)).toBeTruthy();
expect(dropDownWrapper.attributes.getNamedItem('ng-reflect-width').nodeValue).toEqual(defaultComboDDWidth);
expect(dropDownWrapper.childElementCount).toEqual(1);

const dropDownElement = dropDownWrapper.children[0];
const dropDownElement = comboElement.children[1];
expect(dropDownElement.classList.contains(CSS_CLASS_COMBO_DROPDOWN)).toBeTruthy();
expect(dropDownElement.classList.contains(CSS_CLASS_DROPDOWN)).toBeTruthy();
expect(dropDownElement.attributes.getNamedItem('ng-reflect-width').nodeValue).toEqual(defaultComboDDWidth);
expect(dropDownElement.childElementCount).toEqual(1);

const dropDownList = dropDownElement.children[0];
Expand Down
1 change: 1 addition & 0 deletions projects/igniteui-angular/src/lib/drop-down/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The following inputs are available in the **igx-drop-down** component:
| :--- | :--- | :--- |
| `width` | string | Sets the tab width of the control. |
| `height` | string | Sets the tab height of the control. |
| `maxHeight` | string | defines drop down maximum height |
| `allowItemsFocus` | boolean | Allows items to take focus. |
| `id` | string | Sets the drop down's id. |

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="igx-drop-down">
<div class="igx-drop-down__list" igxToggle (onOpening)="onToggleOpening($event)" (onOpened)="onToggleOpened()" (onClosing)="onToggleClosing($event)" (onClosed)="onToggleClosed()">
<ng-container *ngIf="!collapsed">
<ng-content></ng-content>
</ng-container>
</div>
</div>
<div class="igx-drop-down__list" igxToggle [style.maxHeight]="maxHeight"
(onOpening)="onToggleOpening($event)" (onOpened)="onToggleOpened()"
(onClosing)="onToggleClosing($event)" (onClosed)="onToggleClosed()">
<ng-container *ngIf="!collapsed">
<ng-content></ng-content>
</ng-container>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ describe('IgxDropDown ', () => {
IgxDropDownImageTestComponent,
IgxDropDownTabsTestComponent,
DropDownWithValuesComponent,
IgxDropDownSelectComponent
IgxDropDownSelectComponent,
DropDownWithMaxHeightComponent,
DropDownWithUnusedMaxHeightComponent
],
imports: [
IgxDropDownModule,
Expand Down Expand Up @@ -73,7 +75,7 @@ describe('IgxDropDown ', () => {
expect(currentItem.componentInstance.index).toEqual(0);
expect(list.collapsed).toEqual(false);

targetElement = fixture.debugElement.queryAll(By.css('.' + CSS_CLASS_DROP_DOWN_BASE))[0].parent;
targetElement = fixture.debugElement.queryAll(By.css('.' + CSS_CLASS_DROP_DOWN_BASE))[0];
expect(targetElement).toBeDefined();

mockObj.code = 'arrowdown';
Expand All @@ -97,15 +99,15 @@ describe('IgxDropDown ', () => {
button.click(mockObj);
tick();
fixture.detectChanges();
targetElement = fixture.debugElement.queryAll(By.css('.' + CSS_CLASS_DROP_DOWN_BASE))[0].parent;
targetElement = fixture.debugElement.queryAll(By.css('.' + CSS_CLASS_DROP_DOWN_BASE))[0];
currentItem = fixture.debugElement.queryAll(By.css('.' + CSS_CLASS_SELECTED))[0];

mockObj.code = 'arrowdown';
mockObj.key = 'arrowdown';
targetElement.triggerEventHandler('keydown', mockObj);
tick();
fixture.detectChanges();
targetElement = fixture.debugElement.queryAll(By.css('.' + CSS_CLASS_DROP_DOWN_BASE))[0].parent;
targetElement = fixture.debugElement.queryAll(By.css('.' + CSS_CLASS_DROP_DOWN_BASE))[0];
currentItem = fixture.debugElement.query(By.css('.' + CSS_CLASS_FOCUSED));

mockObj.code = 'enter';
Expand Down Expand Up @@ -152,7 +154,7 @@ describe('IgxDropDown ', () => {
let currentItem = fixture.debugElement.query(By.css('.' + CSS_CLASS_FOCUSED));
expect(currentItem.componentInstance.index).toEqual(0);

targetElement = fixture.debugElement.query(By.css('.' + CSS_CLASS_DROP_DOWN_BASE)).parent;
targetElement = fixture.debugElement.query(By.css('.' + CSS_CLASS_DROP_DOWN_BASE));
mockObj.code = 'arrowdown';
mockObj.key = 'arrowdown';
targetElement.triggerEventHandler('keydown', mockObj);
Expand Down Expand Up @@ -209,7 +211,7 @@ describe('IgxDropDown ', () => {
tick();
fixture.detectChanges();
let currentItem = fixture.debugElement.query(By.css('.' + CSS_CLASS_FOCUSED));
targetElement = fixture.debugElement.query(By.css('.' + CSS_CLASS_DROP_DOWN_BASE)).parent;
targetElement = fixture.debugElement.query(By.css('.' + CSS_CLASS_DROP_DOWN_BASE));
mockObj.code = 'ArrowDown';
mockObj.key = 'ArrowDown';
targetElement.triggerEventHandler('keydown', mockObj);
Expand Down Expand Up @@ -544,7 +546,7 @@ describe('IgxDropDown ', () => {
fixture.detectChanges();
let currentItem = fixture.debugElement.query(By.css('.' + CSS_CLASS_FOCUSED));
expect(currentItem).toBeDefined();
targetElement = fixture.debugElement.query(By.css('.' + CSS_CLASS_DROP_DOWN_BASE)).parent;
targetElement = fixture.debugElement.query(By.css('.' + CSS_CLASS_DROP_DOWN_BASE));
targetElement.triggerEventHandler('keydown', mockObj);
tick();

Expand Down Expand Up @@ -884,6 +886,32 @@ describe('IgxDropDown ', () => {
expect(dropdown.selectedItem).toEqual(dropdownItem);
expect(dropdown.collapsed).toEqual(true);
}));

it('Should properly set maxHeight option', fakeAsync(() => {
const fixture = TestBed.createComponent(DropDownWithMaxHeightComponent);
fixture.detectChanges();
const dropdown = fixture.componentInstance.dropdown;
dropdown.toggle();
tick();

fixture.detectChanges();
const ddList = fixture.debugElement.query(By.css('.igx-drop-down__list')).nativeElement;
expect(parseInt(ddList.style.maxHeight, 10)).toEqual(ddList.offsetHeight);
expect(ddList.style.maxHeight).toBe('100px');
}));

it('Should properly set maxHeight option (maxHeight value larger than needed)', fakeAsync(() => {
const fixture = TestBed.createComponent(DropDownWithUnusedMaxHeightComponent);
fixture.detectChanges();
const dropdown = fixture.componentInstance.dropdown;
dropdown.toggle();
tick();

fixture.detectChanges();
const ddList = fixture.debugElement.query(By.css('.igx-drop-down__list')).nativeElement;
expect(parseInt(ddList.style.maxHeight, 10)).toBeGreaterThan(ddList.offsetHeight);
expect(ddList.style.maxHeight).toBe('700px');
}));
});

describe('igxDropDown Unit tests', () => {
Expand Down Expand Up @@ -1674,3 +1702,23 @@ class DropDownWithValuesComponent {
{ name: 'Product 4', id: 3 },
];
}

@Component({
template: `
<igx-drop-down #dropdownElement [maxHeight]="'100px'">
<igx-drop-down-item *ngFor="let item of items" [value]="item">
{{ item.field }}
</igx-drop-down-item>
</igx-drop-down>`
})
class DropDownWithMaxHeightComponent extends DropDownWithValuesComponent {}

@Component({
template: `
<igx-drop-down #dropdownElement [maxHeight]="'700px'">
<igx-drop-down-item *ngFor="let item of items" [value]="item">
{{ item.field }}
</igx-drop-down-item>
</igx-drop-down>`
})
class DropDownWithUnusedMaxHeightComponent extends DropDownWithValuesComponent {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
Optional,
HostListener,
Directive,
Inject
Inject,
HostBinding
} from '@angular/core';
import { IgxSelectionAPIService } from '../core/selection';
import { IgxToggleDirective, IgxToggleModule } from '../directives/toggle/toggle.directive';
Expand Down Expand Up @@ -205,6 +206,25 @@ export class IgxDropDownBase implements OnInit, IToggleView {
this.toggleDirective.id = value;
}

@HostBinding('class.igx-drop-down')
cssClass = 'igx-drop-down';

/**
* Gets/Sets the drop down's container max height.
*
* ```typescript
* // get
* let maxHeight = this.dropdown.maxHeight;
* ```
*
* ```html
* <!--set-->
* <igx-drop-down [maxHeight]='200px'></igx-drop-down>
* ```
*/
@Input()
public maxHeight = null;

/**
* Gets if the dropdown is collapsed
*
Expand Down