Skip to content

style(drop-down): Adding classes for different density types #5036

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

Merged
merged 21 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
837815b
style(drop-down): Aadding classes for different density types
Jun 10, 2019
71b22d1
Fix padding and lint error
Jun 10, 2019
8882007
Merge branch '7.2.x' into add-density-to-drop-down_7.2.x
simeonoff Jun 10, 2019
05214fc
style(drop-down): Aadding classes for different density types
Jun 10, 2019
4eb64c5
Fix padding and lint error
Jun 10, 2019
1a46cc9
Fix lint errors and padding
Jun 10, 2019
818671e
Update padding and height to match the spec
Jun 10, 2019
5fa559f
style(drop-down/combo): Update the height to match the newly updated …
Jun 11, 2019
fb11597
style(drop-down/combo): Fix misspelling
Jun 11, 2019
31bc2f6
Merge branch '7.2.x' into add-density-to-drop-down_7.2.x
simeonoff Jun 11, 2019
273014f
Merge branch '7.2.x' into add-density-to-drop-down_7.2.x
ViktorSlavov Jun 18, 2019
60cfb7e
feat(drop-down): implement density handling in DD, Combo, Select, #5034
ViktorSlavov Jun 12, 2019
4f3635f
test(select): fix failing tests, #5034
ViktorSlavov Jun 17, 2019
6b40fbb
Merge branch '7.2.x' into add-density-to-drop-down_7.2.x
wnvko Jun 18, 2019
8d04f20
docs(*): update README.md, CHANGELOG.md with drop-down display densit…
ViktorSlavov Jun 19, 2019
fb40637
test(drop-down): add tests for Display Density to Combo & Drop-Down s…
ViktorSlavov Jun 19, 2019
bdca07f
chore(*): properly extend DisplayDensity in interface; clarify positi…
ViktorSlavov Jun 19, 2019
bec7cb0
chore(*): remove static prop from tests
ViktorSlavov Jun 19, 2019
4fddb35
test(drop-down): remove unnecessary test, #1663
ViktorSlavov Jun 19, 2019
811e2e9
Merge branch '7.2.x' into add-density-to-drop-down_7.2.x
simeonoff Jun 20, 2019
5615063
Merge branch '7.2.x' into add-density-to-drop-down_7.2.x
Lipata Jun 20, 2019
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ChangeDetectorRef, Component, ContentChild, ElementRef, forwardRef, Inject, QueryList, OnDestroy, AfterViewInit, ContentChildren
ChangeDetectorRef, Component, ElementRef, Inject, QueryList, OnDestroy, AfterViewInit, ContentChild, ContentChildren, Optional,
forwardRef
} from '@angular/core';
import { takeUntil, take } from 'rxjs/operators';
import { IgxForOfDirective } from '../directives/for-of/for_of.directive';
Expand All @@ -14,6 +15,7 @@ import { IgxComboAPIService } from './combo.api';
import { IgxDropDownItemBase } from '../drop-down/drop-down-item.base';
import { IgxSelectionAPIService } from '../core/selection';
import { IgxComboItemComponent } from './combo-item.component';
import { DisplayDensityToken, IDisplayDensityOptions } from '../core/density';

