dom-element-is-natively-editable
Advanced tools
Comparing version 1.0.1 to 1.0.2
21
index.js
@@ -11,3 +11,3 @@ module.exports = function (element) { | ||
case 'input': | ||
return true | ||
return isEditableInput(element) | ||
case 'textarea': | ||
@@ -40,1 +40,20 @@ return true | ||
} | ||
function isEditableInput (input) { | ||
switch (input.type) { | ||
case 'text': | ||
return true | ||
case 'email': | ||
return true | ||
case 'password': | ||
return true | ||
case 'search': | ||
return true | ||
case 'tel': | ||
return true | ||
case 'url': | ||
return true | ||
default: | ||
return false | ||
} | ||
} |
{ | ||
"name": "dom-element-is-natively-editable", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Returns true if the provided DOM element is supposed to be natively editable", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -83,12 +83,30 @@ /* eslint-env mocha */ | ||
context('provided an `input` element', () => { | ||
it('sync returns true', (done) => { | ||
jsdom.env('<input>input</input>', (err, {document}) => { | ||
if (err) { | ||
return | ||
} | ||
const element = document.querySelector('input') | ||
isEditable(element).should.be.true | ||
done() | ||
// this list of types is kind of a guess based on: | ||
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input | ||
;['text', 'email', 'password', 'search', 'tel', 'url'].forEach((type) => { | ||
context(`that is of type \`${type}\``, () => { | ||
it('sync returns true', (done) => { | ||
jsdom.env(`<input type="${type}">${type} input</input>`, (err, {document}) => { | ||
if (err) { | ||
return | ||
} | ||
const element = document.querySelector('input') | ||
isEditable(element).should.be.true | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
context('that is not of an editable type (`radio`)', () => { | ||
it('sync returns false', (done) => { | ||
jsdom.env('<input type="radio">radio input</input>', (err, {document}) => { | ||
if (err) { | ||
return | ||
} | ||
const element = document.querySelector('input') | ||
isEditable(element).should.be.false | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -95,0 +113,0 @@ context('provided a `textarea` element', () => { |
8584
187