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

feat(selection-list): Selection-list initial version all code(without demo) #5562

Merged
merged 13 commits into from Aug 12, 2017

Conversation

sllethe
Copy link
Contributor

@sllethe sllethe commented Jul 6, 2017

No description provided.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 6, 2017
@sllethe sllethe changed the title Selection-list initial version al lcode Selection-list initial version all code(without demo) Jul 6, 2017
@@ -0,0 +1,11 @@
<div [ngClass]="(checkboxPosition == 'before')?'mat-list-item-content' : 'mat-list-item-content-reverse'" >
<!--<div class="mat-list-item-content">-->
Copy link
Member

Choose a reason for hiding this comment

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

Commented out code

@@ -175,3 +204,122 @@ export class MdListItem implements AfterContentInit {
return this._element.nativeElement;
}
}

@Component({
Copy link
Member

Choose a reason for hiding this comment

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

This class needs a JsDoc description

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added doc for 'md-selection-option'

@@ -0,0 +1,11 @@
<div [ngClass]="(checkboxPosition == 'before')?'mat-list-item-content' : 'mat-list-item-content-reverse'" >
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using ngClass and applying one of two classes, you should be able to have the default styles always applied and then apply the "reverse" styles when the condition is met like this:

<div [class.mat-list-option-reverse]="checkboxPosition == 'after'">

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed '[ngClass]' to '<div [class.mat-list-option-reverse]="checkboxPosition == 'after'">'


@Input() checkboxPosition: 'before' | 'after' = 'after';

@ViewChild('autocheckbox') pCheckbox;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need this @ViewChild (and all associated code), since the state of the pseudo-checkbox should be set via binding in the template

constructor(private _renderer: Renderer2,
private _element: ElementRef,
@Optional() private _slist: MdSelectionList,
@Optional() navList: MdNavListCssMatStyler,
Copy link
Member

Choose a reason for hiding this comment

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

Why does this deal with a nav-list? MdListOption should only be used in a selection list. Getting rid of this should let you also get rid of _isNavList and _isSelectionList

(should be assumed that this is always inside of a selection list)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted navList in selection-list-option

console.log('checked or not: ' + this.pCheckbox.state + ', isSelected or not: ' + this.isSelected);
if(this.isSelected == false) {
this.isSelected = true;
this.selectionList.checkedItems.select(this._element.nativeElement);
Copy link
Member

Choose a reason for hiding this comment

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

Rather than using the HTMLElement as the selected value, it should use either the option itself (this).

})
export class MdSelectionListCheckboxer {

checkedItems: SelectionModel<HTMLElement> = new SelectionModel<HTMLElement>(true);
Copy link
Member

Choose a reason for hiding this comment

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

checkedItems -> _selectedOptions

This property should also live directly on MdSelectionList (you shouldn't need this class at all)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed checkedItems to selectedOptions. And deleted MdSelectionListCheckboxer class

styleUrls: ['list.css'],
encapsulation: ViewEncapsulation.None
})
export class MdSelectionList {
Copy link
Member

Choose a reason for hiding this comment

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

In another PR after this one, we'll need to add support for the MdSelectionList being a form control, similar to the md-select

selector: 'md-selection-list, mat-selection-list',
host: {'class': 'mat-selection-list'}
})
export class MdSelectionListCssMatStyler {}
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need this class; you can add the mat-selection-list class in MdSelectionList

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted 'MdSelectionListCssMatStyler' class.

'(click)': 'onchange()',
'(keydown)':'onKeydown($event)',
'[tabIndex]': 'disabled ? -1 : 0',
'[attr.aria-selected]': '',
Copy link
Member

Choose a reason for hiding this comment

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

Missing binding expression for aria-selected. The expression needs to resolve to a string of either 'true' or 'false' (see how existing MdOption does this).

You'll also need a binding for aria-disabled based on the disabled state

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added binding expression for 'attr.aria-selected' and 'attr.aria-disabled'

Copy link
Contributor Author

@sllethe sllethe left a comment

Choose a reason for hiding this comment

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

Comments addressed. Please take another look 👍

private _disableRipple: boolean = false;
private _isNavList: boolean = false;
private _isSelectionList: boolean = false;
isSelected: boolean = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed isSelected to selected. And added @Input(selected) for it.(Using coerceBooleanProperty)


constructor(private _renderer: Renderer2,
private _element: ElementRef,
@Optional() private _slist: MdSelectionList,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed _slist to selectionList and deleted MdSelectionListCheckboxer class

constructor(private _renderer: Renderer2,
private _element: ElementRef,
@Optional() private _slist: MdSelectionList,
@Optional() navList: MdNavListCssMatStyler,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted navList in selection-list-option

this._lineSetter = new MdLineSetter(this._lines, this._renderer, this._element);
}

onchange(): void {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed 'onchange()' to 'toggle()' and added doc for it.

})
export class MdSelectionListCheckboxer {

checkedItems: SelectionModel<HTMLElement> = new SelectionModel<HTMLElement>(true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed checkedItems to selectedOptions. And deleted MdSelectionListCheckboxer class

}

onchange(): void {
console.log('checked or not: ' + this.pCheckbox.state + ', isSelected or not: ' + this.isSelected);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed console.log

selector: 'md-list-option',
host: {
'role': 'option',
'class': 'mat-list-item',
Copy link
Member

Choose a reason for hiding this comment

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

If you add mat-list-option to this as well it will be easier to write styles for the option specifically. For example, instead of .mat-selection-list .mat-list-item you could just have mat-list-option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added .mat-list-option class in css files

padding: 0 $mat-list-side-padding;
position: relative;
flex-direction: row-reverse;
-webkit-justify-content: space-around; /* Safari */
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need the -webkit-justify-content, since Safari 9 and 10 both support all of the flex properties unprefixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure~
Deleted -webkit-justify-content in CSS file

@@ -43,6 +43,19 @@ $mat-dense-list-icon-size: 20px;
position: relative;
}

.mat-list-item-content-reverse {
display: flex;
//flex-direction: row;
Copy link
Member

Choose a reason for hiding this comment

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

Commented line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed commented line

<md-pseudo-checkbox [state]="selected ? 'checked' : 'unchecked'" #autocheckbox [disabled]="disabled"></md-pseudo-checkbox>
<div class="mat-list-text"><ng-content></ng-content></div>

</div>
Copy link
Member

Choose a reason for hiding this comment

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

Can you configure your IDE to add newlines at the end of files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added new line at each file

@@ -60,18 +73,18 @@ $mat-dense-list-icon-size: 20px;
height: $avatar-height;
}

&.mat-2-line .mat-list-item-content {
&.mat-2-line .mat-list-item-content .mat-list-item-content-reverse {
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need to add mat-list-item-content-reverse to these existing styles; the mat-list-item-content-reverse class should only have the extra styles you need to reverse the display

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted 'mat-list-item-content-reverse' to these existing styles;

this.selectionList.selectedOptions.deselect(this);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

The toggle function by itself can just be

toggle() {
  this.selected = !this.selected;
  this.selectionList.selectedOption.toggle(this);
}

The logic that a disabled option should do anything on click should be specifically tied to the click handler rather than being in the more general toggle()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Great!

host: {'role': 'listbox',
'[attr.tabindex]': '_tabIndex',
'class': 'mat-selection-list',
// Events
Copy link
Member

Choose a reason for hiding this comment

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

No need for category comments inside host; the different syntax makes it clear enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@Component({
moduleId: module.id,
selector: 'md-selection-list, mat-selection-list',
host: {'role': 'listbox',
Copy link
Member

Choose a reason for hiding this comment

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

Format like

host: {
  'role': 'listbox',
  ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

options: QueryList<MdListOption>;

// options which are selected.
selectedOptions: SelectionModel<any> = new SelectionModel<any>(true);
Copy link
Member

Choose a reason for hiding this comment

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

SelectionModel<MdListOption>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

// Always prevent space from scrolling the page since the list has focus
event.preventDefault();
break;
case LEFT_ARROW:
Copy link
Member

Choose a reason for hiding this comment

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

The selection-list shouldn't need shortcuts for left/right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted shortcuts for left/right

Copy link
Contributor Author

@sllethe sllethe left a comment

Choose a reason for hiding this comment

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

Comments Addressed~. Please take another look~ 👍

<md-pseudo-checkbox [state]="selected ? 'checked' : 'unchecked'" #autocheckbox [disabled]="disabled"></md-pseudo-checkbox>
<div class="mat-list-text"><ng-content></ng-content></div>

</div>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added new line at each file

@@ -43,6 +43,19 @@ $mat-dense-list-icon-size: 20px;
position: relative;
}

.mat-list-item-content-reverse {
display: flex;
//flex-direction: row;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed commented line

padding: 0 $mat-list-side-padding;
position: relative;
flex-direction: row-reverse;
-webkit-justify-content: space-around; /* Safari */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure~
Deleted -webkit-justify-content in CSS file

@@ -60,18 +73,18 @@ $mat-dense-list-icon-size: 20px;
height: $avatar-height;
}

&.mat-2-line .mat-list-item-content {
&.mat-2-line .mat-list-item-content .mat-list-item-content-reverse {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted 'mat-list-item-content-reverse' to these existing styles;

@@ -182,3 +195,31 @@ $mat-dense-list-icon-size: 20px;
}
}
}

.mat-selection-list {
a {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted <a> element

this.selectionList.selectedOptions.deselect(this);
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Great!

@Component({
moduleId: module.id,
selector: 'md-selection-list, mat-selection-list',
host: {'role': 'listbox',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

host: {'role': 'listbox',
'[attr.tabindex]': '_tabIndex',
'class': 'mat-selection-list',
// Events
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

options: QueryList<MdListOption>;

// options which are selected.
selectedOptions: SelectionModel<any> = new SelectionModel<any>(true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

// Always prevent space from scrolling the page since the list has focus
event.preventDefault();
break;
case LEFT_ARROW:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted shortcuts for left/right

@@ -305,6 +305,26 @@
"integrity": "sha1-dO6TaJbaXkU8NBzygEQ0LBqazrc=",
"dev": true
},
"@gulp-sourcemaps/identity-map": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Revert this file?

Copy link
Contributor

Choose a reason for hiding this comment

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

Revert?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Reverted~

@@ -182,3 +214,8 @@ $mat-dense-list-icon-size: 20px;
}
}
}

.mat-selection-list {
Copy link
Contributor

Choose a reason for hiding this comment

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

remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted that empty class

@@ -159,7 +501,8 @@ export class MdListItem implements AfterContentInit {

/** Whether this list item should show a ripple effect when clicked. */
isRippleEnabled() {
return !this.disableRipple && this._isNavList && !this._list.disableRipple;
return !this.disableRipple && (this._isNavList)
Copy link
Contributor

Choose a reason for hiding this comment

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

revert this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted changes

import {CommonModule} from '@angular/common';
import {coerceBooleanProperty, MdLine, MdLineSetter, MdPseudoCheckbox, MdSelectionModule, SelectionModel} from '../core';
import {FocusKeyManager} from '../core/a11y/focus-key-manager';
import {MdCheckbox} from '../checkbox';
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unused imports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed unused imports

'[attr.aria-disabled]': 'disabled.toString()',
},
templateUrl: 'list-option.html',
encapsulation: ViewEncapsulation.None
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also make this changeDetection: ChangeDetectionStrategy.OnPush?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make md-list-option 'changeDetection: ChangeDetectionStrategy.OnPush', add chengeDetector

/** The option components contained within this selection-list. */
options: QueryList<MdListOption>;

// options which are selected.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: use /** */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍


/**
* Whether the ripple effect should be disabled on the list-items or not.
* This flag only has an effect for `md-nav-list` components.
Copy link
Contributor

Choose a reason for hiding this comment

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

mat-selection-list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes~ 👍 it's should be mat-selection-list

get disableRipple() { return this._disableRipple; }
set disableRipple(value: boolean) { this._disableRipple = coerceBooleanProperty(value); }

// Whether the selection-list is disabled
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Use /**

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

this._subscribeOptions(this.options);

// When the list changes, re-subscribe
this.options.changes.subscribe((options: QueryList<MdListOption>) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also unsubscribe this in ngOnDestroy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added unsubscribe for 'this.options.changes.subscribe((options: QueryList)' in onDistory();

switch (event.keyCode) {
case SPACE:
// If we are selectable, toggle the focused option
if (this.selectable) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this if since you check this.selectable in _toggleSelectOnFocusedOption

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Removed if (this.selectable) check

@sllethe sllethe force-pushed the selection-list-initialVersionAllcode branch from ab78883 to 8524538 Compare July 12, 2017 23:25
Copy link
Contributor Author

@sllethe sllethe left a comment

Choose a reason for hiding this comment

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

Comments Addressed~ Please take another look 👍

@@ -182,3 +214,8 @@ $mat-dense-list-icon-size: 20px;
}
}
}

.mat-selection-list {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted that empty class

import {CommonModule} from '@angular/common';
import {coerceBooleanProperty, MdLine, MdLineSetter, MdPseudoCheckbox, MdSelectionModule, SelectionModel} from '../core';
import {FocusKeyManager} from '../core/a11y/focus-key-manager';
import {MdCheckbox} from '../checkbox';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed unused imports

'[attr.aria-disabled]': 'disabled.toString()',
},
templateUrl: 'list-option.html',
encapsulation: ViewEncapsulation.None
Copy link
Contributor Author

Choose a reason for hiding this comment

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

make md-list-option 'changeDetection: ChangeDetectionStrategy.OnPush', add chengeDetector

/** The option components contained within this selection-list. */
options: QueryList<MdListOption>;

// options which are selected.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍


/**
* Whether the ripple effect should be disabled on the list-items or not.
* This flag only has an effect for `md-nav-list` components.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes~ 👍 it's should be mat-selection-list

get disableRipple() { return this._disableRipple; }
set disableRipple(value: boolean) { this._disableRipple = coerceBooleanProperty(value); }

// Whether the selection-list is disabled
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

this._subscribeOptions(this.options);

// When the list changes, re-subscribe
this.options.changes.subscribe((options: QueryList<MdListOption>) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added unsubscribe for 'this.options.changes.subscribe((options: QueryList)' in onDistory();

switch (event.keyCode) {
case SPACE:
// If we are selectable, toggle the focused option
if (this.selectable) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Removed if (this.selectable) check

@@ -159,7 +501,8 @@ export class MdListItem implements AfterContentInit {

/** Whether this list item should show a ripple effect when clicked. */
isRippleEnabled() {
return !this.disableRipple && this._isNavList && !this._list.disableRipple;
return !this.disableRipple && (this._isNavList)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted changes

get disabled() { return (this.selectionList && this.selectionList.disabled) || this._disabled; }
set disabled(value: any) { this._disabled = coerceBooleanProperty(value); }

@Input('value')
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use @Input() here

get value() { return this._value; }
set value( val: any) { this._value = coerceBooleanProperty(val); }

@Input('selected')
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

toggle(): void {
if(this._disabled == false) {
this.selected = !this.selected;
this._changeDetector.markForCheck();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need markForCheck here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the position of markForCheck to the end of this function


_handleFocus() {
this._hasFocus = true;
this._renderer.addClass(this._element.nativeElement, 'mat-list-item-focus');
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: make mat-list-item-focus a const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added const 'FOCUSED_STYLE'

@@ -29,6 +33,22 @@
background: mat-color($background, 'hover');
}
}

.mat-selection-list .mat-list-item {
Copy link
Member

Choose a reason for hiding this comment

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

Can these styles just be moved to .mat-list-option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved styles in .mat-selection-list .mat-list-item to .mat-list-option

position: relative;
flex-direction: row-reverse;
justify-content: space-around;
}
Copy link
Member

Choose a reason for hiding this comment

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

Do position, box-sizing, and height need to be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted position, box-sizing, and height


/** Whether the label should appear after or before the checkbox. Defaults to 'after' */

@Input() checkboxPosition: 'before' | 'after' = 'after';
Copy link
Member

Choose a reason for hiding this comment

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

Have you tested this in RTL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it works.

@ContentChildren(MdLine) _lines: QueryList<MdLine>;

/** Whether the label should appear after or before the checkbox. Defaults to 'after' */

Copy link
Member

Choose a reason for hiding this comment

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

Omit blank line between JsDoc and the property it describes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍


@Input() checkboxPosition: 'before' | 'after' = 'after';

/** Whether the checkbox is disabled. */
Copy link
Member

Choose a reason for hiding this comment

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

"checkbox" -> "option"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

// otherwise pass to our key manager
if (target && (target.classList.contains('mat-selection-list') ||
target.classList.contains('mat-list-item') ||
target.classList.contains('mat-list-option'))) {
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need this check on the target? If this component receives a keydown, don't you always want to handle it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted check on the target.


let focusedIndex = this._keyManager.activeItemIndex;

if (typeof focusedIndex === 'number' && this._isValidIndex(focusedIndex)) {
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need this typeof check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because focusedIndex = this._keyManager.activeItemIndex and the type of keyManager.activeItemIndex is 'number | null'. If I do not check typeof, it will run out an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Check whether focusedIndex is null?

Copy link
Member

@jelbourn jelbourn Jul 17, 2017

Choose a reason for hiding this comment

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

Yeah, checking for == null is more typical

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed to check 'focusedIndex != null'

Copy link
Contributor Author

@sllethe sllethe left a comment

Choose a reason for hiding this comment

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

Comments Addressed. Please take another look 👍

@@ -29,6 +33,22 @@
background: mat-color($background, 'hover');
}
}

.mat-selection-list .mat-list-item {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved styles in .mat-selection-list .mat-list-item to .mat-list-option

position: relative;
flex-direction: row-reverse;
justify-content: space-around;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted position, box-sizing, and height

@ContentChildren(MdLine) _lines: QueryList<MdLine>;

/** Whether the label should appear after or before the checkbox. Defaults to 'after' */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍


/** Whether the label should appear after or before the checkbox. Defaults to 'after' */

@Input() checkboxPosition: 'before' | 'after' = 'after';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it works.


@Input() checkboxPosition: 'before' | 'after' = 'after';

/** Whether the checkbox is disabled. */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

// otherwise pass to our key manager
if (target && (target.classList.contains('mat-selection-list') ||
target.classList.contains('mat-list-item') ||
target.classList.contains('mat-list-option'))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted check on the target.


let focusedIndex = this._keyManager.activeItemIndex;

if (typeof focusedIndex === 'number' && this._isValidIndex(focusedIndex)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because focusedIndex = this._keyManager.activeItemIndex and the type of keyManager.activeItemIndex is 'number | null'. If I do not check typeof, it will run out an error.

@tinayuangao tinayuangao changed the title Selection-list initial version all code(without demo) feat(selection-list): Selection-list initial version all code(without demo) Jul 17, 2017
'(focus)': 'focus()',
'(keydown)': 'keydown($event)'},
queries: {
options: new ContentChildren(MdListOption)
Copy link
Member

Choose a reason for hiding this comment

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

Why do you add queries here instead of using @ContentChildren?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to use @ContentChildren


let focusedIndex = this._keyManager.activeItemIndex;

if (typeof focusedIndex === 'number' && this._isValidIndex(focusedIndex)) {
Copy link
Member

@jelbourn jelbourn Jul 17, 2017

Choose a reason for hiding this comment

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

Yeah, checking for == null is more typical

encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class MdSelectionList implements AfterContentInit, OnDestroy {
Copy link
Member

Choose a reason for hiding this comment

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

Can md-selection-list and md-list-option go in separate files? (selection-list.ts and list-option.ts)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 made md-selection-list and md-list-option go in separate files? (selection-list.ts and list-option.ts)

@sllethe
Copy link
Contributor Author

sllethe commented Jul 19, 2017

Comments Addressed 👍
Please take another look.

'[attr.tabindex]': '_tabIndex',
'class': 'mat-selection-list',
'(focus)': 'focus()',
'(keydown)': 'keydown($event)'},
Copy link
Member

Choose a reason for hiding this comment

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

This needs a binding for aria-disabled to reflect its disabled state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Binded aria-disabled

selector: 'md-selection-list, mat-selection-list',
host: {
'role': 'listbox',
'[attr.tabindex]': '_tabIndex',
Copy link
Member

Choose a reason for hiding this comment

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

The tabindex should be -1 when the selection-list is disabled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Set The tabindex of list option as -1 when the selection-list is disabled

/** Whether the selection-list is disabled */
@Input()
get disabled() { return this._disabled; }
set disabled(value: any) { this._disabled = coerceBooleanProperty(value); }
Copy link
Member

Choose a reason for hiding this comment

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

Instead of defining the disabled getter/setter yourself, you can include it via mixin. Check out button.ts for an example of how to apply a mixin (there's some boilerplate involved but it ultimately reduces code duplication).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied mixin on disabled 👍

// it back to the first option when the user tabs out.
this._tabOutSubscription = this._keyManager.tabOut.subscribe(() => {
this._tabIndex = -1;
setTimeout(() => this._tabIndex = 0);
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why you're doing this with tabindex. AFAIK, the tabindex of the selection list should always be 0 if it is enabled and -1 if it is disabled. The individual options should all have tabindex="-1"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this part is not being needed. I've deleted this part

private _tabOutSubscription: Subscription;

/** Subscription to option changes from the selection-list. */
private _optionSubscription: Subscription;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe _optionsChangeSubscription?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to '_optionsChangeSubscription'

get selectable(): boolean { return this._selectable; }
set selectable(value: boolean) {
this._selectable = coerceBooleanProperty(value);
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this selectable property is in the wrong class, but also not necessary for option and should probably be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed selectable property

@@ -139,10 +147,20 @@ $mat-dense-list-icon-size: 20px;
$mat-list-icon-size
);
}

.mat-list-option {
@include mat-line-base(
Copy link
Contributor

@kara kara Jul 19, 2017

Choose a reason for hiding this comment

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

Do you mean mat-list-item-base here? The mat-line-base mixin only takes one arg, so this will prevent it from building.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! It should be mat-list-item-base

selector: 'md-list-option, mat-list-option',
host: {
'role': 'option',
'class': 'mat-list-item, mat-list-option',
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the comma is a typo? Don't want a comma between class names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 change ['class': 'mat-list-item, mat-list-option',] to ['class': 'mat-list-item mat-list-option',]; Removed the comma between class names.


/**
* Whether the ripple effect on click should be disabled. This applies only to list items that are
* part of a nav list. The value of `disableRipple` on the `md-nav-list` overrides this flag.
Copy link
Contributor

Choose a reason for hiding this comment

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

List-options are only on selection-lists, right? The comment talks about nav lists, so it looks like this might need to be updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated the comments.


/**
* Whether or not this option is selectable. When a option is not selectable,
* it's selected state is always ignored.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: it's -> its

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

option.onFocus.subscribe(() => {
let optionIndex: number = this.options.toArray().indexOf(option);

if (this._isValidIndex(optionIndex)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the validity of the index necessary to check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Deleted unnecessaey this._isValidIndex(optionIndex) check

*/
protected _addOption(option: MdListOption) {
// If we've already been subscribed to a parent, do nothing
if (this._subscribed.has(option)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of keeping a list of options that were previously subscribed, it might be easier to merge all the option subscriptions into one stream. Then you can just switchMap to a new merged stream every time the option list changes. Check out how we do this in the autocomplete here and here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Finally make it work.
@kara @tinayuangao Thank you so much for your help~~! 🥇

@sllethe sllethe force-pushed the selection-list-initialVersionAllcode branch from 43b88c6 to ba0d581 Compare July 20, 2017 19:13
Copy link
Contributor Author

@sllethe sllethe left a comment

Choose a reason for hiding this comment

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

Comments Addressed 👍
Please take another look.

selector: 'md-selection-list, mat-selection-list',
host: {
'role': 'listbox',
'[attr.tabindex]': '_tabIndex',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Set The tabindex of list option as -1 when the selection-list is disabled

selector: 'md-list-option, mat-list-option',
host: {
'role': 'option',
'class': 'mat-list-item, mat-list-option',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 change ['class': 'mat-list-item, mat-list-option',] to ['class': 'mat-list-item mat-list-option',]; Removed the comma between class names.


/**
* Whether the ripple effect on click should be disabled. This applies only to list items that are
* part of a nav list. The value of `disableRipple` on the `md-nav-list` overrides this flag.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated the comments.

@@ -139,10 +147,20 @@ $mat-dense-list-icon-size: 20px;
$mat-list-icon-size
);
}

.mat-list-option {
@include mat-line-base(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! It should be mat-list-item-base

'[attr.tabindex]': '_tabIndex',
'class': 'mat-selection-list',
'(focus)': 'focus()',
'(keydown)': 'keydown($event)'},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Binded aria-disabled


/**
* Whether or not this option is selectable. When a option is not selectable,
* it's selected state is always ignored.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

/** Whether the selection-list is disabled */
@Input()
get disabled() { return this._disabled; }
set disabled(value: any) { this._disabled = coerceBooleanProperty(value); }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied mixin on disabled 👍

get selectable(): boolean { return this._selectable; }
set selectable(value: boolean) {
this._selectable = coerceBooleanProperty(value);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed selectable property

option.onFocus.subscribe(() => {
let optionIndex: number = this.options.toArray().indexOf(option);

if (this._isValidIndex(optionIndex)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Deleted unnecessaey this._isValidIndex(optionIndex) check

*/
protected _addOption(option: MdListOption) {
// If we've already been subscribed to a parent, do nothing
if (this._subscribed.has(option)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Finally make it work.
@kara @tinayuangao Thank you so much for your help~~! 🥇

@sllethe sllethe force-pushed the selection-list-initialVersionAllcode branch 2 times, most recently from 9c2d9d6 to a97c924 Compare July 21, 2017 01:29
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

No other major comments on the implementation, just needs unit tests now

import {merge} from 'rxjs/operator/merge';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/startWith';
Copy link
Member

Choose a reason for hiding this comment

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

The main components can't use the rxjs /add/ imports (and there should be a lint failure for doing so). You can use RxChain instead

It looks like you have some other lint errors as well; you can see them locally with gulp tslint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed to use 'RxChain' instead of directly importing 'observer/add/'Changed to use 'RxChain' instead of directly importing 'observer/add/'

Copy link
Contributor

@tinayuangao tinayuangao left a comment

Choose a reason for hiding this comment

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

LGTM

.mat-subheader {
@include mat-typography-level-to-styles($config, body-2);
}

.mat-list-item-disabled {
background: #ededed;
Copy link
Member

Choose a reason for hiding this comment

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

This color needs to take whether we're in a light or dark theme into account; ideally it would come from the background color palette on the theme

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to background-color: mat-color($background, disabled-list-option);

}

toggle(): void {
if (this._disabled == false && this.selectionList.disabled == false) {
Copy link
Member

Choose a reason for hiding this comment

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

Don't need to compare against false; you would just do

if (!this.disabled) {
  ...
}

(the disabled getter already takes the selectionList state into account)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 changed to :

if (!this.disabled) {
  ...
}

this._lineSetter = new MdLineSetter(this._lines, this._renderer, this._element);

if (this.selectionList.disabled) {
this._disabled = true;
Copy link
Member

Choose a reason for hiding this comment

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

It would be better not to mutate the option disabled state based on the parent state; this can be error prone, as it's easy to miss updating one when the other changes. It's better to rely on the disabled getter for the option to account for the parent state.

onFocus = new EventEmitter<MdSelectionListOptionEvent>();

/** Emitted when the option is selected. */
@Output() select = new EventEmitter<MdSelectionListOptionEvent>();
Copy link
Member

Choose a reason for hiding this comment

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

select -> selected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems selected has already been defined.

@Input()
get selected() { return this._selected; }
set selected( val: boolean) { this._selected = coerceBooleanProperty(val); }

Copy link
Contributor

Choose a reason for hiding this comment

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

or rename it to selectChange?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed to selectChange

@Output() select = new EventEmitter<MdSelectionListOptionEvent>();

/** Emitted when the option is deselected. */
@Output() deselect = new EventEmitter<MdSelectionListOptionEvent>();
Copy link
Member

Choose a reason for hiding this comment

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

deselect -> deselected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed deselect -> deselected

/**
* Map all the options' destroy event subscriptions and merge them into one stream.
*/
onDestroySubscription(): Subscription {
Copy link
Member

Choose a reason for hiding this comment

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

This method should be private

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed it to 'private _onDestroySubscription()'

/**
* Map all the options' onFocus event subscriptions and merge them into one stream.
*/
onFocusSubscription(): Subscription {
Copy link
Member

Choose a reason for hiding this comment

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

This method should be private

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed to 'private _onFocusSubscription()'

}

/** Passes relevant key presses to our key manager. */
keydown(event: KeyboardEvent) {
Copy link
Member

Choose a reason for hiding this comment

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

This should be internal (start with an _)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed to '_keydown'

}

/** Toggles the selected state of the currently focused option. */
protected _toggleSelectOnFocusedOption(): void {
Copy link
Member

Choose a reason for hiding this comment

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

This method should be private

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed to 'private'

import {UP_ARROW, DOWN_ARROW, SPACE} from '../core/keyboard/keycodes';
import {Platform} from '../core/platform/index';

describe('test normal selection list with list option', () => {
Copy link
Member

Choose a reason for hiding this comment

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

You can wrap all of these child describe blocks in one top-level block:

describe('MdSelectionList', () => {
  ...
});

Then, each describe block has a name that modifies the selection list, e.g.

describe('MdSelectionList', () => {
  describe('with multiple options', () => {
    ...
  });

  describe('with one option', () => {
    ...
  });

  describe('with disabled state', () => {
    ...
  });
});

This will make the test failures report like

MdSelectionList with one option should select an option

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed the structure like that~

Copy link
Contributor Author

@sllethe sllethe left a comment

Choose a reason for hiding this comment

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

Comments Addressed 👍
Please take another look

onFocus = new EventEmitter<MdSelectionListOptionEvent>();

/** Emitted when the option is selected. */
@Output() select = new EventEmitter<MdSelectionListOptionEvent>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems selected has already been defined.

@Input()
get selected() { return this._selected; }
set selected( val: boolean) { this._selected = coerceBooleanProperty(val); }

@Output() select = new EventEmitter<MdSelectionListOptionEvent>();

/** Emitted when the option is deselected. */
@Output() deselect = new EventEmitter<MdSelectionListOptionEvent>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed deselect -> deselected

@Output() deselect = new EventEmitter<MdSelectionListOptionEvent>();

/** Emitted when the option is destroyed. */
@Output() destroy = new EventEmitter<MdSelectionListOptionEvent>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

}

toggle(): void {
if (this._disabled == false && this.selectionList.disabled == false) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 changed to :

if (!this.disabled) {
  ...
}

this._lineSetter = new MdLineSetter(this._lines, this._renderer, this._element);

if (this.selectionList.disabled) {
this._disabled = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to :

if (!this.disabled) {
  ...
}

import {UP_ARROW, DOWN_ARROW, SPACE} from '../core/keyboard/keycodes';
import {Platform} from '../core/platform/index';

describe('test normal selection list with list option', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed the structure like that~

/**
* Map all the options' destroy event subscriptions and merge them into one stream.
*/
onDestroySubscription(): Subscription {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed it to 'private _onDestroySubscription()'

/**
* Map all the options' onFocus event subscriptions and merge them into one stream.
*/
onFocusSubscription(): Subscription {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed to 'private _onFocusSubscription()'

}

/** Passes relevant key presses to our key manager. */
keydown(event: KeyboardEvent) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed to '_keydown'

}

/** Toggles the selected state of the currently focused option. */
protected _toggleSelectOnFocusedOption(): void {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed to 'private'

@@ -659,6 +659,7 @@ $mat-light-theme-background: (
selected-button: map_get($mat-grey, 300),
selected-disabled-button: map_get($mat-grey, 400),
disabled-button-toggle: map_get($mat-grey, 200),
disabled-list-option: map_get($mat-grey, 200),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: indent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Deleted indent

onFocus = new EventEmitter<MdSelectionListOptionEvent>();

/** Emitted when the option is selected. */
@Output() select = new EventEmitter<MdSelectionListOptionEvent>();
Copy link
Contributor

Choose a reason for hiding this comment

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

or rename it to selectChange?

@@ -659,6 +659,7 @@ $mat-light-theme-background: (
selected-button: map_get($mat-grey, 300),
selected-disabled-button: map_get($mat-grey, 400),
disabled-button-toggle: map_get($mat-grey, 200),
disabled-list-option: map_get($mat-grey, 200),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: indent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Deleted indent

this._lineSetter = new MdLineSetter(this._lines, this._renderer, this._element);

if (this.selectionList.disabled) {
this._disabled = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to delete if (this.selectionList.disabled) {...} part

}

toggle(): void {
if (!this._disabled) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use this.disabled to consider the case when parent selectionList is disabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed to this.disabled

@@ -182,3 +212,5 @@ $mat-dense-list-icon-size: 20px;
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: too many empty lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Deleted empty lines

Copy link
Contributor Author

@sllethe sllethe left a comment

Choose a reason for hiding this comment

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

Comments Addressed 👍
Please take another look~

@@ -659,6 +659,7 @@ $mat-light-theme-background: (
selected-button: map_get($mat-grey, 300),
selected-disabled-button: map_get($mat-grey, 400),
disabled-button-toggle: map_get($mat-grey, 200),
disabled-list-option: map_get($mat-grey, 200),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Deleted indent

@@ -659,6 +659,7 @@ $mat-light-theme-background: (
selected-button: map_get($mat-grey, 300),
selected-disabled-button: map_get($mat-grey, 400),
disabled-button-toggle: map_get($mat-grey, 200),
disabled-list-option: map_get($mat-grey, 200),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Deleted indent

onFocus = new EventEmitter<MdSelectionListOptionEvent>();

/** Emitted when the option is selected. */
@Output() select = new EventEmitter<MdSelectionListOptionEvent>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed to selectChange

this._lineSetter = new MdLineSetter(this._lines, this._renderer, this._element);

if (this.selectionList.disabled) {
this._disabled = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleted if (this.selectionList.disabled) {...} part in toggle(), and put theif (this.selectionList.disabled) {...} part into a new function which is '_handleClick()'.

}

toggle(): void {
if (!this._disabled) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Changed to this.disabled

@@ -182,3 +212,5 @@ $mat-dense-list-icon-size: 20px;
}
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Deleted empty lines

@tinayuangao
Copy link
Contributor

LGTM. Please sync and rebase.

# This is the 1st commit message:

add lib files for sticky-header

add chose parent

add support to 'optional 'cdkStickyRegion' input '

add app-demo for sticky-header

fix bugs and deleted unused tag id in HTML files

modify

fix some code according to PR review comments

change some format to pass TSlint check

add '_' before private elements

delete @Injectable for StickyHeaderDirective. Because we do not need @Injectable

refine code

encapsulate 'set style for element'

change @input()

Delete 'Observable.fromEvent(this.upperScrollableContainer, 'scroll')'

add const STICK_START_CLASS and STICK_END_CLASS

Add doc for [cdkStickyRegion] and 'unstuckElement()'. Delete 'detach()' function, add its content into 'ngOnDestroy()'.

change 'MdStickyHeaderModule' to 'CdkStickyHeaderModule';

encapsulate reset css style operation for sticky header.

delete unnecessary gloable variables

sticky-header-rebased

add one test &&

fixed bug 'sticky-header not working on iPhone', and bug 'reshape too obviously when being sticked'. &&

made some change according to the design doc('md-stick --> cdkSticky')

make the sticky element being scrolled up smoothly when being unsticked

Add code to support  optional parentRegion input

add

add unit test for sticky-header

add e2e/sticky-header files

e2e test

clear code

master

sticky-header-rebased

Add code to support  optional parentRegion input

add e2e/sticky-header files

e2e test

clear code

fix

encapsulate reset css style operation for sticky header.

sticky-header-rebased

Add code to support  optional parentRegion input

add e2e/sticky-header files

e2e test

clear code

master

sticky-header-rebased

Add code to support  optional parentRegion input

add e2e/sticky-header files

e2e test

clear code

fix

delete unused files

encapsulate reset css style operation for sticky header.

sticky-header-rebased

Add code to support  optional parentRegion input

add unit test for sticky-header

add e2e/sticky-header files

e2e test

clear code

master

sticky-header-rebased

Add code to support  optional parentRegion input

add e2e/sticky-header files

e2e test

clear code

fix

encapsulate reset css style operation for sticky header.

sticky-header-rebased

Add code to support  optional parentRegion input

add e2e/sticky-header files

e2e test

clear code

master

sticky-header-rebased

Add code to support  optional parentRegion input

add e2e/sticky-header files

e2e test

clear code

fix

clean unused files

delete sticky-header

delete styicky-heade demo

delete sticky-header lib

revert public_api

delete sticky-header e2e files

delete.firebasesrc

revert

revert

revert

revert

add css styles for selection-list

add selection-list structures in list.ts

initial version of selection-list all src/lib code

fix tslint error

fix tslint error

applied '[class.mat-list-item-content-reverse]="checkboxPosition == 'after'"', deleted comments in code

Deleted 'MdSelectionListCssMatStyler' class

Added doc for 'md-selection-option'

Added binding expression for 'attr.aria-selected' and 'attr.aria-disabled'

Added a value and a disabled @input() property

Changed 'isSelected' to 'selected'. And added '@input(selected)' for it.(Using 'coerceBooleanProperty')

changed '_slist' to 'selectionList' and deleted 'MdSelectionListCheckboxer' class

Deleted navList in selection-list-option

changed 'onchange()' to toggle(). And added doc for it

checkedItems -> selectedOptions

deleted 'pCheckbox' and store 'this' instead of HTMLelement in 'optionlist'

optimized toggle() with 'this._selected = !this._selected'

Added 'Tab' moves focus on selection-list, 'UP_ARROW' and 'DOWN_ARROW' moves focus within selection-list. And use 'SPACE' to select checkbox

Added another empty line at the end of each file

remove comment line in CSS file

Deleted 'webkit-justify-content' in CSS file

Deleted 'mat-list-item-content-reverse' to these existing styles; the 'mat-list-item-content-reverse' class should only have the extra styles you need to reverse the display

Deleted 'mat-list-item-content' and 'mat-list-item-content-reverse' and '<a>' styles in '.mat-selection-list'

Deleted unused 'mat-checkbox' class

add ".mat-list-option" class in css file

added 'mat-list-option' class

fix toggle() disabled

Deleted empty class

Deleted unused import

Removed 'if (this.selectable)' check

moved styles in '.mat-selection-list .mat-list-item' to '.mat-list-option'.

Deleted position, box-sizing, and height in '.mat-list-item-content-reverse' in list.scss file

put md-selection-list and md-list-option in separate files(selection-list.ts and list-option.ts)

# This is the commit message angular#2:

nit
# This is the commit message angular#3:

correct imports in index.ts


# This is the commit message angular#4:

use ' @ContentChildren(MdListOption) options;' instead of QueryList
add chose parent

add support to 'optional 'cdkStickyRegion' input '

add app-demo for sticky-header

fix bugs and deleted unused tag id in HTML files

modify

fix some code according to PR review comments

change some format to pass TSlint check

add '_' before private elements

delete @Injectable for StickyHeaderDirective. Because we do not need @Injectable

refine code

encapsulate 'set style for element'

change @input()

Delete 'Observable.fromEvent(this.upperScrollableContainer, 'scroll')'

add const STICK_START_CLASS and STICK_END_CLASS

Add doc for [cdkStickyRegion] and 'unstuckElement()'. Delete 'detach()' function, add its content into 'ngOnDestroy()'.

change 'MdStickyHeaderModule' to 'CdkStickyHeaderModule';

encapsulate reset css style operation for sticky header.

delete unnecessary gloable variables

sticky-header-rebased

add one test &&

fixed bug 'sticky-header not working on iPhone', and bug 'reshape too obviously when being sticked'. &&

made some change according to the design doc('md-stick --> cdkSticky')

make the sticky element being scrolled up smoothly when being unsticked

Add code to support  optional parentRegion input

add

add unit test for sticky-header

add e2e/sticky-header files

e2e test

clear code

master

sticky-header-rebased

Add code to support  optional parentRegion input

add e2e/sticky-header files

e2e test

clear code

fix

encapsulate reset css style operation for sticky header.

sticky-header-rebased

Add code to support  optional parentRegion input

add e2e/sticky-header files

e2e test

clear code

master

sticky-header-rebased

Add code to support  optional parentRegion input

add e2e/sticky-header files

e2e test

clear code

fix

delete unused files

encapsulate reset css style operation for sticky header.

sticky-header-rebased

Add code to support  optional parentRegion input

add unit test for sticky-header

add e2e/sticky-header files

e2e test

clear code

master

sticky-header-rebased

Add code to support  optional parentRegion input

add e2e/sticky-header files

e2e test

clear code

fix

encapsulate reset css style operation for sticky header.

sticky-header-rebased

Add code to support  optional parentRegion input

add e2e/sticky-header files

e2e test

clear code

master

sticky-header-rebased

Add code to support  optional parentRegion input

add e2e/sticky-header files

e2e test

clear code

fix

clean unused files

delete sticky-header

delete styicky-heade demo

delete sticky-header lib

revert public_api

delete sticky-header e2e files

delete.firebasesrc

revert

revert

revert

revert

add css styles for selection-list

add selection-list structures in list.ts

initial version of selection-list all src/lib code

fix tslint error

fix tslint error

applied '[class.mat-list-item-content-reverse]="checkboxPosition == 'after'"', deleted comments in code

Deleted 'MdSelectionListCssMatStyler' class

Added doc for 'md-selection-option'

Added binding expression for 'attr.aria-selected' and 'attr.aria-disabled'

Added a value and a disabled @input() property

Changed 'isSelected' to 'selected'. And added '@input(selected)' for it.(Using 'coerceBooleanProperty')

changed '_slist' to 'selectionList' and deleted 'MdSelectionListCheckboxer' class

Deleted navList in selection-list-option

changed 'onchange()' to toggle(). And added doc for it

checkedItems -> selectedOptions

deleted 'pCheckbox' and store 'this' instead of HTMLelement in 'optionlist'

optimized toggle() with 'this._selected = !this._selected'

Added 'Tab' moves focus on selection-list, 'UP_ARROW' and 'DOWN_ARROW' moves focus within selection-list. And use 'SPACE' to select checkbox

Added another empty line at the end of each file

remove comment line in CSS file

Deleted 'webkit-justify-content' in CSS file

Deleted 'mat-list-item-content-reverse' to these existing styles; the 'mat-list-item-content-reverse' class should only have the extra styles you need to reverse the display

Deleted 'mat-list-item-content' and 'mat-list-item-content-reverse' and '<a>' styles in '.mat-selection-list'

Deleted unused 'mat-checkbox' class

add ".mat-list-option" class in css file

added 'mat-list-option' class

fix toggle() disabled

Deleted empty class

Deleted unused import

Removed 'if (this.selectable)' check

moved styles in '.mat-selection-list .mat-list-item' to '.mat-list-option'.

Deleted position, box-sizing, and height in '.mat-list-item-content-reverse' in list.scss file

put md-selection-list and md-list-option in separate files(selection-list.ts and list-option.ts)

nit

correct imports in index.ts

use ' @ContentChildren(MdListOption) options;' instead of QueryList

change to check 'focusedIndex != null'.

Set The tabindex of list option as -1 when the selection-list is disabled

change ['class': 'mat-list-item, mat-list-option',] to ['class': 'mat-list-item mat-list-option',];
Don't want a comma between class names.

fix typo in comments

fix

Binded 'aria-disabled' for selection-list.ts

rename to '_optionsChangeSubscription'

typo

Instead of defining the disabled getter/setter yourself, you can include it via mixin.

Removed ' selectable' property

Deleted unnecessary 'this._isValidIndex(optionIndex)' check

import switchMap

Added SwitchMerge

nit

revert
revert
revert2

revert3
r4
r5
r2
r3
r4
r5

revert

fix rxjs import

Changed to use 'RxChain' instead of directly importing 'observer/add/'

delete unusd import

Added exports for selectionlist

fix tslint check

fix tslint check

fix tslint check

Add tests for selection-list and list-option

fix typo in test

Added new test on native element's focus & blur

Added check expect(selectList.selected.length).toBe(0);before the toggle

nit

Added test on desecting an option

fix tslink check

fix typo in doc

refine docs

fix 'What happens if the selection list is disabled later? Would the list option become disabled?'

Changed all the test name to the format of 'should ...'

rename

Deleted unused '_tabOutSubscription'

return RxChain.from(this.options.changes)...

fix tsLint check

fix tslint

fix tslint error

test can not pass on travel CI

fix travelCI check

try to fix nativeElement focus test

revert

fix test

fix travis CI error

fixing travis
fixed~!
update fix

fix

fix
fix2
fix

added test check on 'aria-selected'

Added test checkou on 'aria-disabled'

reformat structure

changed to 'if (!fixture.componentInstance.isIE) { ... }'

Change 'platform.SAFARI || platform.EDGE || platform.FIREFOX' to '!platform.IS_TRIDENT'

fix travis check

Added aris-disabled test

fix travis test

put disabled style in theme.scss

use background color for disabled items

deselect --> deselected

destory -> destoryed

optimize

changed to "if (!this.disabled) {   ... }"

restructured test cases

change function to private

_keydown

protected -> private

indent

change 'select' to 'selectChange'

Better to delete if (this.selectionList.disabled) {...} part

Use this.disabled to consider the case when parent selectionList is disabled?

Deleted emty lines

It would be better not to mutate the option disabled state based on the parent state; this can be error prone, as it's easy to miss updating one when the other changes. It's better to rely on the disabled getter for the option to account for the parent state.
@sllethe sllethe force-pushed the selection-list-initialVersionAllcode branch from 2098fc6 to 7f72853 Compare August 10, 2017 19:25
@sllethe
Copy link
Contributor Author

sllethe commented Aug 10, 2017

👍 synced and rebased

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Aug 10, 2017
@jelbourn
Copy link
Member

@sllethe seems like the unit tests are failing

@sllethe
Copy link
Contributor Author

sllethe commented Aug 12, 2017

fixed failing tests~

constructor(private _renderer: Renderer2,
private _element: ElementRef,
private _changeDetector: ChangeDetectorRef,
@Self() @Optional() @Inject(forwardRef(() => MdSelectionList)) public selectionList: MdSelectionList) { }
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for @Self() here, and Inject needs to be added to imports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Deleted @Self() and added import for Inject

@mmalerba mmalerba merged commit dccce1c into angular:master Aug 12, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants