Skip to content

Commit 4f42901

Browse files
committed
rename input to text-field
1 parent 85484dc commit 4f42901

24 files changed

+107
-106
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
/src/cdk/bidi/** @jelbourn
6262
/src/cdk/coercion/** @jelbourn
6363
/src/cdk/collections/** @jelbourn @crisbeto @andrewseguin
64-
/src/cdk/input/** @mmalerba
6564
/src/cdk/keycodes/** @jelbourn
6665
/src/cdk/layout/** @josephperrott
6766
/src/cdk/observers/** @jelbourn @crisbeto
@@ -72,6 +71,7 @@
7271
/src/cdk/stepper/** @mmalerba
7372
/src/cdk/table/** @andrewseguin
7473
/src/cdk/testing/** @devversion
74+
/src/cdk/text-field/** @mmalerba
7575

7676
# Moment adapter package
7777
/src/material-moment-adapter/** @mmalerba

src/cdk/input/_input.scss

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/cdk/input/input-prebuilt.scss

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/cdk/input/BUILD.bazel renamed to src/cdk/text-field/BUILD.bazel

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ load("@angular//:index.bzl", "ng_module")
33
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library", "sass_binary")
44

55
ng_module(
6-
name = "input",
6+
name = "text-field",
77
srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]),
8-
module_name = "@angular/cdk/input",
8+
module_name = "@angular/cdk/text-field",
99
deps = [
1010
"@rxjs",
1111
"//src/cdk/platform",
@@ -14,21 +14,21 @@ ng_module(
1414
)
1515

1616
sass_library(
17-
name = "input_scss_lib",
17+
name = "text_field_scss_lib",
1818
srcs = glob(["**/_*.scss"]),
1919
)
2020

2121
sass_binary(
22-
name = "input_prebuilt_scss",
23-
src = "input-prebuilt.scss",
24-
deps = [":input_scss_lib"],
22+
name = "text_field_prebuilt_scss",
23+
src = "text-field-prebuilt.scss",
24+
deps = [":text_field_scss_lib"],
2525
)
2626

2727
# TODO(jelbourn): remove this when sass_binary supports specifying an output filename and dir.
2828
# Copy the output of the sass_binary such that the filename and path match what we expect.
2929
genrule(
30-
name = "input_prebuilt_css",
31-
srcs = [":input_prebuilt_scss"],
32-
outs = ["input-prebuilt.css"],
33-
cmd = "cat $(locations :input_prebuilt_scss) > $@",
30+
name = "text_field_prebuilt_css",
31+
srcs = [":text_field_prebuilt_scss"],
32+
outs = ["text-field-prebuilt.css"],
33+
cmd = "cat $(locations :text_field_prebuilt_scss) > $@",
3434
)

src/cdk/text-field/_text-field.scss

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Core styles that enable monitoring autofill state of text fields.
2+
@mixin cdk-text-field {
3+
// Keyframes that apply no styles, but allow us to monitor when an text field becomes autofilled
4+
// by watching for the animation events that are fired when they start.
5+
// Based on: https://medium.com/@brunn/detecting-autofilled-fields-in-javascript-aed598d25da7
6+
@keyframes cdk-text-field-autofill-start {}
7+
@keyframes cdk-text-field-autofill-end {}
8+
9+
.cdk-text-field-autofill-monitored:-webkit-autofill {
10+
animation-name: cdk-text-field-autofill-start;
11+
}
12+
13+
.cdk-text-field-autofill-monitored:not(:-webkit-autofill) {
14+
animation-name: cdk-text-field-autofill-end;
15+
}
16+
17+
// Remove the resize handle on autosizing textareas, because whatever height
18+
// the user resized to will be overwritten once they start typing again.
19+
textarea.cdk-textarea-autosize {
20+
resize: none;
21+
}
22+
}
23+
24+
// Used to generate UIDs for keyframes used to change the text field autofill styles.
25+
$cdk-text-field-autofill-color-frame-count: 0;
26+
27+
// Mixin used to apply custom background and foreground colors to an autofilled text field.
28+
// Based on: https://stackoverflow.com/questions/2781549/
29+
// removing-input-background-colour-for-chrome-autocomplete#answer-37432260
30+
@mixin cdk-text-field-autofill-color($background, $foreground:'') {
31+
@keyframes cdk-text-field-autofill-color-#{$cdk-text-field-autofill-color-frame-count} {
32+
to {
33+
background: $background;
34+
@if $foreground != '' { color: $foreground; }
35+
}
36+
}
37+
38+
&:-webkit-autofill {
39+
animation-name: cdk-text-field-autofill-color-#{$cdk-text-field-autofill-color-frame-count};
40+
animation-fill-mode: both;
41+
}
42+
43+
&.cdk-text-field-autofill-monitored:-webkit-autofill {
44+
animation-name: cdk-text-field-autofill-start,
45+
cdk-text-field-autofill-color-#{$cdk-text-field-autofill-color-frame-count};
46+
}
47+
48+
$cdk-text-field-autofill-color-frame-count:
49+
$cdk-text-field-autofill-color-frame-count + 1 !global;
50+
}

