Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(list): fix converted space when target is content editable.
Browse files Browse the repository at this point in the history
As this is a feature which is depending on the browsers behaviour, we need to dispatch native events to the editable element, otherwise the test won't fail when the `editableContent` check is removed.

Fixes #5406

  Closes #7161
  • Loading branch information
devversion authored and ThomasBurleson committed Feb 26, 2016
1 parent a517eac commit 5d596a4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {

if (!hasClick && !proxies.length) {
firstChild && firstChild.addEventListener('keypress', function(e) {
if (e.target.nodeName != 'INPUT' && e.target.nodeName != 'TEXTAREA') {
if (e.target.nodeName != 'INPUT' && e.target.nodeName != 'TEXTAREA' && !e.target.isContentEditable) {
var keyCode = e.which || e.keyCode;
if (keyCode == $mdConstant.KEY_CODE.SPACE) {
if (firstChild) {
Expand Down
24 changes: 24 additions & 0 deletions src/components/list/list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ describe('mdListItem directive', function() {
expect($rootScope.modelVal).toBeFalsy();
}));

it('should not convert spacebar keypress for editable elements', inject(function($mdConstant) {
var listItem = setup('<md-list-item><div contenteditable="true"></div></md-list-item>');
var editableEl = listItem.find('div');
var onClickSpy = jasmine.createSpy('onClickSpy');

// We need to append our element to the DOM because the browser won't detect `contentEditable` when the element
// is hidden in the DOM. See the related issue for chromium:
// https://code.google.com/p/chromium/issues/detail?id=313082
document.body.appendChild(listItem[0]);

editableEl.on('click', onClickSpy);

// We need to dispatch the keypress natively, because otherwise the `keypress` won't be triggered in the list.
var event = document.createEvent('Event');
event.keyCode = $mdConstant.KEY_CODE.SPACE;
event.initEvent('keypress', true, true);

editableEl[0].dispatchEvent(event);

expect(onClickSpy).not.toHaveBeenCalled();

document.body.removeChild(listItem[0]);
}));

xit('should not convert spacebar keypress for text inputs', inject(function($mdConstant) {

var listItem = setup('<md-list-item><input ng-keypress="pressed = true" type="text"></md-list-item>');
Expand Down

0 comments on commit 5d596a4

Please sign in to comment.