Add text to pydom.Element (#1911)

* add missing test for html attribute

* add test for text attribute

* fix text attribute test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Andrea Giammarchi <andrea.giammarchi@gmail.com>
This commit is contained in:
Fabio Pliger
2024-02-12 14:50:36 -05:00
committed by GitHub
parent 30c6c830ae
commit f6d5cf06c8
9 changed files with 40 additions and 6 deletions

View File

@@ -125,6 +125,14 @@ class Element(BaseElement):
def html(self, value):
self._js.innerHTML = value
@property
def text(self):
return self._js.textContent
@text.setter
def text(self, value):
self._js.textContent = value
@property
def content(self):
# TODO: This breaks with with standard template elements. Define how to best

View File

@@ -98,6 +98,8 @@
<p class="collection"></p>
<div class="collection"></div>
<h3 class="collection"></h3>
<div id="element_attribute_tests"></div>
</div>

View File

@@ -163,6 +163,30 @@ class TestElement:
assert called
def test_html_attribute(self):
# GIVEN an existing element on the page with a known empty text content
div = pydom["#element_attribute_tests"][0]
# WHEN we set the html attribute
div.html = "<b>New Content</b>"
# EXPECT the element html and underlying JS Element innerHTML property
# to match what we expect and what
assert div.html == div._js.innerHTML == "<b>New Content</b>"
assert div.text == div._js.textContent == "New Content"
def test_text_attribute(self):
# GIVEN an existing element on the page with a known empty text content
div = pydom["#element_attribute_tests"][0]
# WHEN we set the html attribute
div.text = "<b>New Content</b>"
# EXPECT the element html and underlying JS Element innerHTML property
# to match what we expect and what
assert div.html == div._js.innerHTML == "&lt;b&gt;New Content&lt;/b&gt;"
assert div.text == div._js.textContent == "<b>New Content</b>"
class TestCollection:
def test_iter_eq_children(self):

View File

@@ -1 +1 @@
export * from "codemirror";
export {};

View File

@@ -1 +1 @@
export * from "@codemirror/commands";
export {};

View File

@@ -1 +1 @@
export * from "@codemirror/lang-python";
export {};

View File

@@ -1 +1 @@
export * from "@codemirror/language";
export {};

View File

@@ -1 +1 @@
export * from "@codemirror/state";
export {};

View File

@@ -1 +1 @@
export * from "@codemirror/view";
export {};