/** @hidden */
@Component({
Expand All @@ -27,8 +29,9 @@ export class IgxComboDropDownComponent extends IgxDropDownComponent implements I
protected cdr: ChangeDetectorRef,
protected selection: IgxSelectionAPIService,
@Inject(IGX_COMBO_COMPONENT) public combo: IgxComboBase,
protected comboAPI: IgxComboAPIService) {
super(elementRef, cdr, selection);
protected comboAPI: IgxComboAPIService,
@Optional() @Inject(DisplayDensityToken) protected _displayDensityOptions: IDisplayDensityOptions) {
super(elementRef, cdr, selection, _displayDensityOptions);
}

protected get scrollContainer() {
Expand Down
4 changes: 2 additions & 2 deletions projects/igniteui-angular/src/lib/combo/combo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<igx-icon *ngIf="!toggleIconTemplate" fontSet="material">{{ dropdown.collapsed ? 'arrow_drop_down' : 'arrow_drop_up'}}</igx-icon>
</igx-suffix>
</igx-input-group>
<igx-combo-drop-down #igxComboDropDown class="igx-combo__drop-down" [width]="itemsWidth || '100%'" (onOpening)="handleOpening($event)"
<igx-combo-drop-down #igxComboDropDown class="igx-combo__drop-down" [displayDensity]="displayDensity" [width]="itemsWidth || '100%'" (onOpening)="handleOpening($event)"
(onClosing)="handleClosing($event)" (onOpened)="handleOpened()" (onClosed)="handleClosed()">
<igx-input-group *ngIf="displaySearchInput" [displayDensity]="displayDensity" class="igx-combo__search">
<input class="igx-combo-input" igxInput #searchInput name="searchInput" autocomplete="off" type="text"
Expand All @@ -58,7 +58,7 @@
<ng-template igxFor let-item let-index="index" [igxForOf]="data | comboFiltering:filteringExpressions:filteringLogic | comboSorting:sortingExpressions | comboGrouping:groupKey"
[igxForScrollOrientation]="'vertical'" [igxForContainerSize]="itemsMaxHeight" [igxForItemSize]="itemHeight"
(onChunkPreload)="dataLoading($event)">
<igx-combo-item [itemHeight]='itemHeight' [value]="item" isHeader={{item.isHeader}} role="option" [index]="index">
<igx-combo-item [itemHeight]='itemHeight' [value]="item" [isHeader]="item.isHeader" role="option" [index]="index">
<ng-container *ngIf="item.isHeader">
<ng-container *ngTemplateOutlet="headerItemTemplate ? headerItemTemplate : headerItemBase; context: {$implicit: item, data: data, valueKey: valueKey, groupKey: groupKey, displayKey: displayKey}"></ng-container>
</ng-container>
Expand Down
23 changes: 21 additions & 2 deletions projects/igniteui-angular/src/lib/combo/combo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { IgxComboItemComponent } from './combo-item.component';
import { IgxComboDropDownComponent } from './combo-dropdown.component';
import { IgxComboFilterConditionPipe, IgxComboFilteringPipe, IgxComboGroupingPipe, IgxComboSortingPipe } from './combo.pipes';
import { OverlaySettings, AbsoluteScrollStrategy } from '../services';
import { Subject, Subscription } from 'rxjs';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { DeprecateProperty } from '../core/deprecateDecorators';
import { DefaultSortingStrategy, ISortingStrategy } from '../data-operations/sorting-strategy';
Expand Down Expand Up @@ -69,6 +69,15 @@ enum DataTypes {
PRIMARYKEY = 'valueKey'
}

/**
* @hidden
*/
const ItemHeights = {
'comfortable': 48,
'cosy': 32,
'compact': 28,
};

export enum IgxComboState {
/**
* Combo with initial state.
Expand Down Expand Up @@ -131,6 +140,7 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
private destroy$ = new Subject<any>();
private _data = [];
private _filteredData = [];
private _itemHeight = null;
private _positionCallback: () => void;
private _onChangeCallback: (_: any) => void = noop;
private overlaySettings: OverlaySettings = {
Expand Down Expand Up @@ -670,7 +680,16 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
* ```
*/
@Input()
public itemHeight = 48;
public get itemHeight(): number {
if (this._itemHeight === null || this._itemHeight === undefined) {
return ItemHeights[this.displayDensity];
}
return this._itemHeight;
}

public set itemHeight(val: number) {
this._itemHeight = val;
}

/**
* @hidden @internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
@extend %igx-drop-down__item !optional;
}

@include e(item, $m: cosy) {
@extend %igx-drop-down__item--cosy !optional;
}

@include e(item, $m: compact) {
@extend %igx-drop-down__item--compact !optional;
}

@include e(item, $m: focused) {
@extend %igx-drop-down__item--focused !optional;
}
Expand All @@ -44,6 +52,14 @@
@extend %igx-drop-down__header !optional;
}

@include e(header, $m: cosy) {
@extend %igx-drop-down__header--cosy !optional;
}

@include e(header, $m: compact) {
@extend %igx-drop-down__header--compact !optional;
}

@include e(group) {
@extend %igx-drop-down__group !optional;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,27 @@
@mixin igx-drop-down($theme) {
@include igx-root-css-vars($theme);

$desktop-item-height: 48px;
$mobile-item-height: 32px;
$item-height: (
comfortable: rem(40px),
cosy: rem(32px),
compact: rem(28px)
);

$item-padding-comfortable: rem(24px);
$item-padding-cosy: rem(20px);
$item-padding-compact: rem(16px);

$item-padding: 16px;
$item-padding: (
comfortable: 0 $item-padding-comfortable,
cosy: 0 $item-padding-cosy,
compact: 0 $item-padding-compact
);

$desktop-header-padding: 16px;
$mobile-header-padding: 8px;
$header-item-padding: (
comfortable: 0 rem(16px),
cosy: 0 rem(12px),
compact: 0 rem(8px)
);

%igx-drop-down {
max-height: 100%;
Expand All @@ -212,24 +226,24 @@
}
}

%igx-drop-down__list--select {
max-width: calc(100% + #{$item-padding} * 2);
}

%igx-drop-down__header,
%igx-drop-down__item {
display: flex;
justify-content: flex-start;
align-items: center;
width: 100%;
white-space: nowrap;
height: map-get($item-height, 'comfortable');
}

%igx-drop-down__item {
color: --var($theme, 'item-text-color');
cursor: pointer;
height: rem($desktop-item-height);
padding: 0 rem($item-padding);
padding: map-get($item-padding, 'comfortable');

//&%igx-drop-down__list--select {
// max-width: calc(100% + #{$item-padding-comfortable} * 2);
//}

&:focus {
outline: 0;
Expand All @@ -244,6 +258,24 @@
}
}

%igx-drop-down__item--cosy {
height: map-get($item-height, 'cosy');
padding: map-get($item-padding, 'cosy');
//
//&%igx-drop-down__list--select {
// max-width: calc(100% + #{$item-padding-cosy} * 2);
//}
}

%igx-drop-down__item--compact {
height: map-get($item-height, 'compact');
padding: map-get($item-padding, 'compact');
//
//&%igx-drop-down__list--select {
// max-width: calc(100% + #{$item-padding-compact} * 2);
//}
}

[dir='rtl'] {
%igx-drop-down__item {
justify-content: flex-end;
Expand All @@ -254,7 +286,17 @@
%igx-drop-down__header {
color: --var($theme, 'header-text-color');
pointer-events: none;
padding: rem(8px) rem($desktop-header-padding);
padding: map-get($header-item-padding, 'comfortable');
}

%igx-drop-down__header--cosy {
height: map-get($item-height, 'cosy');
padding: map-get($header-item-padding, 'cosy');
}

%igx-drop-down__header--compact {
height: map-get($item-height, 'compact');
padding: map-get($header-item-padding, 'compact');
}

%igx-drop-down__group {
Expand All @@ -265,7 +307,7 @@
}

%igx-drop-down__item {
text-indent: rem($desktop-header-padding);
text-indent: map-get($item-padding, 'comfortable') ;
}
}

Expand Down Expand Up @@ -328,7 +370,7 @@
%igx-drop-down__header,
%igx-drop-down__group > label {
@include igx-type-style($type-scale, $header) {
margin : 0;
margin: 0;
}
}

Expand Down
32 changes: 32 additions & 0 deletions projects/igniteui-angular/src/lib/drop-down/drop-down-item.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ export abstract class IgxDropDownItemBase implements DoCheck {
return !this.isHeader;
}

/**
* @hidden @internal
*/
@HostBinding('class.igx-drop-down__item--cosy')
public get itemStyleCosy() {
return this.dropDown.displayDensity === 'cosy';
}

/**
* @hidden @internal
*/
@HostBinding('class.igx-drop-down__item--compact')
public get itemStyleCompact() {
return this.dropDown.displayDensity === 'compact';
}

/**
* Sets/Gets if the item is the currently selected one in the dropdown
*
Expand Down Expand Up @@ -196,6 +212,22 @@ export abstract class IgxDropDownItemBase implements DoCheck {
@HostBinding('class.igx-drop-down__header')
public isHeader: boolean;

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop down could update its items display density via hidden input. This way items will not know about drop down. Other possible solution is to use some service to update display density of the items.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this would be better left for another PR - in order for the drop-down item to not know about it's parent, the remaining selection logic and the allowItemFocus handling inside of the drop-down-item component will have to be abstracted in a service as well

* @hidden @internal
*/
@HostBinding('class.igx-drop-down__header--cosy')
public get headerClassCosy() {
return this.isHeader && this.dropDown.displayDensity === 'cosy';
}

/**
* @hidden @internal
*/
@HostBinding('class.igx-drop-down__header--compact')
public get headerClassCompact() {
return this.isHeader && this.dropDown.displayDensity === 'compact';
}

/**
* Sets/gets if the given item is disabled
*
Expand Down
10 changes: 7 additions & 3 deletions projects/igniteui-angular/src/lib/drop-down/drop-down.base.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {
Input, HostBinding, ElementRef, QueryList, Output, EventEmitter, ChangeDetectorRef
Input, HostBinding, ElementRef, QueryList, Output, EventEmitter, ChangeDetectorRef, Optional, Inject
} from '@angular/core';

import { Navigate, ISelectionEventArgs } from './drop-down.common';
import { IDropDownList } from './drop-down.common';
import { DropDownActionKey } from './drop-down.common';
import { IgxDropDownItemBase } from './drop-down-item.base';
import { DisplayDensityBase, DisplayDensityToken, IDisplayDensityOptions } from '../core/density';

let NEXT_ID = 0;

Expand All @@ -16,7 +17,7 @@ let NEXT_ID = 0;
* Properties and methods for navigating (highlighting/focusing) items from the collection
* Properties and methods for selecting items from the collection
*/
export abstract class IgxDropDownBase implements IDropDownList {
export abstract class IgxDropDownBase extends DisplayDensityBase implements IDropDownList {
protected _width;
protected _height;
protected _focusedItem: any = null;
Expand Down Expand Up @@ -170,7 +171,10 @@ export abstract class IgxDropDownBase implements IDropDownList {

constructor(
protected elementRef: ElementRef,
protected cdr: ChangeDetectorRef) { }
protected cdr: ChangeDetectorRef,
@Optional() @Inject(DisplayDensityToken) protected _displayDensityOptions: IDisplayDensityOptions) {
super(_displayDensityOptions);
}

/** Keydown Handler */
public onItemActionKey(key: DropDownActionKey, event?: Event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface IDropDownList {
* @hidden
*/
export interface IDropDownBase extends IDropDownList, IToggleView {
displayDensity: string;
onOpening: EventEmitter<CancelableEventArgs>;
onOpened: EventEmitter<void>;
onClosing: EventEmitter<CancelableBrowserEventArgs>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,8 @@ describe('IgxDropDown ', () => {
expect(igxDropDown.collapsed).toEqual(true);
}));

it('#1663 drop down flickers on open', fakeAsync(() => {
xit('#1663 drop down flickers on open', fakeAsync(() => {
// This tests nothing.
const fixture = TestBed.createComponent(IgxDropDownWithScrollComponent);
fixture.detectChanges();
const button = fixture.debugElement.query(By.css('button')).nativeElement;
Expand All @@ -1110,7 +1111,7 @@ describe('IgxDropDown ', () => {
tick();
fixture.detectChanges();

expect((<any>igxDropDown).toggleDirective.element.scrollTop).toEqual(116);
expect((<any>igxDropDown).toggleDirective.element.scrollTop).toEqual(80);
}));

it('Should set isSelected via igxDropDownIteComponent', fakeAsync(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
ViewChild,
EventEmitter,
Output,
Optional,
Inject
} from '@angular/core';
import { IgxToggleDirective } from '../directives/toggle/toggle.directive';
import { IgxDropDownItemComponent } from './drop-down-item.component';
Expand All @@ -24,7 +26,7 @@ import { IgxSelectionAPIService } from '../core/selection';
import { Subject } from 'rxjs';
import { IgxDropDownItemBase } from './drop-down-item.base';
import { OverlaySettings } from '../services';

import { DisplayDensityToken, IDisplayDensityOptions } from '../core/density';

/**
* **Ignite UI for Angular DropDown** -
Expand Down Expand Up @@ -173,8 +175,9 @@ export class IgxDropDownComponent extends IgxDropDownBase implements IDropDownBa
constructor(
protected elementRef: ElementRef,
protected cdr: ChangeDetectorRef,
protected selection: IgxSelectionAPIService) {
super(elementRef, cdr);
protected selection: IgxSelectionAPIService,
@Optional() @Inject(DisplayDensityToken) protected _displayDensityOptions: IDisplayDensityOptions) {
super(elementRef, cdr, _displayDensityOptions);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class SelectPositioningStrategy extends ConnectedPositioningStrategy impl
this.itemTextPadding = numericLeftPadding;
this.itemTextIndent = numericTextIndent;
contentElement.style.left += `${START.X - numericLeftPadding - numericTextIndent}px`;
contentElement.style.width = inputRect.width + 24 + 32 + 'px';
contentElement.style.width = inputRect.width + 24 + 48 + 'px';
this.deltaX = START.X - numericLeftPadding - numericTextIndent;
const currentScroll = this.getItemsOutOfView(contentElement, itemHeight)['currentScroll'];
const remainingScroll = this.getItemsOutOfView(contentElement, itemHeight)['remainingScroll'];
Expand Down
Loading