Skip to content

Commit

Permalink
WIP: Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
acdvorak committed Feb 12, 2019
1 parent d3ee22d commit 44f2987
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/mdc-textfield/icon/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
*/

import {MDCFoundation} from '@material/base/foundation';
import {EventType} from '@material/base/index';
import {SpecificEventListener} from '@material/base/types';
import {MDCTextFieldIconAdapter} from './adapter';
import {strings} from './constants';

const CLICK_KEYDOWN_EVENTS: EventType[] = ['click', 'keydown'];
type InteractionEventType = 'click' | 'keydown';

const INTERACTION_EVENTS: InteractionEventType[] = ['click', 'keydown'];

class MDCTextFieldIconFoundation extends MDCFoundation<MDCTextFieldIconAdapter> {
static get strings() {
Expand All @@ -51,7 +53,7 @@ class MDCTextFieldIconFoundation extends MDCFoundation<MDCTextFieldIconAdapter>
}

private savedTabIndex_: string | null;
private readonly interactionHandler_: EventListener;
private readonly interactionHandler_: SpecificEventListener<InteractionEventType>;

constructor(adapter?: Partial<MDCTextFieldIconAdapter>) {
super({...MDCTextFieldIconFoundation.defaultAdapter, ...adapter});
Expand All @@ -63,13 +65,13 @@ class MDCTextFieldIconFoundation extends MDCFoundation<MDCTextFieldIconAdapter>
init() {
this.savedTabIndex_ = this.adapter_.getAttr('tabindex');

CLICK_KEYDOWN_EVENTS.forEach((evtType) => {
INTERACTION_EVENTS.forEach((evtType) => {
this.adapter_.registerInteractionHandler(evtType, this.interactionHandler_);
});
}

destroy() {
CLICK_KEYDOWN_EVENTS.forEach((evtType) => {
INTERACTION_EVENTS.forEach((evtType) => {
this.adapter_.deregisterInteractionHandler(evtType, this.interactionHandler_);
});
}
Expand All @@ -96,7 +98,7 @@ class MDCTextFieldIconFoundation extends MDCFoundation<MDCTextFieldIconAdapter>
this.adapter_.setContent(content);
}

handleInteraction(evt: Event) {
handleInteraction(evt: MouseEvent | KeyboardEvent) {
const isEnterKey = (evt as KeyboardEvent).key === 'Enter' || (evt as KeyboardEvent).keyCode === 13;
if (evt.type === 'click' || isEnterKey) {
this.adapter_.notifyIconAction();
Expand Down

0 comments on commit 44f2987

Please sign in to comment.