Skip to content

Commit 097529f

Browse files
authored
fix(checkbox): make checkboxes non-editable (#184)
1 parent 321109e commit 097529f

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
14

src/transform/plugins/checkbox/checkbox.ts

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const checkboxReplace = function (_md: MarkdownIt, opts: CheckboxOptions)
4848
token.attrs = [
4949
['type', 'checkbox'],
5050
['id', id],
51+
['disabled', ''],
5152
];
5253
if (checked === true) {
5354
token.attrs.push(['checked', 'true']);

test/checkbox.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('markdown-it-checkbox', function () {
2929
assert.equal(
3030
res,
3131
'<div class="checkbox">\n' +
32-
'<input type="checkbox" id="checkbox0" checked="true">\n' +
32+
'<input type="checkbox" id="checkbox0" disabled="" checked="true">\n' +
3333
'<label for="checkbox0">test written</label>\n' +
3434
'</div>\n',
3535
);
@@ -44,7 +44,7 @@ describe('markdown-it-checkbox', function () {
4444
assert.equal(
4545
res,
4646
'<div class="cb">\n' +
47-
'<input type="checkbox" id="checkbox0" checked="true">\n' +
47+
'<input type="checkbox" id="checkbox0" disabled="" checked="true">\n' +
4848
'<label for="checkbox0">test written</label>\n' +
4949
'</div>\n',
5050
);
@@ -59,7 +59,7 @@ describe('markdown-it-checkbox', function () {
5959
assert.equal(
6060
res,
6161
'<div class="checkbox">\n' +
62-
'<input type="checkbox" id="cb0" checked="true">\n' +
62+
'<input type="checkbox" id="cb0" disabled="" checked="true">\n' +
6363
'<label for="cb0">test written</label>\n' +
6464
'</div>\n',
6565
);

test/data/checkbox/checkbox.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[ ] unchecked
33
.
44
<div class="checkbox">
5-
<input type="checkbox" id="checkbox0">
5+
<input type="checkbox" id="checkbox0" disabled="">
66
<label for="checkbox0">unchecked</label>
77
</div>
88
.
@@ -11,7 +11,7 @@
1111
[_] unchecked
1212
.
1313
<div class="checkbox">
14-
<input type="checkbox" id="checkbox1">
14+
<input type="checkbox" id="checkbox1" disabled="">
1515
<label for="checkbox1">unchecked</label>
1616
</div>
1717
.
@@ -20,7 +20,7 @@
2020
[x] checked
2121
.
2222
<div class="checkbox">
23-
<input type="checkbox" id="checkbox2" checked="true">
23+
<input type="checkbox" id="checkbox2" disabled="" checked="true">
2424
<label for="checkbox2">checked</label>
2525
</div>
2626
.
@@ -29,7 +29,7 @@
2929
[X] checked
3030
.
3131
<div class="checkbox">
32-
<input type="checkbox" id="checkbox3" checked="true">
32+
<input type="checkbox" id="checkbox3" disabled="" checked="true">
3333
<label for="checkbox3">checked</label>
3434
</div>
3535
.
@@ -41,13 +41,13 @@
4141
<ul>
4242
<li>
4343
<div class="checkbox">
44-
<input type="checkbox" id="checkbox4">
44+
<input type="checkbox" id="checkbox4" disabled="">
4545
<label for="checkbox4">unchecked</label>
4646
</div>
4747
</li>
4848
<li>
4949
<div class="checkbox">
50-
<input type="checkbox" id="checkbox5" checked="true">
50+
<input type="checkbox" id="checkbox5" disabled="" checked="true">
5151
<label for="checkbox5">checked</label>
5252
</div>
5353
</li>

0 commit comments

Comments
 (0)