Skip to content

Commit

Permalink
Merge pull request #1110 from marvinhagemeister/spellcheck
Browse files Browse the repository at this point in the history
Fix spellcheck attr not set to false
  • Loading branch information
developit committed May 25, 2018
2 parents 7e49a91 + 836c99d commit 534eb8f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/dom/index.js
Expand Up @@ -81,10 +81,13 @@ export function setAccessor(node, name, old, value, isSvg) {
}
else if (name!=='list' && name!=='type' && !isSvg && name in node) {
setProperty(node, name, value==null ? '' : value);
if (value==null || value===false) node.removeAttribute(name);
if ((value==null || value===false) && name!='spellcheck') node.removeAttribute(name);
}
else {
let ns = isSvg && (name !== (name = name.replace(/^xlink:?/, '')));
// spellcheck is treated differently than all other boolean values and
// should not be removed when the value is `false`. See:
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-spellcheck
if (value==null || value===false) {
if (ns) node.removeAttributeNS('http://www.w3.org/1999/xlink', name.toLowerCase());
else node.removeAttribute(name);
Expand Down
2 changes: 1 addition & 1 deletion src/preact.d.ts
Expand Up @@ -690,7 +690,7 @@ declare global {
sizes?: string;
slot?: string;
span?: number;
spellCheck?: boolean;
spellcheck?: boolean;
src?: string;
srcset?: string;
srcDoc?: string;
Expand Down
6 changes: 6 additions & 0 deletions test/browser/components.js
Expand Up @@ -151,6 +151,12 @@ describe('Components', () => {
expect(scratch.innerHTML).to.equal('');
});

// Test for #651
it('should set enumerable boolean attribute', () => {
render(<input spellcheck={false} />, scratch);
expect(scratch.firstChild.spellcheck).to.equal(false);
});

// Test for Issue #73
it('should remove orphaned elements replaced by Components', () => {
class Comp extends Component {
Expand Down

0 comments on commit 534eb8f

Please sign in to comment.