Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 6907147

Browse files
authored
refactor(select): Sync MDC v6.0.0 changes (#2245)
closes #2243
1 parent d2a013b commit 6907147

14 files changed

+818
-299
lines changed

demos/src/app/components/select/examples.html

-14
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ <h3 class="demo-content__headline">Select</h3>
1010
<button mdc-button
1111
(click)="standardSelect.disabled = !standardSelect.disabled">Disabled:
1212
{{standardSelect.disabled ? 'On' : 'Off'}}</button>
13-
<button mdc-button
14-
(click)="standardSelect.floatLabel = !standardSelect.floatLabel">Float
15-
Label: {{standardSelect.floatLabel ? 'On' :
16-
'Off'}}</button>
1713
<button mdc-button
1814
(click)="standardSelect.setSelectionByValue('banana')">Select
1915
Banana</button>
@@ -68,9 +64,6 @@ <h3 class="demo-content__headline">Leading Icon</h3>
6864
{{meal.required ? 'On' : 'Off'}}</button>
6965
<button mdc-button (click)="meal.disabled = !meal.disabled">Disabled:
7066
{{meal.disabled ? 'On' : 'Off'}}</button>
71-
<button mdc-button (click)="meal.floatLabel = !meal.floatLabel">Float
72-
Label: {{meal.floatLabel ? 'On' :
73-
'Off'}}</button>
7467
<button mdc-button (click)="meal.setSelectedIndex(2)">Set Index (2)</button>
7568
</div>
7669
<mdc-select #meal [helperText]="mealHelper" required
@@ -186,9 +179,6 @@ <h3 class="demo-content__headline">Select with ngModel</h3>
186179
{{select.outlined ? 'On' : 'Off'}}</button>
187180
<button mdc-button (click)="select.disabled = !select.disabled">Disabled:
188181
{{select.disabled ? 'On' : 'Off'}}</button>
189-
<button mdc-button (click)="select.floatLabel = !select.floatLabel">Float
190-
Label: {{select.floatLabel ? 'On' :
191-
'Off'}}</button>
192182
<button mdc-button (click)="demoNgModel.reset()">Clear Selection</button>
193183
<button mdc-button (click)="select.setSelectionByValue('fruit-3')">Select
194184
Fruit</button>
@@ -225,10 +215,6 @@ <h3 class="demo-content__headline">Select with FormControl</h3>
225215
(click)="favoriteFood.disabled = !favoriteFood.disabled">Disabled:
226216
{{favoriteFood.disabled ?
227217
'On' : 'Off'}}</button>
228-
<button mdc-button
229-
(click)="favoriteFood.floatLabel = !favoriteFood.floatLabel">Float
230-
Label:
231-
{{favoriteFood.floatLabel ? 'On' : 'Off'}}</button>
232218
<button mdc-button
233219
(click)="favoriteFood.setSelectionByValue('pizza-1')">Select
234220
Pizza</button>

demos/src/app/components/select/module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ import {MDC_SELECT_DEFAULT_OPTIONS} from '@angular-mdc/web/select';
1010
RoutingModule
1111
],
1212
declarations: [ROUTE_DECLARATIONS],
13-
providers: [{ provide: MDC_SELECT_DEFAULT_OPTIONS, useValue: {outlined: true}}],
13+
// providers: [{ provide: MDC_SELECT_DEFAULT_OPTIONS, useValue: {outlined: true}}],
1414
})
1515
export class SelectModule {}

