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

fix(ripple): Use mdc-dom.matches instead of getMatchesProperty() #706

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 4 additions & 15 deletions packages/ripple/index.tsx
Expand Up @@ -25,9 +25,8 @@ import {Subtract} from 'utility-types'; // eslint-disable-line no-unused-vars

// @ts-ignore no mdc .d.ts file
import {MDCRippleFoundation, MDCRippleAdapter, util} from '@material/ripple/dist/mdc.ripple';

const HTMLElementShim: any = typeof HTMLElement === 'undefined' ? {} : HTMLElement;
const MATCHES = util.getMatchesProperty(HTMLElementShim.prototype);
// @ts-ignore no mdc .d.ts file
import {matches} from '@material/dom/ponyfill';

export interface RippledComponentProps<T> {
unbounded?: boolean;
Expand Down Expand Up @@ -55,10 +54,6 @@ export interface InjectedProps<S, A = Element> extends RippledComponentProps<S>
initRipple: React.Ref<S> | ((surface: S | null, activator?: A | null) => void);
}

function isElement(element: any): element is Element {
return element[MATCHES as 'matches'] !== undefined;
}

type ActivateEventTypes<S>
= React.MouseEvent<S> | React.TouchEvent<S> | React.KeyboardEvent<S> | React.FocusEvent<S>;

Expand Down Expand Up @@ -158,16 +153,10 @@ export function withRipple <
isUnbounded: () => this.props.unbounded,
isSurfaceActive: () => {
if (activator) {
if (isElement(activator)) {
return activator[MATCHES as 'matches'](':active');
}
return false;
return matches(activator, ':active');
}

if (isElement(surface)) {
return surface[MATCHES as 'matches'](':active');
}
return false;
return matches(surface, ':active');
},
isSurfaceDisabled: () => this.props.disabled,
addClass: (className: string) => {
Expand Down
1 change: 1 addition & 0 deletions packages/ripple/package.json
Expand Up @@ -16,6 +16,7 @@
"url": "https://github.com/material-components/material-components-web-react.git"
},
"dependencies": {
"@material/dom": "^0.41.0",
"@material/ripple": "^0.41.0",
"classnames": "^2.2.5",
"react": "^16.4.2",
Expand Down
12 changes: 4 additions & 8 deletions packages/tab-scroller/index.tsx
Expand Up @@ -27,6 +27,8 @@ import {
util,
// @ts-ignore no .d.ts file
} from '@material/tab-scroller/dist/mdc.tabScroller';
// @ts-ignore no mdc .d.ts file
import {matches} from '@material/dom/ponyfill';

const convertDashToCamelCase = (propName: string) =>
propName.replace(/-(\w)/g, (_, v) => v.toUpperCase());
Expand All @@ -47,12 +49,6 @@ interface TabScrollerState {

type ScrollerElementNames = 'scrollAreaStyleProperty' | 'scrollContentStyleProperty';

const MATCHES = util.getMatchesProperty(HTMLElement.prototype);

function isElement(element: any): element is Element {
return element[MATCHES as 'matches'] !== undefined;
}

export default class TabScroller extends React.Component<
TabScrollerProps,
TabScrollerState
Expand Down Expand Up @@ -120,8 +116,8 @@ export default class TabScroller extends React.Component<
get adapter() {
return {
eventTargetMatchesSelector: (evtTarget: HTMLDivElement, selector: string) => {
if (selector && isElement(evtTarget)) {
return evtTarget[MATCHES as 'matches'](selector);
if (selector) {
return matches(evtTarget, selector);
}
return false;
},
Expand Down
1 change: 1 addition & 0 deletions packages/tab-scroller/package.json
Expand Up @@ -18,6 +18,7 @@
"url": "https://github.com/material-components/material-components-web-react.git"
},
"dependencies": {
"@material/dom": "^0.41.0",
"@material/tab-scroller": "^0.41.0",
"classnames": "^2.2.5",
"react": "^16.4.2"
Expand Down