question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot set data-* attribute on VirtualDOM.

See original GitHub issue

Hi,

I try to set data-* attribute to element with no luck on virtual-dom

For example: This working:

hx`<a href="${pagination.links.next}">Next</a>`

But this is not:

hx`<a href="#" data-href="${pagination.links.next}">Next</a>`

I’ve googled and found this https://github.com/Matt-Esch/virtual-dom/blob/master/docs/vnode.md#custom-attributes-data- which maybe related to my issue.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
tswaterscommented, Sep 3, 2016

Sorry for all the noise there, pushed up some force commits after I noticed some errors…

The PR has been adjusted to use a flag, {vdom: true} - this will fix data-, aria- and style being passed as a string. I noticed that tabindex and role both seemed to work without any explicit modifications, so maybe that was a bug upstream that is now fixed.

That reminds me - on the note of upstream bugs. Note that the tests relating to style as a string won’t pass unless min-document v2.18.1 is present, due to this bug. This matches the version in this package.json so it should be fine.

0reactions
arturicommented, Aug 12, 2016

This is an issue with aria (and thus accessibility) too, I’m currently struggling with it: since I have a nested tree of elements that I want to put attributes like aria-hidden on. Works fine with bel, but not virtual-dom.

Maybe we could really put this behind a supportVDomAttributes flag, as suggested in https://github.com/substack/hyperx/pull/29, or something?

return html`<div class="Uppy UppyTheme--default UppyDashboard ${isTouchDevice ? 'Uppy--isTouchDevice' : ''}"
                 aria-hidden="${modal.isHidden}"
                 aria-label="Uppy Dialog Window (Press escape to close)"
                 role="dialog">
    <div class="UppyDashboard-inner" tabindex="0">
      ...
    </div>
</div>

All attributes — aria, role, tabindex — except for class are missing from the resulting DOM.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - JQuery, cannot assign data attribute after creation
I'm trying to add some data attributes to a list element after creation. var el = document.createElement('li'); el.
Read more >
Developers - Cannot set data-* attribute on VirtualDOM. -
Hi,. I try to set data-* attribute to element with no luck on virtual-dom. For example: This working: hx`<a href="${pagination.links.next}">Next</a>`.
Read more >
Adventures in the Virtual DOM — Part 4: Rendering Attributes
This function is going to expand as we add more attribute types. We're going to add handling here for events, classes, styles, data...
Read more >
In JavaScript data binding, why use the data attribute instead ...
Well, first you can't easily extend DOM objects. The DOM has control of ... The data attribute exists for HTML/JS interchange. ... Could...
Read more >
How do I add data attributes to a script using the HTML builder
The purpose of this topic is to allow Discourse developers to understand how the new code works. What's a Virtual DOM? A Virtual...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found