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(checkbox): Ensure ripple is activated on keydown #241

Merged
merged 3 commits into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
3 changes: 3 additions & 0 deletions packages/mdc-checkbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import {MDCComponent} from '@material/base';
import {MDCRipple, MDCRippleFoundation} from '@material/ripple';
import {getMatchesProperty} from '@material/ripple/util';
import {getCorrectEventName} from '@material/animation';

import MDCCheckboxFoundation from './foundation';
Expand All @@ -38,8 +39,10 @@ export class MDCCheckbox extends MDCComponent {
}

initRipple_() {
const MATCHES = getMatchesProperty(HTMLElement.prototype);
const adapter = Object.assign(MDCRipple.createAdapter(this), {
isUnbounded: () => true,
isSurfaceActive: () => this.nativeCb_[MATCHES](':active'),
registerInteractionHandler: (type, handler) => this.nativeCb_.addEventListener(type, handler),
deregisterInteractionHandler: (type, handler) => this.nativeCb_.removeEventListener(type, handler),
computeBoundingRect: () => {
Expand Down
21 changes: 21 additions & 0 deletions test/unit/mdc-checkbox/mdc-checkbox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {createMockRaf} from '../helpers/raf';
import {MDCCheckbox} from '../../../packages/mdc-checkbox';
import {strings} from '../../../packages/mdc-checkbox/constants';
import {getCorrectEventName} from '../../../packages/mdc-animation';
import {getMatchesProperty} from '../../../packages/mdc-ripple/util';

function getFixture() {
return bel`
Expand Down Expand Up @@ -71,6 +72,26 @@ if (supportsCssVariables(window)) {
component.destroy();
raf.flush();
t.false(root.classList.contains('mdc-ripple-upgraded'));
raf.restore();
t.end();
});

test('(regression) activates ripple on keydown when the input element surface is active', (t) => {
const raf = createMockRaf();
const {root} = setupTest();
const input = root.querySelector('input');
raf.flush();

const fakeMatches = td.func('.matches');
td.when(fakeMatches(':active')).thenReturn(true);
input[getMatchesProperty(HTMLElement.prototype)] = fakeMatches;

t.true(root.classList.contains('mdc-ripple-upgraded'));
domEvents.emit(input, 'keydown');
raf.flush();

t.true(root.classList.contains('mdc-ripple-upgraded--background-active'));
raf.restore();
t.end();
});
}
Expand Down