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 spellcheck attr not set to false #1110

Merged
merged 1 commit into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/dom/index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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