Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
fix(checkbox): Ensure ripple is activated on keydown (#241)
Browse files Browse the repository at this point in the history
Fixes an issue where the ripple was not activated on keyDown within the
checkbox component.
  • Loading branch information
traviskaufman authored Feb 3, 2017
1 parent db6a6db commit b661dae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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

0 comments on commit b661dae

Please sign in to comment.