From 0647781dbd71164191424630c7113290d6b00d1d Mon Sep 17 00:00:00 2001 From: rmorshea Date: Fri, 3 Feb 2023 11:23:09 -0800 Subject: [PATCH 1/3] fix data-* and aria-* attribute name conversion --- .../idom-client-react/src/element-utils.js | 2 +- tests/test_client.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/client/packages/idom-client-react/src/element-utils.js b/src/client/packages/idom-client-react/src/element-utils.js index 334ca9019..a3ec61c3e 100644 --- a/src/client/packages/idom-client-react/src/element-utils.js +++ b/src/client/packages/idom-client-react/src/element-utils.js @@ -64,7 +64,7 @@ function normalizeAttribute([key, value]) { key.startsWith("aria_") || DASHED_HTML_ATTRS.includes(key) ) { - normKey = key.replace("_", "-"); + normKey = key.split("_").join("-"); } else { normKey = snakeToCamel(key); } diff --git a/tests/test_client.py b/tests/test_client.py index fae191078..483eeffcf 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -132,3 +132,21 @@ async def handle_change(event): await inp.type("hello", delay=DEFAULT_TYPE_DELAY) assert (await inp.evaluate("node => node.value")) == "hello" + + +async def test_data_and_aria_attribute_naming(display: DisplayFixture): + @idom.component + def SomeComponent(): + return idom.html.h1( + "see attributes", + id="title", + data_some_thing="some data", + aria_description="some title", + ) + + await display.show(SomeComponent) + + title = await display.page.wait_for_selector("#title") + + assert await title.get_attribute("data-some-thing") == "some data" + assert await title.get_attribute("aria-description") == "some title" From ebf484edafd9f3dd8587b2ecbb4cd5c96307fa32 Mon Sep 17 00:00:00 2001 From: rmorshea Date: Fri, 3 Feb 2023 11:26:29 -0800 Subject: [PATCH 2/3] changelog --- docs/source/about/changelog.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/source/about/changelog.rst b/docs/source/about/changelog.rst index 2a48d6f37..0a6117b8b 100644 --- a/docs/source/about/changelog.rst +++ b/docs/source/about/changelog.rst @@ -23,7 +23,11 @@ more info, see the :ref:`Contributor Guide `. Unreleased ---------- -No changes. +**Fixed** + +- :pull:`911` - fixed ``data-*`` and ``aria-*`` attribute name conversions. Previously + an attribute declared as ``data_some_thing`` got converted to ``data-some_thing`` + instead of ``data-some-thing``. v1.0.0-a3 From 036b307d3bb48299b966e0a94eb7151e37c3a548 Mon Sep 17 00:00:00 2001 From: rmorshea Date: Fri, 3 Feb 2023 17:49:13 -0800 Subject: [PATCH 3/3] add **dict for data-attrs test --- tests/test_client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_client.py b/tests/test_client.py index 483eeffcf..c833d1bbf 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -142,6 +142,7 @@ def SomeComponent(): id="title", data_some_thing="some data", aria_description="some title", + **{"data-another-thing": "more data"}, ) await display.show(SomeComponent) @@ -149,4 +150,5 @@ def SomeComponent(): title = await display.page.wait_for_selector("#title") assert await title.get_attribute("data-some-thing") == "some data" + assert await title.get_attribute("data-another-thing") == "more data" assert await title.get_attribute("aria-description") == "some title"