mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 10:17:23 -05:00
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:
@@ -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
|
||||
|
||||
@@ -98,6 +98,8 @@
|
||||
<p class="collection"></p>
|
||||
<div class="collection"></div>
|
||||
<h3 class="collection"></h3>
|
||||
|
||||
<div id="element_attribute_tests"></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@@ -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 == "<b>New Content</b>"
|
||||
assert div.text == div._js.textContent == "<b>New Content</b>"
|
||||
|
||||
|
||||
class TestCollection:
|
||||
def test_iter_eq_children(self):
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from "codemirror";
|
||||
export {};
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from "@codemirror/commands";
|
||||
export {};
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from "@codemirror/lang-python";
|
||||
export {};
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from "@codemirror/language";
|
||||
export {};
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from "@codemirror/state";
|
||||
export {};
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from "@codemirror/view";
|
||||
export {};
|
||||
|
||||
Reference in New Issue
Block a user