demos/src/app/components/select/select.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class Select implements OnInit {
2121
ngOnInit(): void {
2222
this._componentViewer.template = {
2323
title: 'Select Menus',
24-
description: 'MDC Select provides Material Design single-option select menus, using the MDC menu. The Select component is fully accessible, and supports RTL rendering.',
24+
description: 'MDC Select provides Material Design single-option select menus, using the MDC menu.',
2525
references: [{
2626
name: 'Material Design guidelines: Menus',
2727
url: 'https://material.io/guidelines/components/menus.html'
@@ -36,7 +36,7 @@ export class Select implements OnInit {
3636
],
3737
code: `import {MdcSelectModule} from '@angular-mdc/web/select';`,
3838
sass: `@use '@material/select/mdc-select';
39-
@use '@material/select';
39+
@use '@material/select/_index' as select;
4040
@use '@material/list/mdc-list';
4141
@use '@material/menu-surface/mdc-menu-surface';
4242
@use '@material/menu/mdc-menu';`
@@ -66,7 +66,6 @@ export class Api implements OnInit {
6666
{name: 'placeholder: string', summary: `Text shown if no value has been selected.`},
6767
{name: 'value: any', summary: `Sets the selected item by value.`},
6868
{name: 'tabIndex: number', summary: `Set the underlying tab index of the select. (Default is 0)`},
69-
{name: 'floatLabel: boolean', summary: `Whether or not to show or hide a floating placeholder.`},
7069
{name: 'outlined: boolean', summary: `Styles the select as an outlined select.`},
7170
{name: 'disabled: boolean', summary: `Enables/disables the select.`},
7271
{name: 'helperText: MdcHelperText', summary: `Reference to related MdcHelperText`},

demos/yarn.lock

+101-96
Large diffs are not rendered by default.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@angular/forms": "^9.1.2",
4141
"@angular/platform-browser": "^9.1.2",
4242
"core-js": "^2.6.9",
43-
"material-components-web": "6.0.0-canary.c141801d5.0",
43+
"material-components-web": "6.0.0",
4444
"rxjs": "^6.5.5",
4545
"tsickle": "0.38.1",
4646
"tslib": "1.11.1",

packages.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# version for the placeholders.
44
ANGULAR_PACKAGE_VERSION = "^9.0.0 || ^10.0.0-0"
55
ANGULAR_CDK_PACKAGE_VERSION = "^9.2.1"
6-
MDC_PACKAGE_VERSION = "6.0.0-canary.c141801d5.0"
6+
MDC_PACKAGE_VERSION = "6.0.0"
77
TSLIB_PACKAGE_VERSION = "^1.11.1"
88

99
VERSION_PLACEHOLDER_REPLACEMENTS = {

packages/select/module.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,13 @@ import {MdcMenuModule} from '@angular-mdc/web/menu';
99
import {MdcListModule} from '@angular-mdc/web/list';
1010

1111
import {MdcSelect} from './select';
12-
import {
13-
MdcSelectAnchor,
14-
MdcSelectIcon,
15-
MdcSelectedText
16-
} from './select-directives';
12+
import {MdcSelectIcon} from './select-icon';
1713
import {MDCSelectHelperText} from './select-helper-text';
1814

1915
const SELECT_DECLARATIONS = [
2016
MdcSelect,
21-
MdcSelectAnchor,
2217
MDCSelectHelperText,
2318
MdcSelectIcon,
24-
MdcSelectedText
2519
];
2620

2721
@NgModule({

packages/select/public-api.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from './module';
2-
export * from './select-directives';
2+
export * from './select-icon';
33
export * from './select-helper-text';
44
export * from './select';

packages/select/select-directives.ts

-50
This file was deleted.

packages/select/select-icon.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {Directive} from '@angular/core';
2+
3+
@Directive({
4+
selector: '[mdcSelectIcon]',
5+
exportAs: 'mdcSelectIcon',
6+
host: {'class': 'mdc-select__icon'}
7+
})
8+
export class MdcSelectIcon {}

packages/select/select.html

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
<div mdcSelectAnchor>
1+
<div #selectAnchor class="mdc-select__anchor"
2+
role="button"
3+
aria-haspopup="listbox"
4+
[tabindex]="disabled ? '-1' : '0'"
5+
[attr.aria-required]="required"
6+
[attr.aria-labelledby]="placeholder"
7+
(focus)="onFocus()"
8+
(blur)="onBlur()"
9+
(keydown)="onKeydown($event)"
10+
(click)="onClick($event)">
11+
<span class="mdc-select__ripple"></span>
212
<ng-content select="mdc-icon"></ng-content>
3-
<i class="mdc-select__dropdown-icon"></i>
4-
<div mdcSelectedText
5-
[tabindex]="disabled ? '-1' : '0'"
6-
(focus)="onFocus()"
7-
(blur)="onBlur()"
8-
(keydown)="onKeydown($event)"
9-
(click)="onClick($event)"
10-
[ariaRequired]="required"
11-
[ariaLabelledby]="id"></div>
13+
<input #selectSelectedText class="mdc-select__selected-text"
14+
type="text"
15+
disabled
16+
readonly
17+
[value]="_selectedText" />
18+
<i class="mdc-select__dropdown-icon"></i>
1219
<label mdcFloatingLabel *ngIf="!outlined" [for]="id">{{placeholder}}</label>
1320
<mdc-line-ripple *ngIf="!outlined"></mdc-line-ripple>
1421
<mdc-notched-outline *ngIf="outlined" [label]="placeholder" [for]="id"></mdc-notched-outline>

packages/select/select.spec.ts

+1-45
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,6 @@ describe('MdcSelectModule', () => {
8080
dispatchKeyboardEvent(testInstance.elementRef.nativeElement, 'keydown', DOWN_ARROW);
8181
fixture.detectChanges();
8282
});
83-
84-
it('#should handle mouse events', fakeAsync(() => {
85-
dispatchMouseEvent(testInstance._selectedText.root, 'click');
86-
fixture.detectChanges();
87-
testInstance.focus();
88-
dispatchKeyboardEvent(testInstance._selectedText.root, 'keydown', DOWN_ARROW);
89-
dispatchKeyboardEvent(testInstance.elementRef.nativeElement, 'keydown', DOWN_ARROW);
90-
fixture.detectChanges();
91-
92-
flush();
93-
}));
9483
});
9584

9685
describe('basic behaviors', () => {
@@ -119,12 +108,6 @@ describe('MdcSelectModule', () => {
119108
expect(testInstance.disabled).toBe(true);
120109
});
121110

122-
it('#should set floatLabel to false', () => {
123-
testComponent.floatLabel = false;
124-
fixture.detectChanges();
125-
expect(testInstance.floatLabel).toBe(false);
126-
});
127-
128111
it('#should set required to true', () => {
129112
testComponent.required = true;
130113
fixture.detectChanges();
@@ -137,15 +120,6 @@ describe('MdcSelectModule', () => {
137120
expect(testInstance.valid).toBe(true);
138121
});
139122

140-
it('#should set outlined and floating label with value', () => {
141-
testInstance.setSelectionByValue('fruit-3');
142-
testComponent.outlined = true;
143-
testComponent.floatLabel = true;
144-
fixture.detectChanges();
145-
146-
expect(testInstance.floatLabel).toBe(true);
147-
});
148-
149123
it('#should generate a unique id for the select if no id is set', () => {
150124
expect(testInstance.id).toMatch(/mdc-select-\d+/);
151125
});
@@ -310,23 +284,6 @@ describe('MdcSelectModule', () => {
310284
expect(testInstance.required).toBe(false);
311285
});
312286

313-
it('#should handle mouse events', fakeAsync(() => {
314-
dispatchMouseEvent(testInstance._selectedText.root, 'click');
315-
fixture.detectChanges();
316-
testInstance.focus();
317-
dispatchKeyboardEvent(testInstance._selectedText.root, 'keydown', DOWN_ARROW);
318-
dispatchKeyboardEvent(testInstance.elementRef.nativeElement, 'keydown', DOWN_ARROW);
319-
fixture.detectChanges();
320-
321-
flush();
322-
}));
323-
324-
it('#should handle keydown events', fakeAsync(() => {
325-
dispatchKeyboardEvent(testInstance._selectedText.root, 'keydown', DOWN_ARROW);
326-
fixture.detectChanges();
327-
flush();
328-
}));
329-
330287
it('#should handle mouse events', fakeAsync(() => {
331288
testComponent.open = true;
332289
fixture.detectChanges();
@@ -393,7 +350,7 @@ it('should be able to provide default values through an injection token', () =>
393350
<form #demoSelectForm="ngForm" id="demoSelectForm">
394351
<mdc-form-field>
395352
<mdc-select #select placeholder="Favorite food" ngModel #demoSelectModel="ngModel" name="food"
396-
[disabled]="disabled" [floatLabel]="floatLabel" [required]="required" [valid]="valid"
353+
[disabled]="disabled" [required]="required" [valid]="valid"
397354
[value]="testValue" [outlined]="outlined" (blur)="handleBlur()"
398355
(valueChange)="handleValueChange($event)" (selectionChange)="handleSelectedChange($event)">
399356
<mdc-menu>
@@ -413,7 +370,6 @@ it('should be able to provide default values through an injection token', () =>
413370
class SimpleTest {
414371
myPlaceholder: string = 'Favorite food';
415372
disabled: boolean = true;
416-
floatLabel: boolean;
417373
multiple: boolean;
418374
required: boolean;
419375
valid: boolean = false;

0 commit comments

Comments
 (0)