Skip to content

Commit ddf1bbb

Browse files
authored
Merge pull request #393 from preactjs/fix/spellcheck-prop-serialization
fix: `spellcheck` prop
2 parents d20ad14 + 6255591 commit ddf1bbb

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

.changeset/angry-chairs-marry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'preact-render-to-string': patch
3+
---
4+
5+
Fix `spellcheck={false}` not rendering as `spellcheck="false"`

package-lock.json

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
UNSAFE_NAME,
55
NAMESPACE_REPLACE_REGEX,
66
HTML_LOWER_CASE,
7+
HTML_ENUMERATED,
78
SVG_CAMEL_CASE,
89
createComponent
910
} from './lib/util.js';
@@ -623,10 +624,11 @@ function _renderToString(
623624
name = name.replace(NAMESPACE_REPLACE_REGEX, '$1:$2').toLowerCase();
624625
} else if (UNSAFE_NAME.test(name)) {
625626
continue;
626-
} else if ((name[4] === '-' || name === 'draggable') && v != null) {
627-
// serialize boolean aria-xyz or draggable attribute values as strings
628-
// `draggable` is an enumerated attribute and not Boolean. A value of `true` or `false` is mandatory
629-
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/draggable
627+
} else if (
628+
(name[4] === '-' || HTML_ENUMERATED.has(name)) &&
629+
v != null
630+
) {
631+
// serialize boolean aria-xyz or enumerated attribute values as strings
630632
v = v + EMPTY_STR;
631633
} else if (isSvgMode) {
632634
if (SVG_CAMEL_CASE.test(name)) {
@@ -637,9 +639,6 @@ function _renderToString(
637639
}
638640
} else if (HTML_LOWER_CASE.test(name)) {
639641
name = name.toLowerCase();
640-
if (name === 'spellcheck') {
641-
v = '' + v;
642-
}
643642
}
644643
}
645644
}

src/lib/util.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
export const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
22
export const UNSAFE_NAME = /[\s\n\\/='"\0<>]/;
33
export const NAMESPACE_REPLACE_REGEX = /^(xlink|xmlns|xml)([A-Z])/;
4-
export const HTML_LOWER_CASE = /^accessK|^auto[A-Z]|^cell|^ch|^col|cont|cross|dateT|encT|form[A-Z]|frame|hrefL|inputM|maxL|minL|noV|playsI|popoverT|readO|rowS|spellC|src[A-Z]|tabI|useM|item[A-Z]/;
5-
export const SVG_CAMEL_CASE = /^ac|^ali|arabic|basel|cap|clipPath$|clipRule$|color|dominant|enable|fill|flood|font|glyph[^R]|horiz|image|letter|lighting|marker[^WUH]|overline|panose|pointe|paint|rendering|shape|stop|strikethrough|stroke|spel|text[^L]|transform|underline|unicode|units|^v[^i]|^w|^xH/;
4+
export const HTML_LOWER_CASE = /^accessK|^auto[A-Z]|^cell|^ch|^col|cont|cross|dateT|encT|form[A-Z]|frame|hrefL|inputM|maxL|minL|noV|playsI|popoverT|readO|rowS|src[A-Z]|tabI|useM|item[A-Z]/;
5+
export const SVG_CAMEL_CASE = /^ac|^ali|arabic|basel|cap|clipPath$|clipRule$|color|dominant|enable|fill|flood|font|glyph[^R]|horiz|image|letter|lighting|marker[^WUH]|overline|panose|pointe|paint|rendering|shape|stop|strikethrough|stroke|text[^L]|transform|underline|unicode|units|^v[^i]|^w|^xH/;
6+
7+
// Boolean DOM properties that translate to enumerated ('true'/'false') attributes
8+
export const HTML_ENUMERATED = new Set(['draggable', 'spellcheck']);
69

710
// DOM properties that should NOT have "px" added when numeric
811
const ENCODED_ENTITIES = /["&<]/;

test/render.test.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ describe('render', () => {
154154
expect(rendered).to.equal(`<div data-checked="false"></div>`);
155155
});
156156

157-
it('should support spellCheck', () => {
158-
let rendered = render(<div spellCheck={false} />);
157+
it('should support spellcheck', () => {
158+
let rendered = render(<div spellcheck={false} />);
159159
expect(rendered).to.equal(`<div spellcheck="false"></div>`);
160160

161-
rendered = render(<div spellCheck />);
161+
rendered = render(<div spellcheck />);
162162
expect(rendered).to.equal(`<div spellcheck="true"></div>`);
163163
});
164164

test/utils.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ export const htmlAttributes = {
400400
slot: 'slot',
401401
span: 'span',
402402
spellcheck: 'spellcheck',
403-
spellCheck: 'spellcheck',
404403
src: 'src',
405404
srcset: 'srcset',
406405
srcDoc: 'srcdoc',

0 commit comments

Comments
 (0)