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: fix checkbox not work as expected in html module. #700

Merged
merged 9 commits into from
Feb 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ class HTMLTodoListNodeParser extends HTMLNodeParser {
}) {
final delta = node.delta ?? Delta();
final domNodes = deltaHTMLEncoder.convert(delta);

final elementNode = dom.Element.html('<input type="checkbox" />');
elementNode.attributes['checked'] =
node.attributes[TodoListBlockKeys.checked].toString();
domNodes.add(elementNode);
if (node.attributes[TodoListBlockKeys.checked] as bool? ?? false) {
elementNode.attributes['checked'] = '';
}
domNodes.insert(0, elementNode);
domNodes.addAll(
processChildrenNodes(node.children, encodeParsers: encodeParsers),
);
Expand Down
4 changes: 2 additions & 2 deletions test/plugins/html/encoder/parser/text_node_parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ void main() async {
expect(
const HTMLTodoListNodeParser()
.transformNodeToHTMLString(checkedNode, encodeParsers: parser),
'<div>Welcome to AppFlowy<input type="checkbox" checked="true"></div>',
'<div><input type="checkbox" checked="">Welcome to AppFlowy</div>',
);
expect(
const HTMLTodoListNodeParser()
.transformNodeToHTMLString(uncheckedNode, encodeParsers: parser),
'<div>Welcome to AppFlowy<input type="checkbox" checked="false"></div>',
'<div><input type="checkbox">Welcome to AppFlowy</div>',
);
});

Expand Down
Loading