8000 Add text to pydom.Element (#1911) · woxtu/pyscript@f6d5cf0 · GitHub
[go: up one dir, main page]

Skip to content

Commit f6d5cf0

Browse files
fpligerpre-commit-ci[bot]WebReflection
authored
Add text to pydom.Element (pyscript#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>
1 parent 30c6c83 commit f6d5cf0

File tree

9 files changed

+40
-6
lines changed

9 files changed

+40
-6
lines changed

pyscript.core/src/stdlib/pyweb/pydom.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ def html(self):
125125
def html(self, value):
126126
self._js.innerHTML = value
127127

128+
@property
129+
def text(self):
130+
return self._js.textContent
131+
132+
@text.setter
133+
def text(self, value):
134+
self._js.textContent = value
135+
128136
@property
129< 8000 /code>137
def content(self):
130138
# TODO: This breaks with with standard template elements. Define how to best

pyscript.core/test/pyscript_dom/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ <h2 id="multi-elem-h2" class="multi-elems">Content multi-elem-h2</h2>
9898
<p class="collection"></p>
9999
<div class="collection"></div>
100100
<h3 class="collection"></h3>
101+
102+
<div id="element_attribute_tests"></div>
101103
</div>
102104

103105

pyscript.core/test/pyscript_dom/tests/test_dom.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,30 @@ def on_click(event):
163163

164164
assert called
165165

166+
def test_html_attribute(self):
167+
# GIVEN an existing element on the page with a known empty text content
168+
div = pydom["#element_attribute_tests"][0]
169+
170+
# WHEN we set the html attribute
171+
div.html = "<b>New Content</b>"
172+
173+
# EXPECT the element html and underlying JS Element innerHTML property
174+
# to match what we expect and what
175+
assert div.html == div._js.innerHTML == "<b>New Content</b>"
176+
assert div.text == div._js.textContent == "New Content"
177+
178+
def test_text_attribute(self):
179+
# GIVEN an existing element on the page with a known empty text content
180+
div = pydom["#element_attribute_tests"][0]
181+
182+
# WHEN we set the html attribute
183+
div.text = "<b>New Content</b>"
184+
185+
# EXPECT the element html and underlying JS Element innerHTML property
186+
# to match what we expect and what
187+
assert div.html == div._js.innerHTML == "&lt;b&gt;New Content&lt;/b&gt;"
188+
assert div.text == div._js.textContent == "<b>New Content</b>"
189+
166190

167191
class TestCollection:
168192
def test_iter_eq_children(self):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "codemirror";
1+
export {};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "@codemirror/commands";
1+
export {};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "@codemirror/lang-python";
1+
export {};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "@codemirror/language";
1+
export {};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "@codemirror/state";
1+
export {};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "@codemirror/view";
1+
export {};

0 commit comments

Comments
 (0)
0