src/cdk/input/autofill.spec.ts renamed to src/cdk/text-field/autofill.spec.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {Component, ElementRef, ViewChild} from '@angular/core';
1111
import {ComponentFixture, inject, TestBed} from '@angular/core/testing';
1212
import {empty as observableEmpty} from 'rxjs/observable/empty';
1313
import {AutofillEvent, AutofillMonitor} from './autofill';
14-
import {InputModule} from './input-module';
14+
import {TextFieldModule} from './text-field-module';
1515

1616

1717
const listenerOptions: any = supportsPassiveEventListeners() ? {passive: true} : false;
@@ -24,7 +24,7 @@ describe('AutofillMonitor', () => {
2424

2525
beforeEach(() => {
2626
TestBed.configureTestingModule({
27-
imports: [InputModule],
27+
imports: [TextFieldModule],
2828
declarations: [Inputs],
2929
}).compileComponents();
3030
});
@@ -52,7 +52,7 @@ describe('AutofillMonitor', () => {
5252
expect(inputEl.addEventListener).not.toHaveBeenCalled();
5353

5454
autofillMonitor.monitor(inputEl);
55-
expect(inputEl.classList).toContain('cdk-input-autofill-monitored');
55+
expect(inputEl.classList).toContain('cdk-text-field-autofill-monitored');
5656
expect(inputEl.addEventListener)
5757
.toHaveBeenCalledWith('animationstart', jasmine.any(Function), listenerOptions);
5858
});
@@ -69,11 +69,11 @@ describe('AutofillMonitor', () => {
6969
it('should remove monitored class and listener upon stop monitoring', () => {
7070
const inputEl = testComponent.input1.nativeElement;
7171
autofillMonitor.monitor(inputEl);
72-
expect(inputEl.classList).toContain('cdk-input-autofill-monitored');
72+
expect(inputEl.classList).toContain('cdk-text-field-autofill-monitored');
7373
expect(inputEl.removeEventListener).not.toHaveBeenCalled();
7474

7575
autofillMonitor.stopMonitoring(inputEl);
76-
expect(inputEl.classList).not.toContain('cdk-input-autofill-monitored');
76+
expect(inputEl.classList).not.toContain('cdk-text-field-autofill-monitored');
7777
expect(inputEl.removeEventListener)
7878
.toHaveBeenCalledWith('animationstart', jasmine.any(Function), listenerOptions);
7979
});
@@ -103,10 +103,10 @@ describe('AutofillMonitor', () => {
103103
const autofillStream = autofillMonitor.monitor(inputEl);
104104
autofillStream.subscribe(event => autofillStreamEvent = event);
105105
expect(autofillStreamEvent).toBeNull();
106-
expect(inputEl.classList).not.toContain('cdk-input-autofilled');
106+
expect(inputEl.classList).not.toContain('cdk-text-field-autofilled');
107107

108-
animationStartCallback({animationName: 'cdk-input-autofill-start', target: inputEl});
109-
expect(inputEl.classList).toContain('cdk-input-autofilled');
108+
animationStartCallback({animationName: 'cdk-text-field-autofill-start', target: inputEl});
109+
expect(inputEl.classList).toContain('cdk-text-field-autofilled');
110110
expect(autofillStreamEvent).toEqual({target: inputEl, isAutofilled: true} as any);
111111
});
112112

@@ -117,12 +117,12 @@ describe('AutofillMonitor', () => {
117117
inputEl.addEventListener.and.callFake((_, cb) => animationStartCallback = cb);
118118
const autofillStream = autofillMonitor.monitor(inputEl);
119119
autofillStream.subscribe(event => autofillStreamEvent = event);
120-
animationStartCallback({animationName: 'cdk-input-autofill-start', target: inputEl});
121-
expect(inputEl.classList).toContain('cdk-input-autofilled');
120+
animationStartCallback({animationName: 'cdk-text-field-autofill-start', target: inputEl});
121+
expect(inputEl.classList).toContain('cdk-text-field-autofilled');
122122
expect(autofillStreamEvent).toEqual({target: inputEl, isAutofilled: true} as any);
123123

124-
animationStartCallback({animationName: 'cdk-input-autofill-end', target: inputEl});
125-
expect(inputEl.classList).not.toContain('cdk-input-autofilled');
124+
animationStartCallback({animationName: 'cdk-text-field-autofill-end', target: inputEl});
125+
expect(inputEl.classList).not.toContain('cdk-text-field-autofilled');
126126
expect(autofillStreamEvent).toEqual({target: inputEl, isAutofilled: false} as any);
127127
});
128128

@@ -131,11 +131,11 @@ describe('AutofillMonitor', () => {
131131
let animationStartCallback: Function = () => {};
132132
inputEl.addEventListener.and.callFake((_, cb) => animationStartCallback = cb);
133133
autofillMonitor.monitor(inputEl);
134-
animationStartCallback({animationName: 'cdk-input-autofill-start', target: inputEl});
135-
expect(inputEl.classList).toContain('cdk-input-autofilled');
134+
animationStartCallback({animationName: 'cdk-text-field-autofill-start', target: inputEl});
135+
expect(inputEl.classList).toContain('cdk-text-field-autofilled');
136136

137137
autofillMonitor.stopMonitoring(inputEl);
138-
expect(inputEl.classlist).not.toContain('cdk-input-autofilled');
138+
expect(inputEl.classlist).not.toContain('cdk-text-field-autofilled');
139139
});
140140

141141
it('should complete the stream when monitoring is stopped', () => {
@@ -159,7 +159,7 @@ describe('cdkAutofill', () => {
159159

160160
beforeEach(() => {
161161
TestBed.configureTestingModule({
162-
imports: [InputModule],
162+
imports: [TextFieldModule],
163163
declarations: [InputWithCdkAutofilled],
164164
}).compileComponents();
165165
});

src/cdk/input/autofill.ts renamed to src/cdk/text-field/autofill.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ export class AutofillMonitor implements OnDestroy {
6969

7070
const result = new Subject<AutofillEvent>();
7171
const listener = (event: AnimationEvent) => {
72-
if (event.animationName === 'cdk-input-autofill-start') {
73-
element.classList.add('cdk-input-autofilled');
72+
if (event.animationName === 'cdk-text-field-autofill-start') {
73+
element.classList.add('cdk-text-field-autofilled');
7474
result.next({target: event.target as Element, isAutofilled: true});
75-
} else if (event.animationName === 'cdk-input-autofill-end') {
76-
element.classList.remove('cdk-input-autofilled');
75+
} else if (event.animationName === 'cdk-text-field-autofill-end') {
76+
element.classList.remove('cdk-text-field-autofilled');
7777
result.next({target: event.target as Element, isAutofilled: false});
7878
}
7979
};
8080

8181
element.addEventListener('animationstart', listener, listenerOptions);
82-
element.classList.add('cdk-input-autofill-monitored');
82+
element.classList.add('cdk-text-field-autofill-monitored');
8383

8484
this._monitoredElements.set(element, {
8585
subject: result,
@@ -101,8 +101,8 @@ export class AutofillMonitor implements OnDestroy {
101101
if (info) {
102102
info.unlisten();
103103
info.subject.complete();
104-
element.classList.remove('cdk-input-autofill-monitored');
105-
element.classList.remove('cdk-input-autofilled');
104+
element.classList.remove('cdk-text-field-autofill-monitored');
105+
element.classList.remove('cdk-text-field-autofilled');
106106
this._monitoredElements.delete(element);
107107
}
108108
}

src/cdk/input/autosize.spec.ts renamed to src/cdk/text-field/autosize.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {FormsModule} from '@angular/forms';
55
import {By} from '@angular/platform-browser';
66
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
77
import {CdkTextareaAutosize} from './autosize';
8-
import {InputModule} from './input-module';
8+
import {TextFieldModule} from './text-field-module';
99

1010

1111
describe('CdkTextareaAutosize', () => {
@@ -17,7 +17,7 @@ describe('CdkTextareaAutosize', () => {
1717
TestBed.configureTestingModule({
1818
imports: [
1919
FormsModule,
20-
InputModule,
20+
TextFieldModule,
2121
NoopAnimationsModule,
2222
],
2323
declarations: [
File renamed without changes.
File renamed without changes.

src/cdk/input/public-api.ts renamed to src/cdk/text-field/public-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
export * from './autofill';
1010
export * from './autosize';
11-
export * from './input-module';
11+
export * from './text-field-module';

src/cdk/input/input-module.ts renamed to src/cdk/text-field/text-field-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ import {CdkTextareaAutosize} from './autosize';
1818
exports: [CdkAutofill, CdkTextareaAutosize],
1919
providers: [AutofillMonitor],
2020
})
21-
export class InputModule {}
21+
export class TextFieldModule {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@import 'text-field';
2+
3+
@include cdk-text-field();

src/cdk/input/tsconfig-build.json renamed to src/cdk/text-field/tsconfig-build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"annotateForClosureCompiler": true,
88
"strictMetadataEmit": true,
99
"flatModuleOutFile": "index.js",
10-
"flatModuleId": "@angular/cdk/input",
10+
"flatModuleId": "@angular/cdk/text-field",
1111
"skipTemplateCodegen": true,
1212
"fullTemplateTypeCheck": true
1313
}

src/demo-app/demo-material-module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import {A11yModule} from '@angular/cdk/a11y';
1010
import {CdkAccordionModule} from '@angular/cdk/accordion';
1111
import {BidiModule} from '@angular/cdk/bidi';
12-
import {InputModule} from '@angular/cdk/input';
12+
import {TextFieldModule} from '@angular/cdk/text-field';
1313
import {ObserversModule} from '@angular/cdk/observers';
1414
import {OverlayModule} from '@angular/cdk/overlay';
1515
import {PlatformModule} from '@angular/cdk/platform';
@@ -98,7 +98,7 @@ import {
9898
A11yModule,
9999
BidiModule,
100100
CdkAccordionModule,
101-
InputModule,
101+
TextFieldModule,
102102
ObserversModule,
103103
OverlayModule,
104104
PlatformModule,

src/demo-app/input/input-demo.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import '../../cdk/input/input';
1+
@import '../../cdk/text-field/text-field';
22

33
.demo-basic {
44
padding: 0;
@@ -31,5 +31,5 @@
3131
}
3232

3333
.demo-custom-autofill-style {
34-
@include cdk-input-autofill-color(transparent, red);
34+
@include cdk-text-field-autofill-color(transparent, red);
3535
}

src/demo-app/system-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ System.config({
4848
'@angular/cdk/bidi': 'dist/packages/cdk/bidi/index.js',
4949
'@angular/cdk/coercion': 'dist/packages/cdk/coercion/index.js',
5050
'@angular/cdk/collections': 'dist/packages/cdk/collections/index.js',
51-
'@angular/cdk/input': 'dist/packages/cdk/input/index.js',
5251
'@angular/cdk/keycodes': 'dist/packages/cdk/keycodes/index.js',
5352
'@angular/cdk/layout': 'dist/packages/cdk/layout/index.js',
5453
'@angular/cdk/observers': 'dist/packages/cdk/observers/index.js',
@@ -58,6 +57,7 @@ System.config({
5857
'@angular/cdk/scrolling': 'dist/packages/cdk/scrolling/index.js',
5958
'@angular/cdk/stepper': 'dist/packages/cdk/stepper/index.js',
6059
'@angular/cdk/table': 'dist/packages/cdk/table/index.js',
60+
'@angular/cdk/text-field': 'dist/packages/cdk/text-field/index.js',
6161

6262
'@angular/material/autocomplete': 'dist/packages/material/autocomplete/index.js',
6363
'@angular/material/bottom-sheet': 'dist/packages/material/bottom-sheet/index.js',

src/e2e-app/system-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ System.config({
3838
'@angular/cdk/bidi': 'dist/bundles/cdk-bidi.umd.js',
3939
'@angular/cdk/coercion': 'dist/bundles/cdk-coercion.umd.js',
4040
'@angular/cdk/collections': 'dist/bundles/cdk-collections.umd.js',
41-
'@angular/cdk/input': 'dist/bundles/cdk-input.umd.js',
4241
'@angular/cdk/keycodes': 'dist/bundles/cdk-keycodes.umd.js',
4342
'@angular/cdk/layout': 'dist/bundles/cdk-layout.umd.js',
4443
'@angular/cdk/observers': 'dist/bundles/cdk-observers.umd.js',
@@ -50,6 +49,7 @@ System.config({
5049
'@angular/cdk/table': 'dist/bundles/cdk-table.umd.js',
5150
'@angular/cdk/testing': 'dist/bundles/cdk-testing.umd.js',
5251
'@angular/material-examples': 'dist/bundles/material-examples.umd.js',
52+
'@angular/cdk/text-field': 'dist/bundles/cdk-text-field.umd.js',
5353

5454
'@angular/material/autocomplete': 'dist/bundles/material-autocomplete.umd.js',
5555
'@angular/material/bottom-sheet': 'dist/bundles/material-bottom-sheet.umd.js',

0 commit comments

Comments
 (0)