wooorm / property-information

Info on the properties and attributes of the web platform
MIT License
38 stars 11 forks source link

Custom data attributes are not correctly converted to properties #19

Closed martypdx closed 11 months ago

martypdx commented 11 months ago

Given:

<p data-title="my paragraph">text</p>

Current behavior reports property as dataTitle which will not work against the dom element to access or set the value. Correct access is through p.dataset.title. While there are tests, the tested behavior is incorrect for web standard platform.

Custom data attributes (data-*) appear on the corresponding element as camelCase sub-properties of element.dataset

Given how the rest of library is structured, my suggestion would be to add a .dataset = true to info and object report the property without the data- prefix.

LMK if I am misunderstanding the purpose of this library. I'm going off the first line that intent is to be web standard:

Info on the properties and attributes of the web platform

Also happy to make PRs if I can help

wooorm commented 11 months ago

In this project, property does not reflect DOM Web IDL properties, because the DOM does not reflect all attributes, and sometimes uses inconsistent casing. For more info, see https://github.com/wooorm/property-information/issues/18#issuecomment-1878518778. And, I’d recommend https://github.com/syntax-tree/hast-util-to-dom, if you want to turn hast into DOM nodes.