Skip to content

Commit fa0f307

Browse files
committed
use link class instead of ID
1 parent 6857f7a commit fa0f307

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ celerybeat.pid
108108

109109
# Environments
110110
.env
111-
.venv
111+
.venv*
112112
env/
113113
venv/
114114
ENV/

src/reactpy_router/components.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,18 @@ def on_click(_event: dict[str, Any]) -> None:
3434
search = f"?{search}"
3535
set_location(Location(pathname, search))
3636

37+
class_name = uuid
38+
if "className" in attributes:
39+
class_name = " ".join([attributes.pop("className"), class_name])
40+
# TODO: This can be removed when ReactPy stops supporting underscores in attribute names
41+
if "class_name" in attributes:
42+
class_name = " ".join([attributes.pop("class_name"), class_name])
43+
3744
attrs = {
3845
**attributes,
3946
"href": to,
4047
"onClick": on_click,
41-
"id": uuid,
48+
"className": uuid,
4249
}
4350
return html._(html.a(attrs, *children), html.script(link_js_content.replace("UUID", uuid)))
4451

src/reactpy_router/static/link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
document.getElementById("UUID").addEventListener("click", (event) => {
1+
document.getElementsByClassName("UUID").addEventListener("click", (event) => {
22
event.preventDefault();
33
let to = event.target.getAttribute("href");
44
window.history.pushState({}, to, new URL(to, window.location));

0 commit comments

Comments
 (0)