Skip to content

Commit 3e17ce7

Browse files
mmalerbajelbourn
authored andcommitted
prototype(checkbox): create prototype checkbox based on MDC Web (#15782)
* 3.1. Add MDC to deps Adds MDC as a peer dependency and updates various build and test config files accordingly. * 3.2. Add the new component skeleton Adds files for MDC-based MatCheckbox. * 3.3. Add a demo for the new component Adds a demo of the MDC-based MatCheckbox at http://localhost:4200/mdc-checkbox. * 3.4. Copy in the canonical MDC DOM and add the MDC styles Adds the MDCCheckbox DOM and styles to the MDC-based MatCheckbox. * 3.5. Set up the MDC foundation Adds the MDCCheckboxFoundation and MDCFormFieldFoundation and translates the lifecycle setup from their respective components (https://github.com/material-components/material-components-web/blob/master/packages/mdc-checkbox/component.ts and https://github.com/material-components/material-components-web/blob/master/packages/mdc-form-field/component.ts) into our MDC-based MatCheckbox. * 3.6. Add a custom MDC adapter Adds an Angular adapter for MDCCheckboxFoundation and MDCFormFieldFoundation * 3.7. Fill in the missing APIs to match the API of the existing Angular Material component Fills in the remaining APIs on the MDC-based MatCheckbox. * 3.8. Copy over the existing demo page to the MDC-based demo Copies over the demo page for the existing MatCheckbox to the demo page for the MDC-based MatCheckbox. Also adds an additional demo to both pages. * 4.1. Manual inspection and testing Adds ripple using RippleRenderer which results in a smaller size than MatRipple or MDCRipple. Also adds support for disabling animations. * 4.2. Copy over unit tests and update them Copies over all of the tests from the existing MatCheckbox and fixes issues that were uncovered by the tests. * 4.3. Copy over e2e tests if any exist Adds MDC-based MatCheckbox to the e2e app and copies over the tests for the existing MatCheckbox. * 4.4. Add MDC-based component to universal-app Adds a couple examples of the MDC-based MatCheckbox to the universal app. * 5.2. Investigate and fix size regressions Removes usgaes of constants from `MDCRippleFoundation`. It looks like their use was preventing the class from being tree-shaken. Results after removing the constants show that the MDC-based implementation is 3kb smaller: https://github.com/mmalerba/mdc-size-comparison/blob/ee1b73a181c4a23345251656df23574140a747c0/results/size-summary.txt * 8. Add user documentation Adds documentation explaining what this component is and how to experiment with it in your app. * 9.2. Address CI failures and reviewer feedback Fixes unit tests in Edge and approves the new API goldens for checkbox.
1 parent 6bcb1da commit 3e17ce7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3947
-113
lines changed

.github/CODEOWNERS

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@
8383
/src/material-moment-adapter/** @mmalerba
8484

8585
# Material experimental package
86-
/src/material-experimental/** @jelbourn
86+
/src/material-experimental/* @jelbourn
87+
/src/material-experimental/mdc-checkbox/** @mmalerba
88+
/src/material-experimental/mdc-helpers/** @mmalerba
8789

8890
# CDK experimental package
8991
/src/cdk-experimental/** @jelbourn
@@ -126,6 +128,7 @@
126128
/src/dev-app/input/** @mmalerba
127129
/src/dev-app/list/** @jelbourn @crisbeto @devversion
128130
/src/dev-app/live-announcer/** @jelbourn
131+
/src/dev-app/mdc-checkbox/** @mmalerba
129132
/src/dev-app/menu/** @crisbeto
130133
/src/dev-app/overlay/** @jelbourn @crisbeto
131134
/src/dev-app/paginator/** @andrewseguin
@@ -164,6 +167,7 @@
164167
/e2e/components/icon-e2e.spec.ts @jelbourn
165168
/e2e/components/input-e2e.spec.ts @mmalerba
166169
/e2e/components/list-e2e.spec.ts @jelbourn @crisbeto @devversion
170+
/e2e/components/mdc-checkbox-e2e.spec.ts @mmalerba
167171
/e2e/components/menu-e2e.spec.ts @crisbeto
168172
/e2e/components/progress-bar-e2e.spec.ts @jelbourn @crisbeto @josephperrott
169173
/e2e/components/progress-spinner-e2e.spec.ts @jelbourn @crisbeto @josephperrott
@@ -189,6 +193,7 @@
189193
/src/e2e-app/icon/** @jelbourn
190194
/src/e2e-app/input/** @mmalerba
191195
/src/e2e-app/list/** @jelbourn
196+
/src/e2e-app/mdc-checkbox/** @mmalerba
192197
/src/e2e-app/menu/** @crisbeto
193198
/src/e2e-app/progress-bar/** @jelbourn @crisbeto @josephperrott
194199
/src/e2e-app/progress-spinner/** @jelbourn @crisbeto @josephperrott

build-config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ const buildVersion = packageJson.version;
1515
*/
1616
const angularVersion = packageJson.requiredAngularVersion;
1717

18+
/**
19+
* Required MDC Web version for all Angular Material packages. This version will be used
20+
* as the peer dependency version for MDC Web in all release packages that require MDC Web.
21+
*/
22+
const mdcVersion = packageJson.requiredMDCVersion;
23+
1824
/** License that will be placed inside of all created bundles. */
1925
const buildLicense = `/**
2026
* @license
@@ -27,6 +33,7 @@ const buildLicense = `/**
2733
module.exports = {
2834
projectVersion: buildVersion,
2935
angularVersion: angularVersion,
36+
mdcVersion: mdcVersion,
3037
projectDir: __dirname,
3138
packagesDir: join(__dirname, 'src'),
3239
outputDir: join(__dirname, 'dist'),
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {browser, by, element, Key} from 'protractor';
2+
3+
describe('MDC checkbox', () => {
4+
describe('check behavior', () => {
5+
beforeEach(async () => await browser.get('/mdc-checkbox'));
6+
7+
it('should be checked when clicked, and unchecked when clicked again', async () => {
8+
const checkboxEl = element(by.id('test-checkbox'));
9+
const inputEl = element(by.css('input[id=test-checkbox-input]'));
10+
11+
await checkboxEl.click();
12+
13+
expect(await inputEl.getAttribute('checked'))
14+
.toBeTruthy('Expect checkbox "checked" property to be true');
15+
16+
await checkboxEl.click();
17+
18+
expect(await inputEl.getAttribute('checked'))
19+
.toBeFalsy('Expect checkbox "checked" property to be false');
20+
});
21+
22+
it('should toggle the checkbox when pressing space', async () => {
23+
const inputEl = element(by.css('input[id=test-checkbox-input]'));
24+
25+
expect(await inputEl.getAttribute('checked'))
26+
.toBeFalsy('Expect checkbox "checked" property to be false');
27+
await inputEl.sendKeys(Key.SPACE);
28+
29+
expect(await inputEl.getAttribute('checked'))
30+
.toBeTruthy('Expect checkbox "checked" property to be true');
31+
});
32+
});
33+
});

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
},
3131
"version": "8.0.0-beta.2",
3232
"requiredAngularVersion": ">=7.0.0",
33+
"requiredMDCVersion": "^1.1.0",
3334
"dependencies": {
3435
"@angular/animations": "8.0.0-beta.10",
3536
"@angular/common": "8.0.0-beta.10",
@@ -40,6 +41,7 @@
4041
"@angular/platform-browser": "8.0.0-beta.10",
4142
"@webcomponents/custom-elements": "^1.1.0",
4243
"core-js": "^2.6.1",
44+
"material-components-web": "^1.1.0",
4345
"rxjs": "^6.4.0",
4446
"systemjs": "0.19.43",
4547
"tsickle": "^0.34.0",

packages.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ MATERIAL_SCSS_LIBS = [
8282
# all in-sync. This map is passed to each ng_package rule to stamp out the appropriate
8383
# version for the placeholders.
8484
ANGULAR_PACKAGE_VERSION = ">=6.0.0-beta.0 <7.0.0"
85+
MDC_PACKAGE_VERSION = "^1.1.0"
8586
VERSION_PLACEHOLDER_REPLACEMENTS = {
8687
"0.0.0-NG": ANGULAR_PACKAGE_VERSION,
88+
"0.0.0-MDC": MDC_PACKAGE_VERSION
8789
}
8890

8991
# Base rollup globals for everything in the repo.

src/dev-app/BUILD.bazel

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@ ng_module(
2525
"@npm//@angular/platform-browser-dynamic",
2626
"@npm//@angular/router",
2727
"@npm//rxjs",
28+
"//src/material-experimental/mdc-checkbox",
2829
"//src/material-examples:examples",
2930
] + CDK_TARGETS + CDK_EXPERIMENTAL_TARGETS + MATERIAL_TARGETS
3031
)
3132

3233
sass_binary(
3334
name = "theme",
3435
src = "theme.scss",
36+
include_paths = [
37+
"external/npm/node_modules",
38+
],
3539
deps = [
36-
"//src/lib/core:all_themes"
40+
"//src/lib/core:all_themes",
41+
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",
42+
"//src/material-experimental/mdc-checkbox:checkbox_scss_lib",
3743
]
3844
)

src/dev-app/checkbox/checkbox-demo-module.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,38 @@
88

99
import {CommonModule} from '@angular/common';
1010
import {NgModule} from '@angular/core';
11-
import {FormsModule} from '@angular/forms';
12-
import {MatCheckboxModule, MatPseudoCheckboxModule} from '@angular/material';
11+
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
12+
import {
13+
MatCheckboxModule,
14+
MatFormFieldModule,
15+
MatInputModule,
16+
MatPseudoCheckboxModule,
17+
MatSelectModule
18+
} from '@angular/material';
1319
import {RouterModule} from '@angular/router';
14-
import {CheckboxDemo, MatCheckboxDemoNestedChecklist} from './checkbox-demo';
20+
import {
21+
AnimationsNoop,
22+
CheckboxDemo,
23+
ClickActionCheck,
24+
ClickActionNoop,
25+
MatCheckboxDemoNestedChecklist
26+
} from './checkbox-demo';
1527

1628
@NgModule({
1729
imports: [
1830
CommonModule,
1931
FormsModule,
2032
MatCheckboxModule,
33+
MatFormFieldModule,
34+
MatInputModule,
35+
MatSelectModule,
2136
MatPseudoCheckboxModule,
37+
ReactiveFormsModule,
2238
RouterModule.forChild([{path: '', component: CheckboxDemo}]),
2339
],
24-
declarations: [CheckboxDemo, MatCheckboxDemoNestedChecklist],
40+
declarations: [
41+
CheckboxDemo, MatCheckboxDemoNestedChecklist, ClickActionCheck, ClickActionNoop, AnimationsNoop
42+
],
2543
})
2644
export class CheckboxDemoModule {
2745
}

0 commit comments

Comments
 (0)