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 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..c833d1bbf 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -132,3 +132,23 @@ 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", + **{"data-another-thing": "more data"}, + ) + + 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("data-another-thing") == "more data" + assert await title.get_attribute("aria-description") == "some title"