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(text-field): Convert JS to TypeScript #4377

Merged
merged 37 commits into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f81a1dd
feat(text-field): Convert JS to TypeScript
acdvorak Feb 8, 2019
63985d2
WIP: Iterate
acdvorak Feb 8, 2019
7e06a00
WIP: Iterate
acdvorak Feb 8, 2019
c4e80b8
WIP: Iterate
acdvorak Feb 8, 2019
ab534b0
Merge remote-tracking branch 'origin/feat/typescript' into feat/types…
acdvorak Feb 8, 2019
fb56327
WIP: Add missing imports
acdvorak Feb 8, 2019
4f49d42
WIP: Address review feedback
acdvorak Feb 8, 2019
edbe19d
WIP: Fix type errors
acdvorak Feb 8, 2019
cb8620a
WIP: Style
acdvorak Feb 8, 2019
3e01b8c
WIP: Fix remaining unit test failures
acdvorak Feb 8, 2019
c390b61
WIP: FIx linter errors
acdvorak Feb 8, 2019
3bcff48
WIP: Mark private fields as nullable
acdvorak Feb 8, 2019
4d657d7
WIP: Remove unnecessary `querySelector()` calls and non-nullable `!` …
acdvorak Feb 8, 2019
5af3c64
WIP: Remove unnecessary types
acdvorak Feb 8, 2019
f30a1d7
WIP: Increase foundation unit test coverage to 99%
acdvorak Feb 8, 2019
fb19eba
WIP: Add missing `private` visibility modifiers
acdvorak Feb 9, 2019
d3a4efa
WIP: Increase unit test coverage to 99%
acdvorak Feb 9, 2019
1c12f8f
WIP: Style
acdvorak Feb 9, 2019
9fa0cc4
WIP: Fix broken sub-component integration and screenshot test for cha…
acdvorak Feb 9, 2019
5a07c74
WIP: Temporarily debug failing unit test in IE 11
acdvorak Feb 9, 2019
c3a4977
WIP: Fix failing unit test in IE 11?
acdvorak Feb 9, 2019
059e1a5
WIP: Fix IE 11?
acdvorak Feb 9, 2019
b6b68a6
WIP: Fix IE 11?
acdvorak Feb 9, 2019
8abd45a
WIP: Fix IE 11!
acdvorak Feb 9, 2019
fbf3ad3
WIP: Make Istanbul happy
acdvorak Feb 9, 2019
8e34f91
Merge remote-tracking branch 'origin/feat/typescript' into feat/types…
acdvorak Feb 11, 2019
d3ee22d
WIP: Address review comments
acdvorak Feb 12, 2019
44f2987
WIP: Address review comments
acdvorak Feb 12, 2019
1c78cf6
Merge remote-tracking branch 'origin/feat/typescript' into feat/types…
acdvorak Feb 12, 2019
2bc7221
WIP: Import from specific `.ts` files instead of `/index`
acdvorak Feb 12, 2019
b676433
WIP: Use `Pick<HTMLInputElement>` instead of a hard-coded interface def
acdvorak Feb 12, 2019
730164d
WIP: Update comments
acdvorak Feb 12, 2019
1d88400
Merge remote-tracking branch 'origin/feat/typescript' into feat/types…
acdvorak Feb 12, 2019
530c4c6
WIP: Address review comments
acdvorak Feb 12, 2019
be64af2
WIP: Wrap `setContent()` expressions in `{}` to ensure `void` return …
acdvorak Feb 12, 2019
c405d56
WIP: Address review comments
acdvorak Feb 12, 2019
03f0022
WIP: Address review comments
acdvorak Feb 12, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/mdc-textfield/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,17 @@ Method Signature | Description
`deregisterTextFieldInteractionHandler(evtType: string, handler: EventListener) => void` | Deregisters an event handler on the root element for a given event.
`registerInputInteractionHandler(evtType: string, handler: EventListener) => void` | Registers an event listener on the native input element for a given event.
`deregisterInputInteractionHandler(evtType: string, handler: EventListener) => void` | Deregisters an event listener on the native input element for a given event.
`registerValidationAttributeChangeHandler(handler: function(!Array<string>) => undefined) => !MutationObserver` | Registers a validation attribute change listener on the input element. Handler accepts list of attribute changes.
`registerValidationAttributeChangeHandler(handler: (attributeNames: string[]) => void) => MutationObserver` | Registers a validation attribute change listener on the input element. Handler accepts list of attribute changes.
`deregisterValidationAttributeChangeHandler(!MutationObserver) => void` | Disconnects a validation attribute observer on the input element.
`getNativeInput() => {value: string, disabled: boolean, badInput: boolean, checkValidity: () => boolean}?` | Returns an object representing the native text input element, with a similar API shape.
`getNativeInput() => NativeInputType \| null` | Returns an object representing the native text input element, with a similar API shape. See [types.ts](types.ts).
`isFocused() => boolean` | Returns whether the input is focused.
`hasOutline() => boolean` | Returns whether there is an outline element.
`notchOutline(labelWidth: number) => void` | Updates the notched outline path to open the notch and update the notch width for the label element.
`closeOutline() => void` | Closes the notch in the notched outline element.

