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(select): Convert JS to TypeScript #4386

Merged
merged 20 commits into from
Feb 13, 2019
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9313e66
feat(select): Convert JS to TypeScript
acdvorak Feb 9, 2019
135e09d
WIP: Add comment
acdvorak Feb 9, 2019
bc8bf0d
WIP: Fix compiler errors
acdvorak Feb 9, 2019
fb0b996
WIP: Make Istanbul happy
acdvorak Feb 9, 2019
7a7d960
Merge branch 'feat/typescript--select' of github.com:material-compone…
acdvorak Feb 9, 2019
91f5975
WIP: Change `MDCList.listElements` from `HTMLElement[]` back to `Elem…
acdvorak Feb 11, 2019
b50a47a
WIP: `extends CustomEvent<MenuItemEventDetail>`
acdvorak Feb 11, 2019
01edf0f
WIP: Remove Closure annotations
acdvorak Feb 11, 2019
a286663
WIP: Initialize `savedTabIndex_` inline
acdvorak Feb 11, 2019
5facf07
WIP: Remove unnecessary `@material/textfield` dependency from `packag…
acdvorak Feb 11, 2019
7b625f6
Merge remote-tracking branch 'origin/feat/typescript' into feat/types…
acdvorak Feb 11, 2019
f6de964
Merge remote-tracking branch 'origin/feat/typescript' into feat/types…
acdvorak Feb 11, 2019
4fa0e79
WIP: Update filename to `.ts` in `js-bundle-factory.js`
acdvorak Feb 11, 2019
dc34eb6
Merge remote-tracking branch 'origin/feat/typescript' into feat/types…
acdvorak Feb 12, 2019
de38dd6
WIP: Revert argument rename in `MDCComponent.emit()`
acdvorak Feb 12, 2019
01b22be
WIP: Address review comments
acdvorak Feb 12, 2019
ebbbbb9
WIP: Re-indent
acdvorak Feb 12, 2019
a236050
WIP: Address review comments
acdvorak Feb 12, 2019
1e8b7e2
WIP: Throw an error if required subelements are missing
acdvorak Feb 12, 2019
a0cce8c
WIP: Fix `TouchEvent` `clientX` bug
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: 5 additions & 1 deletion packages/mdc-select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,14 @@ class MDCSelect extends MDCComponent<MDCSelectFoundation> implements RippleCapab
*/
private getNormalizedXCoordinate_(evt: MouseEvent | TouchEvent): number {
const targetClientRect = (evt.target as Element).getBoundingClientRect();
const xCoordinate = (evt as MouseEvent).clientX; // TODO(acdvorak): How does this work for TouchEvent?
const xCoordinate = this.isTouchEvent_(evt) ? evt.touches[0].clientX : evt.clientX;
return xCoordinate - targetClientRect.left;
}

private isTouchEvent_(evt: MouseEvent | TouchEvent): evt is TouchEvent {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we changed this to just getXCoordinateFromEvent? Then we just encapsulate this this.isTouchEvent_(evt) ? evt.touches[0].clientX : evt.clientX; logic...cause we still end up having to cast it anyways inside this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, it would need to look like this:

  private getNormalizedXCoordinate_(evt: MouseEvent | TouchEvent): number {
    const targetClientRect = (evt.target as Element).getBoundingClientRect();
    return this.getClientXFromEvent_(evt) - targetClientRect.left;
  }

  private getClientXFromEvent_(evt: MouseEvent | TouchEvent): number {
    const touchEvt = evt as TouchEvent;
    const mouseEvt = evt as MouseEvent;
    if (touchEvt.touches) {
      return touchEvt.touches[0].clientX;
    }
    return mouseEvt.clientX;
  }

Matt and I prefer the isTouchEvent_() style, so we're going to leave it as-is.

return Boolean((evt as TouchEvent).touches);
}

/**
* Returns a map of all subcomponents to subfoundations.
*/
Expand Down