Skip to content

Commit 0b04860

Browse files
Enumerate draggable attribute (preactjs#288)
* Enumerate draggable attribute * Restore cross-env changes * Restore package.json * Create .changeset/fifty-hounds-press.md --------- Co-authored-by: Jovi De Croock <[email protected]>
1 parent a0546fe commit 0b04860

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

.changeset/fifty-hounds-press.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+
Enumerate draggable attribute, so the output isn't `draggable` but `draggable="true"`

src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,13 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
311311
name = name.toLowerCase().replace(XLINK_REPLACE_REGEX, 'xlink:');
312312
} else if (UNSAFE_NAME.test(name)) {
313313
continue;
314-
} else if (name[0] === 'a' && name[1] === 'r' && v != null) {
315-
// serialize boolean aria-xyz attribute values as strings
314+
} else if (
315+
((name[0] === 'a' && name[1] === 'r') || name === 'draggable') &&
316+
v != null
317+
) {
318+
// serialize boolean aria-xyz or draggable attribute values as strings
319+
// `draggable` is an enumerated attribute and not Boolean. A value of `true` or `false` is mandatory
320+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/draggable
316321
v += '';
317322
}
318323
}

test/render.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ describe('render', () => {
135135
expect(rendered).to.equal(expected);
136136
});
137137

138+
it('should include boolean draggable attribute', () => {
139+
let rendered = render(<div draggable />),
140+
expected = `<div draggable="true"></div>`;
141+
142+
expect(rendered).to.equal(expected);
143+
});
144+
138145
describe('attribute name sanitization', () => {
139146
it('should omit attributes with invalid names', () => {
140147
let rendered = render(

0 commit comments

Comments
 (0)