#### `MDCTextFieldAdapter.getNativeInput()`

Returns an object representing the native text input element, with a similar API shape. The object returned should include the `value`, `disabled` and `badInput` properties, as well as the `checkValidity()` function. We _never_ alter the value within our code, however we _do_ update the disabled property, so if you choose to duck-type the return value for this method in your implementation it's important to keep this in mind. Also note that this method can return null, which the foundation will handle gracefully.
Returns an object representing the native text input element, with a similar API shape. We _never_ alter the value within our code, however we _do_ update the disabled property, so if you choose to duck-type the return value for this method in your implementation it's important to keep this in mind. Also note that this method can return null, which the foundation will handle gracefully.

#### `MDCTextFieldAdapter.getIdleOutlineStyleValue(propertyName: string)`

Expand Down
208 changes: 0 additions & 208 deletions packages/mdc-textfield/adapter.js

This file was deleted.

147 changes: 147 additions & 0 deletions packages/mdc-textfield/adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/**
* @license
* Copyright 2017 Google Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

import {EventType, SpecificEventListener} from '@material/base/types';
import {NativeInputElement} from './types';

/**
* Defines the shape of the adapter expected by the foundation.
* Implement this adapter for your framework of choice to delegate updates to
* the component in your framework of choice. See architecture documentation
* for more details.
* https://github.com/material-components/material-components-web/blob/master/docs/code/architecture.md
*/
interface MDCTextFieldAdapter {
/**
* Adds a class to the root Element.
*/
addClass(className: string): void;

/**
* Removes a class from the root Element.
*/
removeClass(className: string): void;

/**
* @return true if the root element contains the given class name.
*/
hasClass(className: string): boolean;

/**
* Registers an event handler on the root element for a given event.
*/
registerTextFieldInteractionHandler<E extends EventType>(evtType: E, handler: SpecificEventListener<E>): void;

/**
* Deregisters an event handler on the root element for a given event.
*/
deregisterTextFieldInteractionHandler<E extends EventType>(evtType: E, handler: SpecificEventListener<E>): void;

/**
* Registers an event listener on the native input element for a given event.
*/
registerInputInteractionHandler<E extends EventType>(evtType: E, handler: SpecificEventListener<E>): void;

/**
* Deregisters an event listener on the native input element for a given event.
*/
deregisterInputInteractionHandler<E extends EventType>(evtType: E, handler: SpecificEventListener<E>): void;

/**
* Registers a validation attribute change listener on the input element.
* Handler accepts list of attribute names.
*/
registerValidationAttributeChangeHandler(handler: (attributeNames: string[]) => void): MutationObserver;

/**
* Disconnects a validation attribute observer on the input element.
*/
deregisterValidationAttributeChangeHandler(observer: MutationObserver): void;

/**
* @return The native `<input>` element, or an object with the same shape.
* Note that this method can return null, which the foundation will handle gracefully.
*/
getNativeInput(): NativeInputElement | null;

/**
* @return true if the textfield is focused. We achieve this via `document.activeElement === this.root_`.
*/
isFocused(): boolean;

/**
* Activates the line ripple.
*/
activateLineRipple(): void;

/**
* Deactivates the line ripple.
*/
deactivateLineRipple(): void;

/**
* Sets the transform origin of the line ripple.
*/
setLineRippleTransformOrigin(normalizedX: number): void;

/**
* Only implement if label exists.
* Shakes label if shouldShake is true.
*/
shakeLabel(shouldShake: boolean): void;

/**
* Only implement if label exists.
* Floats the label above the input element if shouldFloat is true.
*/
floatLabel(shouldFloat: boolean): void;

/**
* @return true if label element exists, false if it doesn't.
*/
hasLabel(): boolean;

/**
* Only implement if label exists.
* @return width of label in pixels.
*/
getLabelWidth(): number;

/**
* @return true if outline element exists, false if it doesn't.
*/
hasOutline(): boolean;

/**
* Only implement if outline element exists.
*/
notchOutline(labelWidth: number): void;

/**
* Only implement if outline element exists.
* Closes notch in outline element.
*/
closeOutline(): void;
}

export {MDCTextFieldAdapter as default, MDCTextFieldAdapter};
Loading